/* Modern Chat Enhancements - Light Theme */

/* Smooth scrollbar for messages */
#messages-container::-webkit-scrollbar {
    width: 8px;
}

#messages-container::-webkit-scrollbar-track {
    background: #f3f4f6;
    border-radius: 10px;
}

#messages-container::-webkit-scrollbar-thumb {
    background: linear-gradient(45deg, #8b5cf6, #ec4899);
    border-radius: 10px;
}

#messages-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(45deg, #7c3aed, #db2777);
}

/* Sidebar scrollbar */
.sidebar-scroll::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: #f9fafb;
    border-radius: 10px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* Message animations */
.message-item {
    animation: messageSlideIn 0.3s ease-out;
    margin-bottom: 1rem;
}

@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* إصلاح ألوان الرسائل المرسلة */
.message-sent {
    background-color: #ec4899 !important;
    color: white !important;
}

.message-sent p {
    color: white !important;
}

.message-sent span {
    color: rgba(255, 255, 255, 0.75) !important;
}

/* ضمان ظهور الألوان الصحيحة */
.bg-pink-500 {
    background-color: #ec4899 !important;
}

.text-white {
    color: #ffffff !important;
}

/* 🎨 تحسينات بصرية متقدمة */

/* تأثيرات انتقالية للرسائل الجديدة */
.message-item {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    transform-origin: center;
}

.message-item.new-message {
    animation: newMessagePop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes newMessagePop {
    0% {
        opacity: 0;
        transform: translateY(30px) scale(0.8);
    }
    50% {
        transform: translateY(-5px) scale(1.02);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ظلال محسنة للرسائل */
.message-sent {
    box-shadow: 0 4px 12px rgba(236, 72, 153, 0.3),
                0 2px 4px rgba(236, 72, 153, 0.2);
    transition: all 0.3s ease;
}

.message-sent:hover {
    box-shadow: 0 6px 20px rgba(236, 72, 153, 0.4),
                0 4px 8px rgba(236, 72, 153, 0.3);
    transform: translateY(-1px);
}

.message-received {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1),
                0 1px 3px rgba(0, 0, 0, 0.08);
    transition: all 0.3s ease;
}

.message-received:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15),
                0 2px 6px rgba(0, 0, 0, 0.1);
    transform: translateY(-1px);
}

/* تحسين الألوان مع تدرجات خفيفة */
.message-sent {
    background: linear-gradient(135deg, #ec4899 0%, #f472b6 100%) !important;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* تأثيرات للأزرار */
.chat-button {
    transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    position: relative;
    overflow: hidden;
}

.chat-button::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.chat-button:active::before {
    width: 300px;
    height: 300px;
}

/* مؤشر الكتابة */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 20px;
    margin: 8px 0;
    backdrop-filter: blur(10px);
    border: 1px solid rgba(0, 0, 0, 0.1);
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: #ec4899;
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0s; }

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1.2);
        opacity: 1;
    }
}

/* تحسينات ترتيب الرسائل */
#messages-container {
    direction: ltr !important;
}

.message-item {
    width: 100% !important;
    display: flex !important;
}

.message-item.justify-end {
    justify-content: flex-end !important;
}

.message-item.justify-start {
    justify-content: flex-start !important;
}

/* فقاعات الرسائل المحسنة */
.message-bubble-sent {
    background: linear-gradient(135deg, #ec4899, #f43f5e) !important;
    margin-left: auto;
}

.message-bubble-received {
    background: #ffffff !important;
    margin-right: auto;
}

/* 📱 تحسينات الموبايل */
@media (max-width: 768px) {
    .message-item {
        margin-bottom: 0.75rem;
    }

    .message-item .max-w-xs {
        max-width: 85%;
    }

    /* تحسين حجم فقاعات الرسائل للموبايل */
    .message-sent, .message-received {
        padding: 12px 16px !important;
        font-size: 14px;
        line-height: 1.4;
    }

    /* تحسين أزرار اللمس */
    .chat-button {
        min-height: 44px;
        min-width: 44px;
        padding: 12px !important;
    }

    /* تحسين حقل الإدخال */
    #message-input {
        font-size: 16px; /* منع zoom في iOS */
        padding: 14px 20px !important;
    }

    /* تحسين التمرير */
    #messages-container {
        scroll-behavior: smooth;
        -webkit-overflow-scrolling: touch;
    }

    /* تحسين الصور الشخصية */
    .message-avatar {
        width: 28px !important;
        height: 28px !important;
    }
}

