/* =============================================
   شات بوت نيكسيون فيجن الذكي - Widget
   تصميم عائم حديث مع glassmorphism
   ============================================= */

:root {
    --chatbot-primary: #6366f1;
    --chatbot-primary-dark: #4f46e5;
    --chatbot-primary-light: #818cf8;
    --chatbot-gradient: linear-gradient(135deg, #6366f1, #8b5cf6, #a78bfa);
    --chatbot-gradient-hover: linear-gradient(135deg, #4f46e5, #7c3aed, #8b5cf6);
    --chatbot-bg: #0f172a;
    --chatbot-bg-light: #1e293b;
    --chatbot-surface: #1e293b;
    --chatbot-text: #f1f5f9;
    --chatbot-text-muted: #94a3b8;
    --chatbot-border: rgba(148, 163, 184, 0.1);
    --chatbot-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --chatbot-user-msg: linear-gradient(135deg, #6366f1, #8b5cf6);
    --chatbot-bot-msg: #1e293b;
    --chatbot-radius: 16px;
    --chatbot-width: 400px;
    --chatbot-height: 600px;
}

/* ===== زر الفقاعة العائمة ===== */
.chatbot-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: var(--chatbot-gradient);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4), 0 0 0 0 rgba(99, 102, 241, 0.3);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    animation: chatbot-pulse 2s infinite;
}

.chatbot-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 40px rgba(99, 102, 241, 0.5);
    animation: none;
}

.chatbot-fab.active {
    animation: none;
    transform: rotate(0deg);
}

.chatbot-fab svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.3s ease;
}

.chatbot-fab.active svg.icon-chat {
    display: none;
}

.chatbot-fab.active svg.icon-close {
    display: block;
}

.chatbot-fab svg.icon-close {
    display: none;
}

.chatbot-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #ef4444;
    border-radius: 50%;
    border: 2px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    color: white;
    font-weight: 700;
}

@keyframes chatbot-pulse {
    0% { box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4), 0 0 0 0 rgba(99, 102, 241, 0.3); }
    70% { box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4), 0 0 0 16px rgba(99, 102, 241, 0); }
    100% { box-shadow: 0 8px 32px rgba(99, 102, 241, 0.4), 0 0 0 0 rgba(99, 102, 241, 0); }
}

/* ===== نافذة الشات ===== */
.chatbot-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    z-index: 9998;
    width: var(--chatbot-width);
    height: var(--chatbot-height);
    max-height: calc(100vh - 140px);
    background: var(--chatbot-bg);
    border-radius: var(--chatbot-radius);
    box-shadow: var(--chatbot-shadow);
    border: 1px solid var(--chatbot-border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.chatbot-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ===== الهيدر ===== */
.chatbot-header {
    background: var(--chatbot-gradient);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.chatbot-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
}

.chatbot-header-info {
    flex: 1;
    min-width: 0;
}

.chatbot-header-title {
    font-size: 15px;
    font-weight: 700;
    color: white;
    margin: 0;
    line-height: 1.3;
}

.chatbot-header-status {
    font-size: 12px;
    color: rgba(255, 255, 255, 0.8);
    display: flex;
    align-items: center;
    gap: 5px;
}

.chatbot-header-status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    display: inline-block;
    animation: chatbot-status-pulse 2s infinite;
}

@keyframes chatbot-status-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.chatbot-close-btn {
    background: rgba(255, 255, 255, 0.15);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    color: white;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}

.chatbot-close-btn:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ===== منطقة الرسائل ===== */
.chatbot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.chatbot-messages::-webkit-scrollbar {
    width: 4px;
}

.chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chatbot-messages::-webkit-scrollbar-thumb {
    background: rgba(148, 163, 184, 0.2);
    border-radius: 4px;
}

/* ===== فقاعات الرسائل ===== */
.chatbot-msg {
    display: flex;
    gap: 8px;
    max-width: 88%;
    animation: chatbot-msg-in 0.3s ease-out;
}

.chatbot-msg.user {
    align-self: flex-start;
    flex-direction: row;
}

.chatbot-msg.bot {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chatbot-msg-avatar {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
    margin-top: 2px;
}

.chatbot-msg.bot .chatbot-msg-avatar {
    background: var(--chatbot-gradient);
}

.chatbot-msg.user .chatbot-msg-avatar {
    background: #334155;
}

.chatbot-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
}

.chatbot-msg.user .chatbot-msg-bubble {
    background: #334155;
    color: var(--chatbot-text);
    border-bottom-right-radius: 4px;
}

