/* --- رنگ برند نارنجی و تنظیمات اصلی --- */
:root {
    --mpc-brand-color: #FF7043; /* نارنجی گرم و دلنشین */
    --mpc-brand-dark: #E65100; /* نارنجی تیره برای هاور */
    --mpc-accent-color: #4CAF50; /* سبز برای دکمه‌های اکشن */
    --mpc-bg-light: #FBFBFC; /* پس‌زمینه بسیار روشن */
    --mpc-shadow-deep: 0 18px 50px rgba(0, 0, 0, 0.25);
    --mpc-radius-lg: 24px;
    --mpc-radius-md: 16px;
    --mpc-radius-sm: 10px;
}

body {
    font-family: 'Vazirmatn', Tahoma, sans-serif; 
    direction: rtl;
}

#mpc-chatbot-container {
    /* موقعیت ثابت برای دسکتاپ */
    position: fixed;
    bottom: 30px;
    right: 30px; 
    z-index: 9999;
    font-family: 'Vazirmatn', Tahoma, sans-serif;
    direction: rtl; 
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.27, 1.55); 
}

/* --- ساختار جدید برای لوگو و کپشن --- */
.mpc-toggle-wrapper {
    display: flex;
    align-items: center;
    flex-direction: row; 
    justify-content: flex-end; 
}

.mpc-toggle-caption {
    background-color: var(--mpc-brand-color);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: 500;
    margin-right: 0; 
    margin-left: 10px; 
    box-shadow: 0 4px 10px rgba(255, 112, 67, 0.4);
    transition: opacity 0.3s;
}

/* --- دکمه باز کردن (AI) --- */
#mpc-chatbot-toggle {
    width: 65px; 
    height: 65px;
    
    background: linear-gradient(135deg, var(--mpc-brand-color) 0%, #FFAB40 100%); 
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(255, 112, 67, 0.6); 
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    overflow: hidden; 
}

#mpc-chatbot-toggle:hover {
    transform: scale(1.08); 
    box-shadow: 0 15px 30px rgba(255, 112, 67, 0.8);
}

/* --- لوگوی OpenAI (پس زمینه) --- */
.ai-background-icon {
    position: absolute;
    width: 100%;
    height: 100%;
    opacity: 0.15; 
    z-index: 1;
    color: white;
    transform: rotate(10deg);
}

/* --- متن AI (ساده و ضخیم) --- */
.ai-text-logo {
    font-size: 26px; 
    font-weight: 900; 
    font-family: 'Vazirmatn', Tahoma, sans-serif; 
    color: white; 
    line-height: 1; 
    position: relative; 
    z-index: 2;
    text-shadow: none; 
    animation: none;
}

/* --- پنجره چت اصلی --- */
#mpc-chatbot-window {
    width: 380px; 
    height: 580px; 
    background-color: #ffffff;
    border-radius: var(--mpc-radius-lg);
    box-shadow: var(--mpc-shadow-deep);
    margin-top: -20px; 
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95); 
    opacity: 0;
    animation: fadeInScale 0.4s forwards cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.9); }
    to { opacity: 1; transform: scale(1); }
}

/* --- هدر --- */
#mpc-chatbot-header {
    background: linear-gradient(135deg, var(--mpc-brand-color) 0%, #FFAB40 100%); 
    color: white;
    padding: 18px 25px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: bold;
    font-size: 14px; 
    border-bottom: 4px solid #FFECB3; 
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    line-height: 1.2; 
}

#mpc-chatbot-header span {
    letter-spacing: 0.5px; 
    white-space: nowrap; 
    overflow: hidden;
    text-overflow: ellipsis;
}

#mpc-close-button {
    background: none;
    border: none;
    color: white;
    font-size: 30px;
    cursor: pointer;
    padding: 0 8px;
    line-height: 1;
    transition: transform 0.3s ease, color 0.3s;
    opacity: 0.8;
}
#mpc-close-button:hover {
    transform: rotate(90deg) scale(1.1);
    color: #ffe0b2;
    opacity: 1;
}

