/* =====================================================
   CHAT WIDGET STYLES
   تصميم نظام الشات للزوار والأدمن
   ===================================================== */

/* ============ المتغيرات ============ */
:root {
    --chat-primary: #001E62;
    --chat-primary-light: #0036b0;
    --chat-accent: #00c9a7;
    --chat-bg: #f8f9fa;
    --chat-white: #ffffff;
    --chat-gray-100: #f1f3f5;
    --chat-gray-200: #e9ecef;
    --chat-gray-300: #dee2e6;
    --chat-gray-500: #6c757d;
    --chat-gray-700: #495057;
    --chat-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    --chat-radius: 16px;
}

/* ============ زر الشات العائم (للزوار) ============ */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--chat-shadow);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    z-index: 9998;
    transition: all 0.3s ease;
}

[dir="rtl"] .chat-fab {
    right: auto;
    left: 24px;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 30px rgba(0, 30, 98, 0.3);
}

.chat-fab .chat-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #dc3545;
    color: white;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* ============ نافذة الشات (للزوار) ============ */
.chat-widget {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 500px;
    max-height: calc(100vh - 150px);
    background: var(--chat-white);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    display: none;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    animation: chatSlideIn 0.3s ease;
}

[dir="rtl"] .chat-widget {
    right: auto;
    left: 24px;
}

.chat-widget.active {
    display: flex;
}

@keyframes chatSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* ============ رأس الشات ============ */
.chat-header {
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
}

.chat-header-info {
    flex: 1;
}

.chat-header-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.chat-header-status {
    font-size: 12px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-header-status .status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4caf50;
}

.chat-header-status .status-dot.offline {
    background: #ff9800;
}

.chat-close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: background 0.2s;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ============ منطقة الرسائل ============ */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: var(--chat-gray-100);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-message {
    max-width: 80%;
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.5;
    position: relative;
    word-wrap: break-word;
}

.chat-message.visitor {
    background: var(--chat-primary);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 6px;
}

[dir="rtl"] .chat-message.visitor {
    border-bottom-right-radius: 18px;
    border-bottom-left-radius: 6px;
}

.chat-message.admin {
    background: var(--chat-white);
    color: var(--chat-gray-700);
    align-self: flex-start;
    border-bottom-left-radius: 6px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

[dir="rtl"] .chat-message.admin {
    border-bottom-left-radius: 18px;
    border-bottom-right-radius: 6px;
}

.chat-message-time {
    font-size: 10px;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.chat-message.admin .chat-message-time {
    text-align: left;
}

[dir="rtl"] .chat-message.admin .chat-message-time {
    text-align: right;
}

/* رسالة الترحيب */
.chat-welcome {
    text-align: center;
    padding: 20px;
    color: var(--chat-gray-500);
}

.chat-welcome-icon {
    font-size: 48px;
    margin-bottom: 12px;
}

.chat-welcome h3 {
    font-size: 16px;
    margin-bottom: 8px;
    color: var(--chat-gray-700);
}

.chat-welcome p {
    font-size: 13px;
}

/* مؤشر الكتابة */
.typing-indicator {
    display: none;
    align-self: flex-start;
    background: var(--chat-white);
    padding: 12px 16px;
    border-radius: 18px;
    border-bottom-left-radius: 6px;
}

.typing-indicator.active {
    display: flex;
    gap: 4px;
    align-items: center;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--chat-gray-400);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) { animation-delay: 0s; }
.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-8px); }
}

/* مؤشر الكتابة للأدمن */
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 8px 12px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--chat-gray-400, #9CA3AF);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dots span:nth-child(1) { animation-delay: 0s; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

/* ============ منطقة الإدخال ============ */
.chat-input-area {
    padding: 12px 16px;
    background: var(--chat-white);
    border-top: 1px solid var(--chat-gray-200);
    display: flex;
    gap: 10px;
    align-items: flex-end;
}

.chat-input-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--chat-gray-100);
    border-radius: 24px;
    padding: 4px 16px;
}

.chat-input {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px 0;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    outline: none;
    font-family: inherit;
}

.chat-input::placeholder {
    color: var(--chat-gray-500);
}

.chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ============ نموذج معلومات الزائر ============ */
.chat-visitor-form {
    padding: 20px;
    background: var(--chat-white);
}

.chat-visitor-form h3 {
    font-size: 16px;
    margin-bottom: 16px;
    color: var(--chat-gray-700);
    text-align: center;
}

.chat-form-group {
    margin-bottom: 12px;
}

.chat-form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--chat-gray-600);
    margin-bottom: 6px;
}

.chat-form-group input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--chat-gray-300);
    border-radius: 10px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.chat-form-group input:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-start-btn {
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-top: 8px;
    transition: transform 0.2s;
}

.chat-start-btn:hover {
    transform: translateY(-2px);
}

/* ============ واجهة الأدمن ============ */
.admin-chat-container {
    display: flex;
    height: calc(100vh - 200px);
    min-height: 500px;
    background: var(--chat-white);
    border-radius: var(--chat-radius);
    overflow: hidden;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

/* قائمة المحادثات */
.chat-conversations-list {
    width: 320px;
    border-right: 1px solid var(--chat-gray-200);
    display: flex;
    flex-direction: column;
    background: var(--chat-white);
}

[dir="rtl"] .chat-conversations-list {
    border-right: none;
    border-left: 1px solid var(--chat-gray-200);
}

.chat-list-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--chat-gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-list-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--chat-gray-700);
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Chat enable/disable toggle */
.chat-toggle-switch {
    position: relative;
    width: 36px;
    height: 20px;
    background: var(--chat-gray-300, #d1d5db);
    border-radius: 10px;
    transition: background 0.2s;
    flex-shrink: 0;
}
.chat-toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}
.chat-toggle-checkbox:checked + .chat-toggle-switch {
    background: var(--rd-success, #10b981);
}
.chat-toggle-checkbox:checked + .chat-toggle-switch::after {
    transform: translateX(16px);
}

.chat-search-input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--chat-gray-200);
    border-radius: 10px;
    margin: 12px 16px;
    font-size: 14px;
}

