/* index.css - نسخه اصلاح شده نهایی برای رفع مشکل پرش صفحه و تداخل موبایل */

/* 🔑 اصلاح حیاتی: تضمین محاسبه درست عرض و ارتفاع (عرض + پدینگ + بردر = اندازه نهایی) */
* {
    box-sizing: border-box;
}

/* =================================================== */
/* --- ۱. معرفی فونت فارسی IRANSansWeb --- */
/* =================================================== */
@font-face {
    font-family: 'IRANSansWeb';
    src: url('../fonts/IRANSansWeb.eot'); /* IE9 Compat Modes */
    src: url('../fonts/IRANSansWeb.eot?#iefix') format('embedded-opentype'), /* IE6-IE8 */
         url('../fonts/IRANSansWeb.woff2') format('woff2'), /* Super Modern Browsers */
         url('../fonts/IRANSansWeb.woff') format('woff'), /* Modern Browsers */
         url('../fonts/IRANSansWeb.ttf') format('truetype'); /* Safari, Android, iOS */
    font-weight: normal;
    font-style: normal;
}

/* =================================================== */
/* سبک‌های صفحه فروشگاه (واکنش‌گرا و مدرن) */
/* =================================================== */
:root {
    --primary-color: green;  /* سبز*/
    --secondary-color: #ffc107; /* زرد/نارنجی */
    --background-light: #f4f7f6;
    --text-dark: #333;

    /* 🔑 متغیرهای ارتفاع برای ثابت نگه داشتن Top Banner, Header و Category Bar (مقدارهای پیش‌فرض دسکتاپ) */
    --banner-height: 75px; /* ارتفاع دلخواه برای تصویر بنر */ 
    --header-height: 65px; 
    --category-bar-height: 0; 
    --total-fixed-height: calc(var(--banner-height) + var(--header-height) + var(--category-bar-height));

    /* 🔑 متغیر برای عرض نوار اسکرول - توسط JS مقداردهی می‌شود (فقط برای دسکتاپ) */
    --scrollbar-width: 0px; 
}

body {
    /* استفاده از فونت جدید و تنظیم RTL برای نمایش درست */
    font-family: 'IRANSansWeb','tahoma' , 'arial', sans-serif;
    direction: rtl;
    font-weight: normal;
    font-style: normal;
    
    background-color: var(--background-light);
    margin: 0;
    color: var(--text-dark);
    line-height: 1.6;
    font-size: 16px; 
    
    /* ثابت شدن بنر، هدر و نوار دسته‌بندی: فضای خالی برای جلوگیری از پوشانده شدن محتوا */
    padding-top: var(--total-fixed-height);
    
    /* آماده سازی برای ایزوله کردن */
    overflow-x: hidden; 
}

/* 🚀 کلاس کنترل کننده اسکرول و جلوگیری از پرش صفحه (اصلاح برای دسکتاپ) 🚀 */
body.no-scroll {
    overflow: hidden; 
    position: fixed; 
    width: 100%;
    
    /* 🔑 جبران عرض نوار اسکرول حذف شده از سمت چپ (فقط در دسکتاپ فعال است) */
    padding-left: var(--scrollbar-width); 
    
    /* حفظ پدینگ بالای صفحه برای هدر و بنر */
    padding-top: var(--total-fixed-height);
}


/* --- Top Banner Space --- */
.top-banner {
    position: sticky; 
    top: 0;
    z-index: 1001; 
    width: 100%;
    height: var(--banner-height); 
    background-color: #e0e0e0; 
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden; 
}

.top-banner img {
    width: 150%;
    height: 100%;
    object-fit: cover; 
    display: block; 
}