/* 🎨 تأثيرات إضافية للرسائل */
.message-context-menu {
    position: absolute;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    padding: 8px 0;
    z-index: 1000;
    min-width: 150px;
    opacity: 0;
    transform: scale(0.95);
    transition: all 0.2s ease;
}

.message-context-menu.show {
    opacity: 1;
    transform: scale(1);
}

.message-context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.message-context-menu-item:hover {
    background-color: #f3f4f6;
}

.message-context-menu-item.danger:hover {
    background-color: #fef2f2;
    color: #dc2626;
}

/* تأثير التحديد للرسائل */
.message-item.selected {
    background: rgba(236, 72, 153, 0.1);
    border-radius: 12px;
    padding: 4px;
    margin: 4px 0;
}

/* شريط الأدوات للرسائل المحددة */
.selection-toolbar {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: white;
    border-radius: 25px;
    padding: 8px 16px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    display: flex;
    gap: 12px;
    z-index: 1000;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    transition: all 0.3s ease;
}

.selection-toolbar.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* 😀 Emoji Picker Styles */
#emoji-picker {
    position: fixed;
    bottom: 80px;
    left: 20px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
    border: 1px solid #e5e7eb;
    padding: 16px;
    z-index: 1000;
    width: 320px;
    max-height: 280px;
}

#emoji-picker .grid {
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 8px;
    max-height: 200px;
    overflow-y: auto;
}

#emoji-picker button {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    background: transparent;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 18px;
}

#emoji-picker button:hover {
    background-color: #f3f4f6;
}

#emoji-picker button:active {
    background-color: #e5e7eb;
    transform: scale(0.95);
}

/* Emoji picker header */
.emoji-picker-header {
    display: flex;
    justify-content: between;
    align-items: center;
    margin-bottom: 12px;
    padding-bottom: 8px;
    border-bottom: 1px solid #e5e7eb;
}

.emoji-picker-title {
    font-size: 14px;
    font-weight: 600;
    color: #374151;
}

.emoji-picker-close {
    background: none;
    border: none;
    color: #6b7280;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
}

.emoji-picker-close:hover {
    background-color: #f3f4f6;
    color: #374151;
}

/* Responsive emoji picker */
@media (max-width: 768px) {
    #emoji-picker {
        left: 10px;
        right: 10px;
        width: auto;
        bottom: 90px;
    }

    #emoji-picker .grid {
        grid-template-columns: repeat(6, 1fr);
    }
}

/* تأكيد موضع الـ emoji picker */
#emoji-picker {
    position: fixed !important;
    bottom: 80px !important;
    left: 20px !important;
    z-index: 9999 !important;
}

/* تحسين container للدردشة */
.chat-input-container {
    position: relative;
}

/* تحسين موضع الـ picker للشاشات الكبيرة */
@media (min-width: 769px) {
    #emoji-picker {
        bottom: 90px !important;
        left: 30px !important;
    }
}

/* 📱 تحسينات صفحة المحادثات الجديدة */

/* Sidebar scrollbar */
.sidebar-scroll::-webkit-scrollbar {
    width: 6px;
}

.sidebar-scroll::-webkit-scrollbar-track {
    background: #f9fafb;
    border-radius: 10px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
    background: #d1d5db;
    border-radius: 10px;
}

.sidebar-scroll::-webkit-scrollbar-thumb:hover {
    background: #9ca3af;
}

