/**
 * Floating Chat Window - WhatsApp Style
 * نافذة الدردشة العائمة - بنمط واتساب
 * Version: 1.0.0
 */

/* ===== النافذة العائمة الرئيسية ===== */
.floating-chat-window {
    position: fixed !important;
    bottom: 20px !important;
    left: 20px !important; /* ✅ أقصى اليسار */
    top: auto !important;
    right: auto !important;
    transform: scale(0.95);
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 600px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4),
                0 10px 30px rgba(0, 0, 0, 0.3),
                0 5px 20px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 999999 !important; /* أعلى من أي modal (100× أعلى) */
    overflow: hidden;
}

.floating-chat-window.show {
    opacity: 1 !important;
    visibility: visible !important;
    transform: scale(1) !important;
    pointer-events: all !important;
}

/* النافذة المصغرة - notification صغير جذاب */
.floating-chat-window.minimized {
    height: 70px;
    width: 360px;
    bottom: 20px !important;
    left: 20px !important; /* ✅ أقصى اليسار */
    top: auto !important;
    right: auto !important;
    transform: none !important;
    overflow: hidden;
    border-radius: 35px; /* دائري أكثر */
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4),
                0 4px 16px rgba(118, 75, 162, 0.3);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); /* gradient جميل */
    animation: minimizedPulse 2s ease-in-out infinite; /* نبض خفيف */
    cursor: pointer; /* يد عند التحويم */
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* تأثير hover على النافذة المصغرة */
.floating-chat-window.minimized:hover {
    transform: scale(1.05) !important;
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.5),
                0 6px 20px rgba(118, 75, 162, 0.4);
}

/* نبض خفيف للفت الانتباه */
@keyframes minimizedPulse {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(102, 126, 234, 0.4),
                    0 4px 16px rgba(118, 75, 162, 0.3);
    }
    50% {
        box-shadow: 0 10px 28px rgba(102, 126, 234, 0.5),
                    0 5px 18px rgba(118, 75, 162, 0.4);
    }
}

.floating-chat-window.minimized .floating-chat-messages,
.floating-chat-window.minimized .floating-chat-input-container {
    display: none;
}

.floating-chat-window.minimized .floating-chat-header {
    cursor: pointer;
    transition: all 0.3s ease;
    background: transparent !important; /* شفاف في الوضع المصغر */
    border: none !important;
    padding: 15px 20px; /* padding أكبر */
}

.floating-chat-window.minimized .floating-chat-header-content {
    gap: 12px; /* مسافة أكبر */
}

.floating-chat-window.minimized .floating-chat-avatar {
    width: 45px;
    height: 45px;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
}

.floating-chat-window.minimized .floating-chat-title h3 {
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.floating-chat-window.minimized .floating-chat-status {
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
}

.floating-chat-window.minimized .floating-chat-actions {
    display: none; /* إخفاء زر التصغير في الوضع المصغر */
}

/* خلفية شفافة (Backdrop) */
.floating-chat-backdrop {
    position: fixed !important;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    z-index: 999998 !important; /* أسفل النافذة بـ 1، أعلى من أي modal */
    pointer-events: none;
}

.floating-chat-backdrop.show {
    opacity: 1 !important;
    visibility: visible !important;
    pointer-events: all !important;
}

/* ضمان الظهور فوق كل العناصر */
.floating-chat-window.show {
    display: flex !important;
}

/* فوق client-modal */
body .floating-chat-window {
    z-index: 2147483647 !important;
}

body.client-modal-open .floating-chat-window {
    z-index: 2147483647 !important;
}

/* ===== رأس النافذة (مثل واتساب) ===== */
.floating-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #128C7E 0%, #075E54 100%);
    color: white;
    border-radius: 16px 16px 0 0;
    flex-shrink: 0;
}

.floating-chat-header-content {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
}

.floating-chat-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    flex-shrink: 0;
}

.floating-chat-avatar i {
    font-size: 24px;
    color: white;
}

.floating-chat-status-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    background: #25D366;
    border: 2px solid #128C7E;
    border-radius: 50%;
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.floating-chat-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.floating-chat-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    color: white;
}

.floating-chat-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.85);
    font-weight: 400;
}

.floating-chat-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.floating-chat-action-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(255, 255, 255, 0.15);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.floating-chat-action-btn:hover {
    background: rgba(255, 255, 255, 0.25);
    transform: scale(1.05);
}

.floating-chat-action-btn i {
    font-size: 14px;
}

/* ===== منطقة الرسائل ===== */
.floating-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #E5DDD5;
    background-image: 
        repeating-linear-gradient(
            45deg,
            transparent,
            transparent 10px,
            rgba(0, 0, 0, 0.01) 10px,
            rgba(0, 0, 0, 0.01) 20px
        );
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.floating-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.floating-chat-messages::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.05);
}

.floating-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 3px;
}

.floating-chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(0, 0, 0, 0.3);
}

/* ===== فقاعة الرسالة ===== */
.floating-chat-message {
    display: flex;
    gap: 8px;
    margin-bottom: 4px;
    animation: messageSlideIn 0.3s ease-out;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.floating-chat-message.user {
    flex-direction: row-reverse;
}

.floating-chat-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    align-self: flex-end;
}