/* --- Header / Navigation --- */
.header {
    background-color: var(--primary-color);
    color: white;
    padding: 0 30px; 
    height: var(--header-height); 
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    position: sticky; 
    top: var(--banner-height); 
    z-index: 1000;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.header h2 { 
    font-size: calc(1.5em + 0.5vw); 
    white-space: nowrap; 
}

.header h2 a {
    color: white;
    text-decoration: none;
    font-weight: bold;
    white-space: nowrap; 
}
.header-controls a {
    color: white;
    text-decoration: none;
    background-color: transparent; 
    border: 1px solid white; 
    border-radius: 5px; 
    padding: 5px 10px; 
    text-align: center;
    display: inline-flex; 
    align-items: center;
    justify-content: center;
    
    margin-right: 10px; 
    font-size: calc(0.9em + 0.15vw); 
    transition: all 0.3s;
    white-space: nowrap; 
    min-width: 120px; 
}
.header-controls a:hover {
    color: var(--primary-color);
    background-color: white; 
}

.cart-count-button {
    background-color: var(--secondary-color);
    color: var(--text-dark);
    border-radius: 5px; 
    padding: 3px 8px; 
    font-size: 0.9em;
    font-weight: bold;
    margin-right: 5px; 
    text-align: center;
    min-width: 15px; 
    display: inline-block;
}

/* --- Category Bar --- */
.category-bar {
    padding: 5px 0; 
    background-color: white; 
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    position: sticky; 
    top: calc(var(--banner-height) + var(--header-height)); 
    z-index: 999;
}
.category-bar .container {
    display: flex;
    justify-content: center; 
    align-items: center;
    max-width: 1200px;
    margin: 0 auto;
}
.category-bar::-webkit-scrollbar {
    display: none; 
}
.category-bar a {
    display: inline-block;
    padding: 5px 12px; 
    margin: 0 3px; 
    text-decoration: none;
    color: var(--primary-color);
    font-weight: bold;
    border-bottom: 2px solid transparent;
    transition: all 0.3s;
    font-size: calc(0.9em + 0.1vw); 
    white-space: nowrap; 
}
.category-bar a i {
     margin-left: 5px; 
}
.category-bar a.active, .category-bar a:hover {
    color: var(--secondary-color);
    border-bottom: 2px solid var(--secondary-color);
}


/* =================================================== */
/* --- ۲. Main Content & Product Grid --- */
/* =================================================== */
.main-content-area {
    flex-grow: 1; 
}
	
.container {
    max-width: 1200px;
    margin: 10px auto;
    padding: 0 20px;
}
.product-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr); 
    gap: 25px;
    margin-top: 30px;
}
.product-card {
    background: white;
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 5px 15px rgba(0, 0, 0, 0.08);
    transition: transform 0.3s, box-shadow 0.3s, background-color 0.3s;
    text-align: center;
    min-height: 250px; 
    display: flex; 
    flex-direction: column; 
}
.product-card.selected { 
    background-color: #FFF5E0; 
    border: 2px solid var(--secondary-color);
}
.product-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}
.product-card img {
    width: 100%;
    height: 90px; 
    object-fit: cover;
    border-bottom: 1px solid #eee;
}
.product-info {
    padding: 15px;
    flex-grow: 1; 
    display: flex;
    flex-direction: column;
    justify-content: space-between; 
}
.product-info h3 {
    font-size: 1em;
    color: var(--text-dark);
    margin: 10px 0 5px 0;
    line-height: 1.2;
    min-height: 2.4em; 
}
.price {
    font-size: 1.1em;
    color: var(--primary-color);
    font-weight: bold;
    margin-bottom: 15px;
}
.add-to-cart-btn {
    background-color: var(--secondary-color);
    color: var(--text-dark);
    border: none;
    padding: 10px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-weight: bold;
    transition: background-color 0.5s;
}
.add-to-cart-btn:hover {
    background-color: #ffeb3b;
}

/* --- استایل جدید برای کنترل مقدار روی کارت محصول --- */
.product-quantity-selector {
    display: flex;
    align-items: center;
    justify-content: center; 
    margin-top: 10px;
    margin-bottom: 5px;
}
.product-qty-btn {
    background-color: var(--secondary-color); 
    color: var(--text-dark);
    border: 1px solid #ccc;
    padding: 5px 10px;
    cursor: pointer;
    font-weight: bold;
    font-size: 1.2em;
    line-height: 1;
    width: 35px;
    text-align: center;
    border-radius: 5px;
    transition: background-color 0.2s;
}
.product-qty-btn:hover {
    background-color: #ffeb3b;
}
.qty-display-product {
    width: 60px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 0;
    padding: 5px 0;
    margin: 0 5px;
    font-size: 1.1em;
    font-weight: bold;
    -moz-appearance: textfield; 
}
.qty-display-product::-webkit-inner-spin-button, 
.qty-display-product::-webkit-outer-spin-button { 
    -webkit-appearance: none; 
    margin: 0; 
}


/* =================================================== */
/* --- ۳. Cart Modal/Sidebar --- */
/* =================================================== */
.cart-sidebar {
    position: fixed;
    top: 0;
    /* ثابت شدن در سمت راست برای سایت RTL */
    right: 0; 
    
    width: 40%; 
    height: 100%;
    background-color: white;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.4); 
    z-index: 2000;
    
    /* مخفی‌سازی کامل با انتقال ۱۰۰٪ به خارج از صفحه (راست) */
    transform: translateX(100%); 
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1); 
    
    display: flex;
    flex-direction: column;
    padding: 20px;
    
    overflow-y: auto; 
    box-sizing: border-box; 
}
.cart-sidebar.open {
    /* نمایش: انتقال به موقعیت صفر */
    transform: translateX(0); 
}