/* --- ناحیه پیام‌ها --- */
#mpc-chatbot-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--mpc-bg-light); 
    direction: rtl;
    text-align: right;
    border-bottom: 1px solid #ECEFF1;
}
#mpc-chatbot-messages::-webkit-scrollbar {
    width: 8px;
}
#mpc-chatbot-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
    border: 2px solid var(--mpc-bg-light); 
}
#mpc-chatbot-messages::-webkit-scrollbar-track {
    background: transparent;
}


/* استایل‌های پیام‌ها */
.mpc-bot-message {
    background-color: #E0F2F7; 
    color: #4A4A4A;
    float: right;
    border-radius: 20px 20px 20px 6px;
    font-weight: 500;
    width: auto !important; 
    max-width: 80% !important; 
}
.mpc-bot-message.mpc-initial-message {
    background-color: #CFE2F3; 
}


.mpc-user-message {
    background-color: var(--mpc-brand-color);
    color: white;
    float: left;
    border-radius: 20px 20px 6px 20px;
}

.mpc-bot-message, .mpc-user-message {
    padding: 14px 20px;
    max-width: 80%; 
    margin-bottom: 15px; 
    font-size: 15.5px;
    line-height: 1.7;
    clear: both;
    word-wrap: break-word; 
    animation: messagePop 0.3s ease-out; 
}

@keyframes messagePop {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.mpc-bot-message.mpc-loading {
    background-color: #E0E0E0;
    color: #777;
    font-style: italic;
    animation: pulse 1.2s infinite ease-in-out;
}

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

.mpc-bot-message .highlight {
    color: var(--mpc-brand-dark);
    font-weight: bold;
}


/* --- ناحیه ورودی --- */
#mpc-chatbot-input-area {
    display: flex;
    padding: 15px;
    border-top: 1px solid #eee; 
    background-color: #fff;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.05); 
}

#mpc-user-input {
    flex-grow: 1;
    padding: 12px 18px;
    border: 1px solid #e0e0e0; 
    border-radius: 28px; 
    margin-left: 10px;
    font-size: 16px;
    direction: rtl;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
    background-color: #fcfcfc;
}

#mpc-user-input:focus {
    border-color: var(--mpc-brand-color);
    box-shadow: 0 0 8px rgba(255, 112, 67, 0.3);
}

#mpc-send-button {
    width: 55px; 
    height: 55px; 
    background-color: var(--mpc-brand-color);
    color: white;
    border: none;
    border-radius: 50%; 
    cursor: pointer;
    font-size: 16px;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 12px rgba(255, 112, 67, 0.4);
    transition: background-color 0.3s, transform 0.2s ease-out, box-shadow 0.3s;
}
#mpc-send-button:hover {
    background-color: var(--mpc-brand-dark);
    transform: scale(1.05);
    box-shadow: 0 6px 15px rgba(255, 112, 67, 0.6);
}
#mpc-send-button .send-icon {
    stroke: white;
    width: 28px;
    height: 28px;
}

/* --- کارت محصولات (نمایش GRID) --- */
.mpc-products-grid { 
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); 
    gap: 15px; 
    margin-top: 15px;
    padding: 0 5px;
    justify-content: center;
    margin-right: auto; 
    margin-left: auto;
    clear: both;
}

.mpc-product-card {
    display: flex;
    flex-direction: column; 
    background-color: #ffffff;
    border: 1px solid #E0E0E0;
    border-radius: var(--mpc-radius-md);
    text-decoration: none;
    color: #333;
    box-shadow: 0 6px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s ease, box-shadow 0.3s;
    overflow: hidden; 
    text-align: center; 
    width: 100%; 
}

.mpc-product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
}

.mpc-product-image-wrapper {
    width: 100%;
    height: 120px; 
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 10px;
    background-color: #F8F9FA;
    border-bottom: 1px solid #ECEFF1;
}

