/* ============================================= */
/* نظام الرسائل المنبثق - Facebook Style */
/* ============================================= */

.messages-icon {
    position: relative;
    margin-left: 15px;
}

.messages-wrapper {
    position: relative;
    cursor: pointer;
}

.messages-wrapper .fa-comment-dots {
    font-size: 22px;
    color: #fff;
    transition: all 0.3s;
}

.messages-wrapper .fa-comment-dots:hover {
    color: #2A7DD8;
    transform: scale(1.1);
}

.messages-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, #ff4444 0%, #cc0000 100%);
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: bold;
    border: 2px solid #0a0e27;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(255, 68, 68, 0.7);
    }
    50% {
        transform: scale(1.1);
        box-shadow: 0 0 0 6px rgba(255, 68, 68, 0);
    }
}

/* قائمة المحادثات المنسدلة */
.messages-dropdown {
    position: absolute;
    top: calc(100% + 15px);
    right: -100px;
    width: 360px;
    max-height: 500px;
    background: linear-gradient(135deg, #1a2332 0%, #0f1419 100%);
    border: 1px solid rgba(42, 125, 216, 0.3);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
}

.messages-dropdown.active {
    display: flex;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.messages-header {
    padding: 15px 20px;
    background: rgba(26, 35, 50, 0.8);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(42, 125, 216, 0.3);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.messages-header strong {
    font-size: 16px;
    color: #fff;
}

.view-all-link {
    font-size: 13px;
    color: #2A7DD8;
    text-decoration: none;
    transition: all 0.2s;
}

.view-all-link:hover {
    color: #5da3ff;
}

.messages-list {
    flex: 1;
    overflow-y: auto;
    max-height: 400px;
}

.messages-loading {
    padding: 30px;
    text-align: center;
    color: #888;
    font-size: 14px;
}

.message-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 1px solid rgba(42, 125, 216, 0.1);
}

.message-item:hover {
    background: rgba(42, 125, 216, 0.15);
}

.message-item.unread {
    background: rgba(42, 125, 216, 0.08);
    border-left: 3px solid #2A7DD8;
}

.message-item-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid rgba(42, 125, 216, 0.3);
    margin-left: 12px;
    position: relative;
    flex-shrink: 0;
}

.message-item-online {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #00ff00;
    border: 2px solid #0f1419;
    box-shadow: 0 0 8px #00ff00;
}

.message-item-info {
    flex: 1;
    min-width: 0;
}

.message-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.message-item-name {
    font-weight: 600;
    font-size: 14px;
    color: #fff;
}

.message-item.unread .message-item-name {
    color: #2A7DD8;
}

.message-item-time {
    font-size: 11px;
    color: #888;
}

.message-item-preview {
    font-size: 13px;
    color: #aaa;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.message-item.unread .message-item-preview {
    font-weight: 600;
    color: #fff;
}

.no-messages {
    padding: 40px 20px;
    text-align: center;
    color: #888;
}

.no-messages-icon {
    font-size: 48px;
    margin-bottom: 15px;
    opacity: 0.3;
}

/* ============================================= */
/* نافذة المحادثة المنبثقة */
/* ============================================= */

.popup-chat-window {
    position: fixed;
    bottom: 0;
    right: 80px;
    width: 380px;
    height: 500px;
    background: linear-gradient(135deg, #1a2332 0%, #0f1419 100%);
    border: 1px solid rgba(42, 125, 216, 0.3);
    border-radius: 12px 12px 0 0;
    box-shadow: 0 -5px 40px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    z-index: 9999;
    animation: slideUp 0.3s ease;
}

.popup-chat-window.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(100%);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.popup-chat-header {
    padding: 15px 20px;
    background: rgba(26, 35, 50, 0.9);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid rgba(42, 125, 216, 0.3);
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: move;
    user-select: none;
}

.popup-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid #2A7DD8;
}

.popup-chat-info {
    flex: 1;
    min-width: 0;
}

.popup-chat-name {
    font-size: 15px;
    font-weight: 600;
    color: #fff;
    margin-bottom: 2px;
}

.popup-chat-status {
    font-size: 12px;
    color: #888;
    display: flex;
    align-items: center;
    gap: 5px;
}

.popup-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #888;
}

