/**
 * Chat Floating Action Button (FAB)
 * زر الدردشة العائم
 * Version: 1.0.0
 */

/* الزر العائم الرئيسي */
.chat-fab {
    position: fixed;
    bottom: 20px; /* أقصى أسفل */
    right: 20px;  /* أقصى يمين */
    left: auto;
    width: 70px;
    height: 70px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(102, 126, 234, 0.6),
                0 4px 16px rgba(118, 75, 162, 0.5),
                0 0 0 0 rgba(102, 126, 234, 0.4);
    z-index: 2147483647 !important; /* أقصى قيمة - فوق الجميع */
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 3px solid rgba(255, 255, 255, 0.9);
    outline: none;
    /* الزر مخفي افتراضياً */
    opacity: 0;
    transform: scale(0) rotate(-180deg);
    pointer-events: none;
}

/* إظهار الزر عند فتح نافذة العميل فقط */
body.client-modal-open .chat-fab {
    opacity: 1;
    transform: scale(1) rotate(0deg);
    pointer-events: all;
    animation: chatFabEntrance 0.6s cubic-bezier(0.34, 1.56, 0.64, 1),
               chatFabPulse 3s ease-in-out 0.6s infinite;
}

/* أيقونة الدردشة */
.chat-fab-icon {
    color: white;
    font-size: 32px;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.2));
}

/* عند التحويم */
.chat-fab:hover {
    transform: scale(1.15);
    box-shadow: 0 12px 32px rgba(102, 126, 234, 0.7),
                0 6px 20px rgba(118, 75, 162, 0.6),
                0 0 40px rgba(102, 126, 234, 0.4);
    border-color: rgba(255, 255, 255, 1);
}

.chat-fab:hover .chat-fab-icon {
    transform: scale(1.15) rotate(15deg);
}

/* عند النقر */
.chat-fab:active {
    transform: scale(0.95);
}

/* Badge للإشعارات */
.chat-fab-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
    color: white;
    font-size: 12px;
    font-weight: 700;
    min-width: 24px;
    height: 24px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 7px;
    box-shadow: 0 3px 8px rgba(239, 68, 68, 0.5),
                0 0 0 3px rgba(255, 255, 255, 0.9);
    animation: chatBadgePulse 1.5s infinite;
    z-index: 1;
}

@keyframes chatBadgePulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 3px 8px rgba(239, 68, 68, 0.5),
                    0 0 0 3px rgba(255, 255, 255, 0.9);
    }
    50% {
        transform: scale(1.15);
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.7),
                    0 0 0 3px rgba(255, 255, 255, 0.9),
                    0 0 20px rgba(239, 68, 68, 0.3);
    }
}

/* Tooltip */
.chat-fab-tooltip {
    position: absolute;
    left: 80px; /* على يسار الزر (لأن الزر على اليمين) */
    right: auto;
    top: 50%;
    transform: translateY(-50%);
    background: linear-gradient(135deg, #1f2937 0%, #111827 100%);
    color: white;
    padding: 10px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3),
                0 0 0 2px rgba(102, 126, 234, 0.3);
    z-index: 2147483647 !important; /* فوق الجميع */
}

/* سهم Tooltip - على اليمين (باتجاه الزر) */
.chat-fab-tooltip::after {
    content: '';
    position: absolute;
    right: 100%;
    left: auto;
    top: 50%;
    transform: translateY(-50%);
    border: 8px solid transparent;
    border-right-color: #1f2937;
}

/* إظهار Tooltip عند التحويم */
.chat-fab:hover .chat-fab-tooltip {
    opacity: 1;
    left: 85px;
    right: auto;
}

/* رسوم متحركة للموجة */
.chat-fab::before {
    content: '';
    position: absolute;
    top: -3px;
    left: -3px;
    width: calc(100% + 6px);
    height: calc(100% + 6px);
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    opacity: 0;
    z-index: -1;
}

/* تأثير النبض المستمر */
body.client-modal-open .chat-fab::before {
    animation: chatFabRipple 2.5s ease-out infinite;
}

/* رسوم متحركة */
@keyframes chatFabEntrance {
    0% {
        transform: scale(0) rotate(-180deg);
        opacity: 0;
    }
    60% {
        transform: scale(1.2) rotate(20deg);
        opacity: 1;
    }
    100% {
        transform: scale(1) rotate(0deg);
        opacity: 1;
    }
}

@keyframes chatFabPulse {
    0%, 100% {
        transform: scale(1) rotate(0deg);
        box-shadow: 0 8px 24px rgba(102, 126, 234, 0.6),
                    0 4px 16px rgba(118, 75, 162, 0.5);
    }
    50% {
        transform: scale(1.05) rotate(0deg);
        box-shadow: 0 12px 32px rgba(102, 126, 234, 0.8),
                    0 6px 20px rgba(118, 75, 162, 0.7);
    }
}

@keyframes chatFabRipple {
    0% {
        transform: scale(1);
        opacity: 0.7;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.4;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* حالة النشاط */
.chat-fab.active {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    box-shadow: 0 8px 24px rgba(16, 185, 129, 0.6),
                0 4px 16px rgba(5, 150, 105, 0.5);
    border-color: rgba(255, 255, 255, 0.95);
}

.chat-fab.active::before {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
}

/* حالة الإغلاق */
.chat-fab.closing .chat-fab-icon {
    transform: rotate(180deg);
}

/* للشاشات الصغيرة */
@media (max-width: 768px) {
    .chat-fab {
        bottom: 15px; /* أقصى أسفل للموبايل */
        right: 15px;  /* أقصى يمين للموبايل */
        left: auto;
        width: 64px;
        height: 64px;
    }
    
    .chat-fab-icon {
        font-size: 28px;
    }
    
    .chat-fab-tooltip {
        display: none;
    }
}

/* Dark Mode */
body.dark-mode .chat-fab-tooltip {
    background: #374151;
    color: #f3f4f6;
}

body.dark-mode .chat-fab-tooltip::after {
    border-right-color: #374151;
    border-left-color: transparent;
}

body[dir="rtl"].dark-mode .chat-fab-tooltip::after {
    border-right-color: #374151;
    border-left-color: transparent;
}

/* تأثير النبض عند وجود رسالة جديدة */
.chat-fab.has-notification {
    animation: chatFabNotificationPulse 1.5s infinite;
}

@keyframes chatFabNotificationPulse {
    0%, 100% {
        box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4),
                    0 2px 8px rgba(118, 75, 162, 0.3);
    }
    50% {
        box-shadow: 0 6px 20px rgba(239, 68, 68, 0.6),
                    0 4px 16px rgba(239, 68, 68, 0.4);
    }
}

/* Accessibility */
.chat-fab:focus {
    outline: 3px solid rgba(102, 126, 234, 0.5);
    outline-offset: 2px;
}

.chat-fab:focus:not(:focus-visible) {
    outline: none;
}

/* تحسين الأداء */
.chat-fab,
.chat-fab::before,
.chat-fab-icon,
.chat-fab-tooltip {
    will-change: transform, opacity;
}
