/* ===== AI ASSISTANT STYLES ===== */

/* زر المساعد - في الجهة اليمنى */
.ai-assistant-button {
    position: fixed;
    bottom: 30px;
    right: 30px;
    z-index: 999;
    background: var(--color-emerald, #1a4d3e);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    font-size: 28px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
}

.ai-assistant-button:hover {
    transform: scale(1.08) translateY(-4px);
    box-shadow: 0 12px 40px rgba(26,77,62,0.4);
}

.ai-assistant-button .badge-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    background: var(--color-gold, #c9a84c);
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: pulse-dot 2s infinite;
}

@keyframes pulse-dot {
    0% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.3); opacity: 0.6; }
    100% { transform: scale(1); opacity: 1; }
}

/* نافذة الشات - في الجهة اليمنى */
.ai-chat-window {
    position: fixed;
    bottom: 100px;
    right: 30px;
    width: 450px;
    max-width: calc(100vw - 60px);
    max-height: 80vh;
    background: #fff;
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1000;
    border: 1px solid rgba(0,0,0,0.06);
    animation: slideUp 0.3s ease;
}

.ai-chat-window.active {
    display: flex;
}

@keyframes slideUp {
    0% { opacity: 0; transform: translateY(20px) scale(0.96); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

/* رأس النافذة */
.ai-chat-header {
    background: var(--color-emerald, #1a4d3e);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--color-gold, #c9a84c);
    flex-shrink: 0;
}

.ai-chat-header h3 {
    margin: 0;
    font-size: clamp(1rem, 1.2vw, 1.2rem);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
}

.ai-chat-header h3 i {
    color: var(--color-gold, #c9a84c);
}

.ai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 26px;
    cursor: pointer;
    padding: 0 6px;
    opacity: 0.7;
    transition: opacity 0.3s;
    line-height: 1;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
}

.ai-chat-close:hover {
    opacity: 1;
}

/* منطقة الرسائل */
.ai-chat-messages {
    flex: 1;
    padding: 16px 20px;
    overflow-y: auto;
    background: #f9fafc;
    max-height: 55vh;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-chat-messages .message {
    max-width: 95%;
    padding: 12px 16px;
    border-radius: 16px;
    line-height: 1.6;
    font-size: clamp(0.9rem, 1vw, 0.95rem);
    word-wrap: break-word;
    animation: msgIn 0.25s ease;
}

@keyframes msgIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.ai-chat-messages .user-msg {
    align-self: flex-end;
    background: var(--color-emerald, #1a4d3e);
    color: #fff;
    border-bottom-right-radius: 4px;
    max-width: 80%;
}

.ai-chat-messages .assistant-msg {
    align-self: flex-start;
    background: #fff;
    color: #1a1a2e;
    border-bottom-left-radius: 4px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.06);
    border: 1px solid #eee;
    max-width: 95%;
    padding: 16px 20px;
}

.ai-chat-messages .assistant-msg.welcome {
    background: var(--color-cream, #f9f6ef);
    border-color: var(--color-gold-light, #f5d78c);
    border-width: 2px;
}

/* مؤشر الكتابة */
.ai-chat-messages .typing-indicator {
    align-self: flex-start;
    background: #fff;
    padding: 12px 18px;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    display: flex;
    gap: 6px;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    border: 1px solid #eee;
}

.ai-chat-messages .typing-indicator span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--color-gray, #4b5563);
    animation: typing 1.4s infinite both;
}

.ai-chat-messages .typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.ai-chat-messages .typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* منطقة الإدخال */
.ai-chat-input-area {
    display: flex;
    border-top: 1px solid #eee;
    padding: 12px 16px;
    gap: 10px;
    background: #fff;
    flex-shrink: 0;
}

.ai-chat-input-area input {
    flex: 1;
    border: 1px solid #ddd;
    border-radius: 30px;
    padding: 12px 18px;
    font-size: clamp(0.9rem, 1vw, 1rem);
    outline: none;
    transition: border-color 0.3s;
    font-family: var(--font-body, 'Inter', sans-serif);
    min-height: var(--touch-min);
}

.ai-chat-input-area input:focus {
    border-color: var(--color-emerald, #1a4d3e);
}

.ai-chat-input-area button {
    background: var(--color-emerald, #1a4d3e);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.3s, transform 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    min-height: var(--touch-min);
    min-width: var(--touch-min);
}

.ai-chat-input-area button:hover {
    background: var(--color-emerald-dark, #0f3328);
    transform: scale(1.05);
}

.ai-chat-input-area button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* ===== أنماط رسالة الترحيب المنبثقة (toast) ===== */
.ai-welcome-toast {
    position: fixed;
    bottom: 100px;
    right: 30px;
    z-index: 1001;
    background: var(--color-emerald, #1a4d3e);
    color: #fff;
    padding: 14px 22px;
    border-radius: 16px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.25);
    font-size: 1rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 12px;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    transition: opacity 0.4s ease, transform 0.4s ease;
    pointer-events: none;
    border: 1px solid var(--color-gold, #c9a84c);
    direction: rtl;
    max-width: 90vw;
}
.ai-welcome-toast.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}
.ai-welcome-toast .toast-icon {
    font-size: 1.8rem;
}
.ai-welcome-toast .toast-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    font-size: 1.4rem;
    cursor: pointer;
    padding: 0 6px;
    pointer-events: auto;
    line-height: 1;
}
.ai-welcome-toast .toast-close:hover {
    color: #fff;
}

/* ===== RESPONSIVE ===== */

/* الهواتف (≤768px) */
@media (max-width: 768px) {
    .ai-assistant-button {
        left: auto;
        right: 20px;
        bottom: 20px;
        width: 52px;
        height: 52px;
        font-size: 22px;
    }

    .ai-chat-window {
        left: auto;
        right: 10px;
        bottom: 80px;
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        max-height: 75vh;
        border-radius: 14px;
        box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    }

    .ai-welcome-toast {
        right: 20px;
        bottom: 80px;
        padding: 10px 16px;
        font-size: 0.9rem;
        max-width: calc(100vw - 40px);
    }

    .ai-chat-messages {
        max-height: 50vh;
        padding: 10px 12px;
        gap: 8px;
    }

    .ai-chat-messages .message {
        font-size: 0.75rem;
        padding: 8px 12px;
        border-radius: 12px;
        line-height: 1.5;
    }

    .ai-chat-messages .assistant-msg {
        padding: 10px 14px;
        font-size: 0.75rem;
    }

    .ai-chat-messages .assistant-msg.welcome {
        font-size: 0.75rem;
    }

    .ai-chat-messages .user-msg {
        font-size: 0.75rem;
    }

    .ai-chat-messages .assistant-msg ul,
    .ai-chat-messages .assistant-msg li {
        font-size: 0.75rem;
    }

    .ai-chat-messages .assistant-msg .product-card,
    .ai-chat-messages .assistant-msg div[style] {
        font-size: 0.75rem !important;
    }

    .ai-chat-header {
        padding: 10px 14px;
    }
    .ai-chat-header h3 {
        font-size: 0.9rem;
    }
    .ai-chat-close {
        font-size: 20px;
    }

    .ai-chat-input-area {
        padding: 8px 12px;
        gap: 6px;
    }
    .ai-chat-input-area input {
        font-size: 0.8rem;
        padding: 8px 12px;
        min-height: 38px;
    }
    .ai-chat-input-area button {
        width: 38px;
        height: 38px;
        font-size: 15px;
    }

    .ai-chat-messages .assistant-msg div[style*="background:#f9f9f9"] {
        font-size: 0.7rem !important;
        padding: 6px 10px !important;
    }
}

/* الهواتف الصغيرة (≤480px) */
@media (max-width: 480px) {
    .ai-assistant-button {
        right: 16px;
        bottom: 16px;
        width: 46px;
        height: 46px;
        font-size: 18px;
    }

    .ai-chat-window {
        right: 6px;
        bottom: 68px;
        width: calc(100vw - 12px);
        max-width: calc(100vw - 12px);
        max-height: 70vh;
        border-radius: 12px;
    }

    .ai-welcome-toast {
        right: 16px;
        bottom: 70px;
        padding: 8px 14px;
        font-size: 0.8rem;
        max-width: calc(100vw - 32px);
    }

    .ai-chat-messages {
        max-height: 45vh;
        padding: 8px 10px;
        gap: 6px;
    }

    .ai-chat-messages .message {
        font-size: 0.65rem;
        padding: 6px 10px;
        border-radius: 10px;
        line-height: 1.4;
    }

    .ai-chat-messages .assistant-msg {
        padding: 8px 12px;
        font-size: 0.65rem;
    }

    .ai-chat-messages .assistant-msg.welcome {
        font-size: 0.65rem;
    }

    .ai-chat-messages .user-msg {
        font-size: 0.65rem;
    }

    .ai-chat-messages .assistant-msg ul,
    .ai-chat-messages .assistant-msg li {
        font-size: 0.65rem;
    }

    .ai-chat-messages .assistant-msg .product-card,
    .ai-chat-messages .assistant-msg div[style] {
        font-size: 0.65rem !important;
    }

    .ai-chat-header {
        padding: 8px 12px;
    }
    .ai-chat-header h3 {
        font-size: 0.8rem;
    }
    .ai-chat-close {
        font-size: 18px;
    }

    .ai-chat-input-area {
        padding: 6px 10px;
        gap: 6px;
    }
    .ai-chat-input-area input {
        font-size: 0.7rem;
        padding: 6px 10px;
        min-height: 34px;
    }
    .ai-chat-input-area button {
        width: 34px;
        height: 34px;
        font-size: 13px;
    }

    .ai-chat-messages .assistant-msg div[style*="background:#f9f9f9"] {
        font-size: 0.6rem !important;
        padding: 4px 8px !important;
    }
}

/* شاشات صغيرة جداً (≤360px) */
@media (max-width: 360px) {
    .ai-assistant-button {
        right: 12px;
        bottom: 12px;
        width: 40px;
        height: 40px;
        font-size: 16px;
    }

    .ai-chat-window {
        right: 4px;
        bottom: 60px;
        width: calc(100vw - 8px);
        max-width: calc(100vw - 8px);
        max-height: 65vh;
        border-radius: 10px;
    }

    .ai-welcome-toast {
        right: 12px;
        bottom: 60px;
        padding: 6px 12px;
        font-size: 0.7rem;
        max-width: calc(100vw - 24px);
    }

    .ai-chat-messages {
        max-height: 40vh;
        padding: 6px 8px;
        gap: 6px;
    }

    .ai-chat-messages .message {
        font-size: 0.6rem;
        padding: 5px 8px;
        line-height: 1.3;
        border-radius: 8px;
    }

    .ai-chat-messages .assistant-msg {
        padding: 6px 10px;
        font-size: 0.6rem;
    }

    .ai-chat-messages .assistant-msg.welcome {
        font-size: 0.6rem;
    }

    .ai-chat-messages .user-msg {
        font-size: 0.6rem;
    }

    .ai-chat-messages .assistant-msg ul,
    .ai-chat-messages .assistant-msg li {
        font-size: 0.6rem;
    }

    .ai-chat-messages .assistant-msg .product-card,
    .ai-chat-messages .assistant-msg div[style] {
        font-size: 0.6rem !important;
    }

    .ai-chat-header h3 {
        font-size: 0.7rem;
    }
    .ai-chat-close {
        font-size: 16px;
    }

    .ai-chat-input-area input {
        font-size: 0.65rem;
        padding: 5px 8px;
        min-height: 30px;
    }
    .ai-chat-input-area button {
        width: 30px;
        height: 30px;
        font-size: 12px;
    }

    .ai-chat-messages .assistant-msg div[style*="background:#f9f9f9"] {
        font-size: 0.55rem !important;
        padding: 4px 6px !important;
    }
}