.mpc-product-image-wrapper img {
    max-width: 90%;
    max-height: 90%;
    object-fit: contain; 
    border-radius: var(--mpc-radius-sm);
}

.mpc-product-details {
    padding: 12px;
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
    justify-content: space-between; 
}

.mpc-product-title {
    font-size: 15px;
    color: #333;
    display: -webkit-box; 
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 8px; 
    min-height: 38px; 
    font-weight: 600;
}

.mpc-product-price {
    font-size: 14px;
    color: var(--mpc-brand-dark); 
    font-weight: 700;
    margin-top: auto; 
}
.mpc-product-price .price-unavailable {
    color: #D32F2F; 
    font-weight: normal;
    font-size: 13px;
}

/* === رسپانسیو برای موبایل و تبلت کوچک (عرض کمتر از 500 پیکسل) === */
@media (max-width: 500px) {
    
    #mpc-chatbot-container {
        position: fixed; 
        /* --- مهم: افزایش فاصله از پایین و راست برای تراز (35px) --- */
        bottom: calc(75px + env(safe-area-inset-bottom, 0px)); 
        right: 35px; /* از 30px به 35px افزایش یافت */
        left: auto; 
        width: auto;
        transform: none; 
    }

    .mpc-toggle-wrapper {
        position: static; 
        bottom: auto;
        right: auto;
        margin-bottom: 0; 
        z-index: 10000;
        flex-direction: row; 
    }
    
    .mpc-toggle-caption {
        font-size: 13px;
        margin-right: 0; 
        margin-left: 10px; 
    }

    #mpc-chatbot-toggle {
        width: 55px; 
        height: 55px;
        box-shadow: 0 8px 20px rgba(255, 112, 67, 0.5);
    }
    .ai-text-logo {
        font-size: 20px; 
    }
    .ai-background-icon {
        opacity: 0.1;
    }

    #mpc-chatbot-window {
        position: fixed;
        /* --- موقعیت نهایی پنجره چت --- */
        bottom: calc(140px + env(safe-area-inset-bottom, 0px)); 
        right: 20px; /* هم‌تراز با کانتینر در موبایل */
        left: auto; 
        top: auto; 
        margin: 0; 
        width: 90vw; 
        height: 75vh; 
        max-width: 400px;
        max-height: 600px;
        animation: slideInUp 0.4s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94); 
    }

    @keyframes slideInUp {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
    
    #mpc-chatbot-header {
        padding: 15px 20px;
        font-size: 14px; 
    }
    #mpc-close-button {
        font-size: 26px;
    }

    #mpc-chatbot-messages {
        padding: 15px;
    }

    .mpc-bot-message, .mpc-user-message {
        font-size: 14.5px;
        padding: 12px 18px;
        margin-bottom: 10px;
    }

    #mpc-chatbot-input-area {
        padding: 10px;
    }
    #mpc-user-input {
        padding: 10px 15px;
        font-size: 15px;
    }
    #mpc-send-button {
        width: 50px;
        height: 50px;
    }
    #mpc-send-button .send-icon {
        width: 26px;
        height: 26px;
    }

    .mpc-products-grid {
        grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); 
        gap: 12px;
    }
    .mpc-product-image-wrapper {
        height: 90px;
    }
    .mpc-product-title {
        font-size: 14px;
        min-height: 36px;
    }
    .mpc-product-price {
        font-size: 13px;
    }
}

/* === رسپانسیو برای تبلت (عرض بین 501 پیکسل تا 800 پیکسل) === */
@media (min-width: 501px) and (max-width: 800px) {
    /* --- تنظیم موقعیت برای تبلت‌ها --- */
    #mpc-chatbot-container {
        bottom: 90px; 
        right: 35px; 
    }

    #mpc-chatbot-window {
        bottom: 165px; 
        right: 35px;
        width: 380px; 
        height: 580px;
    }
}