.chat-conversations {
    flex: 1;
    overflow-y: auto;
}

.chat-conversation-item {
    padding: 14px 20px;
    border-bottom: 1px solid var(--chat-gray-100);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    gap: 12px;
    align-items: center;
}

.chat-conversation-item:hover {
    background: var(--chat-gray-50);
}

.chat-conversation-item.active {
    background: rgba(0, 30, 98, 0.08);
    border-left: 3px solid var(--chat-primary);
}

[dir="rtl"] .chat-conversation-item.active {
    border-left: none;
    border-right: 3px solid var(--chat-primary);
}

.chat-conversation-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--chat-primary), var(--chat-primary-light));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    flex-shrink: 0;
}

.chat-conversation-info {
    flex: 1;
    min-width: 0;
}

.chat-conversation-name {
    font-weight: 600;
    font-size: 14px;
    color: var(--chat-gray-700);
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-conversation-name .unread-badge {
    background: #dc3545;
    color: white;
    font-size: 11px;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
}

.chat-conversation-preview {
    font-size: 13px;
    color: var(--chat-gray-500);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-conversation-time {
    font-size: 11px;
    color: var(--chat-gray-400);
    margin-top: 4px;
}

/* منطقة المحادثة للأدمن */
.admin-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-gray-100);
}

.admin-chat-header {
    padding: 16px 20px;
    background: var(--chat-white);
    border-bottom: 1px solid var(--chat-gray-200);
    display: flex;
    align-items: center;
    gap: 12px;
}

.admin-chat-user-info {
    flex: 1;
}

.admin-chat-user-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--chat-gray-700);
}

.admin-chat-user-email {
    font-size: 12px;
    color: var(--chat-gray-500);
}

.admin-chat-actions {
    display: flex;
    gap: 8px;
}

.admin-chat-action-btn {
    padding: 8px 12px;
    border: 1px solid var(--chat-gray-300);
    border-radius: 8px;
    background: var(--chat-white);
    cursor: pointer;
    font-size: 13px;
    color: var(--chat-gray-600);
    transition: all 0.2s;
}

.admin-chat-action-btn:hover {
    background: var(--chat-gray-100);
    border-color: var(--chat-primary);
    color: var(--chat-primary);
}

.admin-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* الردود السريعة */
.quick-replies-bar {
    padding: 8px 16px;
    background: var(--chat-white);
    border-top: 1px solid var(--chat-gray-200);
    display: flex;
    gap: 8px;
    overflow-x: auto;
}

.quick-reply-btn {
    padding: 6px 12px;
    background: var(--chat-gray-100);
    border: 1px solid var(--chat-gray-200);
    border-radius: 16px;
    font-size: 12px;
    color: var(--chat-gray-600);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.quick-reply-btn:hover {
    background: var(--chat-primary);
    color: white;
    border-color: var(--chat-primary);
}

/* رسالة عدم وجود محادثة محددة */
.no-chat-selected {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--chat-gray-500);
    text-align: center;
    padding: 40px;
}

.no-chat-selected-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

.no-chat-selected h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--chat-gray-600);
}

/* ============ Responsive ============ */
@media (max-width: 768px) {
    .chat-widget {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
    }

    [dir="rtl"] .chat-widget {
        left: 0;
        right: 0;
    }

    .chat-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    [dir="rtl"] .chat-fab {
        right: auto;
        left: 16px;
    }

    .admin-chat-container {
        flex-direction: column;
        height: auto;
    }

    .chat-conversations-list {
        width: 100%;
        max-height: 300px;
        border-right: none;
        border-bottom: 1px solid var(--chat-gray-200);
    }

    [dir="rtl"] .chat-conversations-list {
        border-left: none;
    }

    .admin-chat-area {
        min-height: 400px;
    }
}

/* ============ تبويب الشات في لوحة الأدمن ============ */
#chatTab {
    padding: 0;
}

#chatTab .admin-chat-container {
    margin: 0;
    border-radius: 0;
    height: calc(100vh - 250px);
}

@media (prefers-color-scheme: dark) {
    .admin-chat-container,
    .chat-window,
    .chat-container,
    .chat-panel,
    .chat-body,
    .chat-messages,
    .chat-widget,
    .chat-popup,
    .chat-box {
        background-color: var(--chat-bg);
        color: var(--chat-gray-700);
    }

    .chat-input-area,
    .chat-input,
    .chat-footer,
    .chat-compose,
    .chat-header,
    .chat-toolbar {
        background-color: var(--chat-white);
        color: var(--chat-gray-700);
        border-color: var(--chat-gray-200);
    }

    .chat-message,
    .message-bubble,
    .msg,
    .bubble,
    .message.incoming,
    .message.received,
    .chat-bubble.them {
        background-color: var(--chat-gray-100);
        color: var(--chat-gray-700);
    }

    .message.outgoing,
    .message.sent,
    .chat-bubble.me,
    .bubble.mine {
        background-color: var(--chat-primary);
        color: #ffffff;
    }

    .admin-chat-fab:not(.has-unread),
    body:has(#chatTab.active) .admin-chat-fab {
        background: var(--chat-white);
        color: var(--chat-gray-700);
    }
}