.popup-status-dot.online {
    background: #00ff00;
    box-shadow: 0 0 8px #00ff00;
}

.popup-chat-controls {
    display: flex;
    gap: 8px;
}

.popup-control-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: rgba(42, 125, 216, 0.2);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.popup-control-btn:hover {
    background: rgba(42, 125, 216, 0.4);
    transform: scale(1.1);
}

.popup-control-btn.close:hover {
    background: rgba(255, 68, 68, 0.4);
    color: #ff4444;
}

.popup-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 0;
}

.popup-message-wrapper {
    display: flex;
    gap: 8px;
    animation: slideIn 0.3s ease;
}

.popup-message-wrapper.sent {
    flex-direction: row-reverse;
}

.popup-message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.popup-message-bubble {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.4;
    word-wrap: break-word;
}

.popup-message-wrapper.sent .popup-message-bubble {
    background: linear-gradient(135deg, #2A7DD8 0%, #1e5fa8 100%);
    border-bottom-right-radius: 4px;
}

.popup-message-wrapper.received .popup-message-bubble {
    background: rgba(42, 125, 216, 0.15);
    border: 1px solid rgba(42, 125, 216, 0.3);
    border-bottom-left-radius: 4px;
}

.popup-message-time {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
    text-align: right;
}

.popup-input-container {
    padding: 12px;
    background: rgba(26, 35, 50, 0.8);
    backdrop-filter: blur(10px);
    border-top: 1px solid rgba(42, 125, 216, 0.3);
}

.popup-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: rgba(42, 125, 216, 0.1);
    border: 1px solid rgba(42, 125, 216, 0.3);
    border-radius: 20px;
    padding: 6px 10px;
}

.popup-message-input {
    flex: 1;
    background: transparent;
    border: none;
    color: #fff;
    font-size: 13px;
    outline: none;
    resize: none;
    max-height: 80px;
    min-height: 24px;
    padding: 4px 0;
}

.popup-message-input::placeholder {
    color: #888;
}

.popup-send-btn {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, #2A7DD8 0%, #1e5fa8 100%);
    border: none;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.popup-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(42, 125, 216, 0.5);
}

.popup-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Scrollbar للنافذة المنبثقة */
.popup-messages-area::-webkit-scrollbar,
.messages-list::-webkit-scrollbar {
    width: 5px;
}

.popup-messages-area::-webkit-scrollbar-track,
.messages-list::-webkit-scrollbar-track {
    background: rgba(42, 125, 216, 0.05);
}

.popup-messages-area::-webkit-scrollbar-thumb,
.messages-list::-webkit-scrollbar-thumb {
    background: rgba(42, 125, 216, 0.3);
    border-radius: 3px;
}

.popup-messages-area::-webkit-scrollbar-thumb:hover,
.messages-list::-webkit-scrollbar-thumb:hover {
    background: rgba(42, 125, 216, 0.5);
}

/* Loading في النافذة المنبثقة */
.popup-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 1;
    color: #888;
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .messages-dropdown {
        right: -50px;
        width: 320px;
    }
    
    .popup-chat-window {
        width: 100%;
        right: 0;
        height: 100vh;
        border-radius: 0;
    }
}

/* ============================================= */
/* تحسينات إضافية */
/* ============================================= */

.popup-chat-window.minimized {
    height: 50px;
}

.popup-chat-window.minimized .popup-messages-area,
.popup-chat-window.minimized .popup-input-container {
    display: none;
}

.popup-chat-header.dragging {
    cursor: grabbing;
}

/* أيقونة الملفات في الرسائل المنبثقة */
.popup-message-file {
    margin-top: 8px;
    padding: 8px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.popup-message-file img {
    max-width: 100%;
    max-height: 200px;
    border-radius: 6px;
}

/* تأثير الكتابة */
.typing-indicator {
    padding: 8px 12px;
    background: rgba(42, 125, 216, 0.15);
    border-radius: 12px;
    display: none;
    align-items: center;
    gap: 4px;
    width: fit-content;
}

.typing-indicator.active {
    display: flex;
}

.typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #2A7DD8;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-8px);
    }
}