.floating-chat-message.bot .floating-chat-message-avatar {
    background: linear-gradient(135deg, #128C7E 0%, #075E54 100%);
    color: white;
}

.floating-chat-message.user .floating-chat-message-avatar {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.floating-chat-message-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.floating-chat-message.bot .floating-chat-message-bubble {
    background: white;
    border-radius: 0 8px 8px 8px;
}

.floating-chat-message.user .floating-chat-message-bubble {
    background: #DCF8C6;
    border-radius: 8px 0 8px 8px;
}

.floating-chat-message-text {
    font-size: 14px;
    line-height: 1.5;
    color: #000;
    word-wrap: break-word;
    margin: 0;
}

.floating-chat-message-time {
    font-size: 11px;
    color: rgba(0, 0, 0, 0.45);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
}

.floating-chat-message.user .floating-chat-message-time {
    color: rgba(0, 0, 0, 0.55);
}

/* ===== الأزرار السريعة (مثل واتساب) ===== */
.floating-chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.floating-chat-quick-reply-btn {
    padding: 6px 12px;
    background: white;
    border: 1px solid #128C7E;
    color: #128C7E;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.floating-chat-quick-reply-btn:hover {
    background: #128C7E;
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(18, 140, 126, 0.3);
}

.floating-chat-quick-reply-btn i {
    font-size: 12px;
}

/* ===== حقل الإدخال (مثل واتساب) ===== */
.floating-chat-input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    background: #F0F0F0;
    border-radius: 0 0 16px 16px;
    flex-shrink: 0;
}

.floating-chat-emoji-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: transparent;
    color: #54656f;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.floating-chat-emoji-btn:hover {
    background: rgba(0, 0, 0, 0.05);
    color: #128C7E;
}

.floating-chat-emoji-btn i {
    font-size: 20px;
}

.floating-chat-input-wrapper {
    flex: 1;
    background: white;
    border-radius: 20px;
    padding: 8px 16px;
    display: flex;
    align-items: center;
}

.floating-chat-input {
    flex: 1;
    border: none;
    outline: none;
    font-size: 14px;
    line-height: 1.5;
    color: #000;
    background: transparent;
    resize: none;
    font-family: inherit;
    max-height: 100px;
}

.floating-chat-input::placeholder {
    color: #8696a0;
}

.floating-chat-send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: #128C7E;
    color: white;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.floating-chat-send-btn:hover {
    background: #075E54;
    transform: scale(1.05);
}

.floating-chat-send-btn:active {
    transform: scale(0.95);
}

.floating-chat-send-btn i {
    font-size: 16px;
}

/* ===== حالة الكتابة ===== */
.floating-chat-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px;
    background: white;
    border-radius: 0 8px 8px 8px;
    max-width: 70px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.floating-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: #8696a0;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite;
}

.floating-chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.floating-chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-8px);
    }
}

/* ===== رسالة الترحيب ===== */
.floating-chat-welcome {
    text-align: center;
    padding: 24px 16px;
    color: #54656f;
}

.floating-chat-welcome-icon {
    font-size: 48px;
    color: #128C7E;
    margin-bottom: 12px;
}

.floating-chat-welcome h4 {
    margin: 0 0 8px 0;
    font-size: 16px;
    color: #000;
}

.floating-chat-welcome p {
    margin: 0;
    font-size: 13px;
    line-height: 1.5;
}

/* ===== Responsive للهواتف ===== */
@media (max-width: 768px) {
    .floating-chat-window {
        bottom: 90px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
        height: 500px;
        max-height: calc(100vh - 120px);
    }
    
    .floating-chat-header {
        padding: 10px 12px;
    }
    
    .floating-chat-avatar {
        width: 38px;
        height: 38px;
    }
    
    .floating-chat-avatar i {
        font-size: 20px;
    }
    
    .floating-chat-title h3 {
        font-size: 15px;
    }
    
    .floating-chat-messages {
        padding: 12px;
    }
    
    .floating-chat-input-container {
        padding: 10px 12px;
    }
}

/* ===== Dark Mode Support ===== */
body.dark-mode .floating-chat-window {
    background: #0b141a;
}

body.dark-mode .floating-chat-messages {
    background: #0b141a;
}

body.dark-mode .floating-chat-message.bot .floating-chat-message-bubble {
    background: #202c33;
    color: #e9edef;
}

body.dark-mode .floating-chat-message-text {
    color: #e9edef;
}

body.dark-mode .floating-chat-input-container {
    background: #202c33;
}

body.dark-mode .floating-chat-input-wrapper {
    background: #2a3942;
}

body.dark-mode .floating-chat-input {
    color: #e9edef;
}

body.dark-mode .floating-chat-input::placeholder {
    color: #8696a0;
}

body.dark-mode .floating-chat-emoji-btn {
    color: #8696a0;
}

body.dark-mode .floating-chat-emoji-btn:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #25D366;
}

body.dark-mode .floating-chat-quick-reply-btn {
    background: #202c33;
    border-color: #25D366;
    color: #25D366;
}

body.dark-mode .floating-chat-quick-reply-btn:hover {
    background: #25D366;
    color: #0b141a;
}

/* ===== Document Cards ?? ??????? ??????? ===== */
.floating-chat-document .document-card {
    transition: all 0.2s ease;
}

.floating-chat-document .document-card:hover {
    background: #e8f5e9 !important;
    border-color: #25D366 !important;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.2);
}

body.dark-mode .floating-chat-document .document-card {
    background: #202c33 !important;
    border-color: #2a3942 !important;
}

body.dark-mode .floating-chat-document .document-card:hover {
    background: #2a3942 !important;
    border-color: #25D366 !important;
}