.chatbot-msg.bot .chatbot-msg-bubble {
    background: var(--chatbot-user-msg);
    color: white;
    border-bottom-left-radius: 4px;
}

.chatbot-msg-bubble strong {
    font-weight: 600;
}

.chatbot-msg-bubble ul, .chatbot-msg-bubble ol {
    margin: 4px 0;
    padding-right: 16px;
}

.chatbot-msg-bubble li {
    margin-bottom: 2px;
}

@keyframes chatbot-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== مؤشر الكتابة ===== */
.chatbot-typing {
    display: flex;
    gap: 8px;
    align-self: flex-end;
    flex-direction: row-reverse;
    max-width: 88%;
}

.chatbot-typing-dots {
    background: var(--chatbot-surface);
    border: 1px solid var(--chatbot-border);
    padding: 12px 18px;
    border-radius: 14px;
    display: flex;
    gap: 4px;
    align-items: center;
}

.chatbot-typing-dots span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chatbot-primary-light);
    animation: chatbot-typing-bounce 1.4s ease-in-out infinite;
}

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

.chatbot-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatbot-typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ===== الاقتراحات ===== */
.chatbot-suggestions {
    padding: 8px 16px 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.chatbot-suggestion-btn {
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    color: var(--chatbot-primary-light);
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
    white-space: nowrap;
}

.chatbot-suggestion-btn:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.4);
    transform: translateY(-1px);
}

/* ===== منطقة الإدخال ===== */
.chatbot-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--chatbot-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    background: var(--chatbot-bg);
    flex-shrink: 0;
}

.chatbot-input {
    flex: 1;
    background: var(--chatbot-surface);
    border: 1px solid var(--chatbot-border);
    border-radius: 12px;
    padding: 10px 14px;
    color: var(--chatbot-text);
    font-size: 14px;
    font-family: inherit;
    resize: none;
    max-height: 80px;
    min-height: 40px;
    line-height: 1.4;
    outline: none;
    transition: border-color 0.2s;
}

.chatbot-input::placeholder {
    color: var(--chatbot-text-muted);
}

.chatbot-input:focus {
    border-color: var(--chatbot-primary);
}

.chatbot-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--chatbot-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.chatbot-send-btn:hover:not(:disabled) {
    background: var(--chatbot-gradient-hover);
    transform: scale(1.05);
}

.chatbot-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.chatbot-send-btn svg {
    width: 18px;
    height: 18px;
    fill: white;
    transform: rotate(180deg);
}

/* ===== رسالة الترحيب ===== */
.chatbot-welcome {
    text-align: center;
    padding: 24px 16px;
}

.chatbot-welcome-emoji {
    font-size: 48px;
    margin-bottom: 12px;
    animation: chatbot-wave 2s ease-in-out 1;
}

@keyframes chatbot-wave {
    0%, 100% { transform: rotate(0deg); }
    25% { transform: rotate(20deg); }
    50% { transform: rotate(-10deg); }
    75% { transform: rotate(15deg); }
}

.chatbot-welcome h3 {
    color: var(--chatbot-text);
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 6px;
}

.chatbot-welcome p {
    color: var(--chatbot-text-muted);
    font-size: 13px;
    margin: 0;
    line-height: 1.5;
}

/* ===== Footer ===== */
.chatbot-footer {
    padding: 6px 16px 8px;
    text-align: center;
    font-size: 10px;
    color: var(--chatbot-text-muted);
    opacity: 0.5;
    flex-shrink: 0;
}

/* ===== خطأ ===== */
.chatbot-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    margin: 4px 0;
}

/* ===== Responsive — Mobile fullscreen ===== */
@media (max-width: 480px) {
    .chatbot-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        max-height: none !important;
        border-radius: 0 !important;
        z-index: 99999 !important;
        transform: none !important;
        margin: 0 !important;
    }

    .chatbot-window.open {
        transform: none !important;
        opacity: 1;
        pointer-events: all;
    }

    .chatbot-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chatbot-fab.active {
        opacity: 0;
        pointer-events: none;
        transform: scale(0);
    }

    .chatbot-fab svg {
        width: 24px;
        height: 24px;
    }

    .chatbot-header {
        padding: 12px 16px;
    }

    .chatbot-footer {
        display: none;
    }
}

/* ===== body lock when chatbot is open on mobile ===== */
body.chatbot-open-mobile {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    overflow: hidden !important;
}

@media (min-width: 481px) and (max-width: 768px) {
    :root {
        --chatbot-width: 360px;
        --chatbot-height: 520px;
    }
}