.cart-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 2px solid var(--primary-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
}
.cart-item {
    display: flex;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 1px dashed #eee;
}
.cart-item-img {
    width: 50px;
    height: 50px;
    object-fit: cover;
    border-radius: 5px;
    margin-left: 10px;
}
.cart-item-details {
    flex-grow: 1;
}
.cart-item-details h5 {
    font-size: 1em;
    margin: 0 0 5px 0;
}
.cart-item-price {
    font-weight: bold;
    font-size: 0.9em;
    color: var(--primary-color);
}
.cart-quantity-controls {
    display: flex;
    align-items: center;
    margin-top: 5px;
}
.qty-input {
    width: 50px;
    text-align: center;
    border: 1px solid #ccc;
    border-radius: 3px;
    padding: 2px 0;
    margin: 0 5px;
}
.qty-btn, .remove-item-btn {
    background: #eee;
    border: 1px solid #ccc;
    padding: 3px 8px;
    cursor: pointer;
    border-radius: 3px;
}
.remove-item-btn {
    background-color: #f44336;
    color: white;
    font-size: 0.8em;
    margin-right: 15px;
}
.cart-footer {
    margin-top: auto;
    padding-top: 15px;
    border-top: 2px solid var(--secondary-color);
    
    display: flex;
    flex-direction: column;
    align-items: center; 
}
.cart-footer p {
    display: flex;
    justify-content: space-between;
    font-size: 1.2em;
    font-weight: bold;
    width: 100%; 
    padding-bottom: 10px;
}
.checkout-btn {
    width: auto;
    max-width: 250px; 
    min-width: 200px;
    
    background-color: #4CAF50;
    color: white;
    border: none;
    padding: 15px;
    font-size: 1.1em;
    border-radius: 5px;
    cursor: pointer;
    margin-top: 10px;
    margin-bottom: 10px;
    transition: all 0.2s;
}
.checkout-btn:hover {
    background-color: #45a049;
    transform: scale(1.02);
}

.cart-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6); 
    z-index: 1999;
    
    /* مخفی سازی کامل و جلوگیری از تداخل کلیک */
    visibility: hidden; 
    opacity: 0;
    
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}
.cart-overlay.show {
    /* نمایش لایه */
    visibility: visible;
    opacity: 1;
}

/* --- Media Queries برای ریسپانسیو بودن گرید محصولات و هدر --- */

/* صفحه متوسط (تا 992px) - ۴ ستون */
@media (max-width: 992px) {
    .product-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    body { font-size: 15px; } 
    .cart-sidebar {
        width: 40%;
    }
    .header-controls a {
        min-width: 80px; 
    }
}

/* تبلت‌ها (تا 768px) - ۳ ستون */
@media (max-width: 768px) {
    .product-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 20px;
    }
    .cart-sidebar {
        width: 40%; 
    }
    body { font-size: 14px; }
}

/* موبایل (تا 600px) - ۲ ستون */
@media (max-width: 600px) {
    /* به روز رسانی ارتفاعات برای موبایل */
    :root {
        --banner-height: 80px; 
        --header-height: 45px; 
        --category-bar-height: 0; 
        --total-fixed-height: calc(var(--banner-height) + var(--header-height) + var(--category-bar-height));
    }

    .container {
        padding: 0 10px; 
        margin: 10px auto; 
    }
    
    /* 🚀 اصلاح حیاتی موبایل: تضمین ایزوله شدن کامل در موبایل */
    body.no-scroll {
        /* 🔑 اجبار به ثابت شدن و پر کردن Viewport موبایل */
        position: fixed; 
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%; 
        overflow: hidden; 
        
        /* 🔑 حذف پدینگ چپ و حفظ پدینگ بالا */
        padding-left: 0 !important; 
        padding-top: var(--total-fixed-height) !important; 
    }
    
    /* 🔑 عرض برای موبایل به ۷۰٪ */
    .cart-sidebar {
        width: 70%; 
    }
    
    .checkout-btn {
        padding: 12px;
        font-size: 1em;
        min-width: 180px;
    }

    .product-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 15px;
    }
    .header {
        height: var(--header-height);
        padding: 0 10px; 
        top: var(--banner-height); 
    }
    .header h2 { 
        font-size: 1.2em; 
    }
    .header-controls a {
        font-size: 0.85em; 
        margin-right: 3px; 
        padding: 3px 6px; 
        min-width: 65px; 
    }
    .cart-count-button {
        padding: 2px 4px; 
        font-size: 0.8em;
        margin-right: 3px;
    }
    .category-bar {
        top: calc(var(--banner-height) + var(--header-height)); 
    }
    .category-bar a {
        font-size: 0.85em; 
        padding: 3px 6px; 
    }
}

/* --- Footer --- */
.footer {
    background-color: var(--primary-color); 
    color: white;
    padding: 15px 20px 10px;
    margin-top: 30px;
}
.footer-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 20px;
}
footer {
    background-color: var(--primary-color);
    color: white;
    text-align: center;
    padding: 20px 0;
    margin-top: 50px;
    width: 100%;
}