/* 📜 Chat Messages Scrollbar - مثل الصورة */
.chat-messages-container {
    scrollbar-width: thin;
    scrollbar-color: #ec4899 #f3f4f6;
}

.chat-messages-container::-webkit-scrollbar {
    width: 8px;
    background: transparent;
}

.chat-messages-container::-webkit-scrollbar-track {
    background: rgba(243, 244, 246, 0.5);
    border-radius: 10px;
    margin: 10px 0;
}

.chat-messages-container::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ec4899, #f472b6);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
    min-height: 30px;
}

.chat-messages-container::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #db2777, #ec4899);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

.chat-messages-container::-webkit-scrollbar-thumb:active {
    background: linear-gradient(180deg, #be185d, #db2777);
    border-radius: 10px;
    border: 2px solid transparent;
    background-clip: content-box;
}

/* تحسين شريط التمرير للموبايل */
@media (max-width: 768px) {
    .chat-messages-container::-webkit-scrollbar {
        width: 6px;
    }

    .chat-messages-container::-webkit-scrollbar-thumb {
        border: 1px solid transparent;
    }
}

/* تأثيرات إضافية للـ scrollbar */
.chat-messages-container::-webkit-scrollbar-corner {
    background: transparent;
}

/* تحسين smooth scrolling */
.chat-messages-container {
    scroll-behavior: smooth;
}

/* إضافة تأثير fade للـ scrollbar */
.chat-messages-container::-webkit-scrollbar-thumb {
    transition: all 0.3s ease;
}

/* تحسين الظهور عند hover على المنطقة */
.chat-messages-container:hover::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ec4899, #f472b6);
}

/* إخفاء الـ scrollbar عندما لا يكون هناك محتوى كافي */
.chat-messages-container:not(:hover)::-webkit-scrollbar-thumb {
    background: rgba(236, 72, 153, 0.3);
}

/* تحسين للـ Firefox */
@supports (scrollbar-width: thin) {
    .chat-messages-container {
        scrollbar-width: thin;
        scrollbar-color: #ec4899 rgba(243, 244, 246, 0.5);
    }
}

/* حالات مختلفة للـ scrollbar */
.chat-messages-container.has-scroll::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #ec4899, #f472b6);
}

.chat-messages-container.scrolling::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #db2777, #ec4899);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* تأثير نبضة للـ scrollbar عند وصول رسالة جديدة */
.chat-messages-container.new-message::-webkit-scrollbar-thumb {
    animation: scrollbar-pulse 0.6s ease-out;
}

@keyframes scrollbar-pulse {
    0% {
        background: linear-gradient(180deg, #ec4899, #f472b6);
        transform: scaleY(1);
    }
    50% {
        background: linear-gradient(180deg, #db2777, #ec4899);
        transform: scaleY(1.1);
    }
    100% {
        background: linear-gradient(180deg, #ec4899, #f472b6);
        transform: scaleY(1);
    }
}

/* تحسين للشاشات اللمسية */
@media (hover: none) and (pointer: coarse) {
    .chat-messages-container::-webkit-scrollbar {
        width: 4px;
    }

    .chat-messages-container::-webkit-scrollbar-thumb {
        background: rgba(236, 72, 153, 0.6);
        border-radius: 2px;
    }
}

/* تأثيرات hover للمحادثات */
.conversation-item {
    transition: all 0.2s ease;
}

.conversation-item:hover {
    background-color: #f9fafb;
    transform: translateX(4px);
}

.conversation-item.active {
    background-color: #fdf2f8;
    border-right: 4px solid #ec4899;
}

/* تحسينات الموبايل لصفحة المحادثات */
@media (max-width: 768px) {
    .messages-sidebar {
        width: 100%;
        position: fixed;
        top: 0;
        left: 0;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }

    .messages-sidebar.open {
        transform: translateX(0);
    }

    .messages-main {
        width: 100%;
    }
}

/* تأثيرات للأزرار في header */
.header-button {
    transition: all 0.2s ease;
}

.header-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

/* تحسين عداد الرسائل غير المقروءة */
.unread-badge {
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        opacity: 1;
    }
    50% {
        opacity: 0.7;
    }
}

/* تحسين حالة الاتصال */
.online-status {
    animation: pulse-green 2s infinite;
}

@keyframes pulse-green {
    0%, 100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    50% {
        box-shadow: 0 0 0 4px rgba(34, 197, 94, 0);
    }
}

/* Message alignment improvements */
.message-item.justify-end {
    direction: ltr; /* للرسائل المرسلة */
}

.message-item.justify-start {
    direction: ltr; /* للرسائل المستقبلة */
}

/* Message bubble improvements */
.message-bubble-sent {
    background: linear-gradient(135deg, #8b5cf6, #ec4899);
    border-radius: 18px 18px 4px 18px;
    margin-left: auto;
}

.message-bubble-received {
    background: #ffffff;
    border-radius: 18px 18px 18px 4px;
    border: 1px solid #e5e7eb;
    margin-right: auto;
}

/* Avatar improvements */
.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    margin-left: 8px;
    flex-shrink: 0;
}

/* Time stamp improvements */
.message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

/* Typing indicator animation */
.typing-dots {
    display: inline-flex;
    align-items: center;
}

.typing-dots span {
    height: 4px;
    width: 4px;
    background: #6b7280;
    border-radius: 50%;
    display: inline-block;
    margin: 0 1px;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typing {
    0%, 80%, 100% {
        transform: scale(0.8);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* Glass morphism effect */
.glass-effect {
    background: rgba(255, 255, 255, 0.25);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.18);
}

/* Gradient text */
.gradient-text {
    background: linear-gradient(45deg, #8b5cf6, #ec4899, #3b82f6);
    background-size: 200% 200%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: gradientShift 3s ease infinite;
}

@keyframes gradientShift {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Floating animation */
.float-animation {
    animation: float 3s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

/* Pulse effect for online status */
.pulse-green {
    animation: pulseGreen 2s infinite;
}

@keyframes pulseGreen {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

/* Message bubble hover effects */
.message-bubble {
    transition: all 0.3s ease;
}

.message-bubble:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

/* Send button ripple effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.5);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::before {
    width: 300px;
    height: 300px;
}

/* Custom focus styles */
.custom-focus:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.3);
}

/* Smooth transitions for all interactive elements */
.smooth-transition {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Conversation card hover effect */
.conversation-card {
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.conversation-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
    transition: left 0.5s;
}

.conversation-card:hover::before {
    left: 100%;
}

.conversation-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
}

/* Message time fade in */
.message-time {
    opacity: 0;
    transition: opacity 0.3s ease;
}

.message-item:hover .message-time {
    opacity: 1;
}

/* Responsive improvements */
@media (max-width: 768px) {
    .message-bubble {
        max-width: 85vw;
    }

    #messages-container {
        padding: 1rem;
    }

    .conversation-card {
        margin: 0.5rem 0;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    .glass-effect {
        background: rgba(0, 0, 0, 0.25);
        border: 1px solid rgba(255, 255, 255, 0.1);
    }
}

/* Loading animation */
.loading-dots {
    display: inline-block;
}

.loading-dots::after {
    content: '';
    animation: loadingDots 1.5s infinite;
}

@keyframes loadingDots {
    0%, 20% { content: '.'; }
    40% { content: '..'; }
    60%, 100% { content: '...'; }
}

/* Notification slide in */
.notification-slide {
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Button press effect */
.button-press:active {
    transform: scale(0.95);
}

/* Gradient border animation */
.gradient-border {
    position: relative;
    background: linear-gradient(45deg, #8b5cf6, #ec4899, #3b82f6);
    background-size: 200% 200%;
    animation: gradientBorder 3s ease infinite;
}

@keyframes gradientBorder {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
