/**
 * استایل‌های اختصاصی ماژول پرفروش‌ترین محصولات هفته (سکشن ۷)
 * فروشگاه آر پی کالا - rpkala.ir
 * ۹ محصول در ۳ ستون ۳ تایی با رتبه‌های ۱ تا ۹
 * پدینگ داخلی باکس اصلی 2rem، بردر ردیوس 1.5rem و بردر 1px rgb(241 245 249)
 *
 * @package RPKala_Toolkit
 * @since   1.0.0
 */

:root {
    --rp-bs-container-width: 1230px;
    --rp-bs-box-radius: 1.5rem;
    --rp-bs-card-radius: 1.15rem;
    --rp-bs-font: 'iransansx', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --rp-bs-primary: rgb(3 44 100 / 1);
    --rp-bs-primary-70: rgb(3 44 100 / 0.7);
    --rp-bs-text-dark: #0f172a;
    --rp-bs-text-muted: rgb(100 116 139 / 1);
    --rp-bs-border-box: rgb(241 245 249);
    --rp-bs-btn-bg-normal: rgb(241 245 249 / 1);
}

.rp-bestsellers-section,
.rp-bestsellers-section * {
    box-sizing: border-box !important;
    font-family: var(--rp-bs-font) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ==========================================================================
   ۱. کانتینر بیرونی سکشن ۷ - فاصله استاندارد ۲.۵ رِم
   ========================================================================== */
.rp-bestsellers-section {
    width: 100%;
    margin-top: 0 !important;
    margin-bottom: 2.5rem !important;
    position: relative;
    z-index: 2;
    direction: rtl !important;
}

.rp-bestsellers-container {
    width: 100%;
    max-width: var(--rp-bs-container-width);
    margin-left: auto;
    margin-right: auto;
    padding-left: 0 !important;
    padding-right: 0 !important;
}

/* ==========================================================================
   ۲. باکس اصلی سکشن پرفروش‌ترین‌ها
   پدینگ 2rem، بردر 1px rgb(241 245 249) و بردر ردیوس 1.5rem
   ========================================================================== */
.rp-bestsellers-box {
    width: 100%;
    background: #ffffff;
    border-radius: 1.5rem !important;
    padding: 2rem !important; /* پدینگ ۲ رِم طبق دستور کاربر */
    border: 1px solid rgb(241 245 249) !important; /* یک پیکسل بردر با رنگ درخواستی */
    box-shadow: 0 4px 20px -2px rgba(0, 0, 0, 0.03), 0 2px 6px -1px rgba(0, 0, 0, 0.02);
}

/* ==========================================================================
   ۳. هدر سکشن: عنوان راست و لینک مشاهده همه در چپ
   سایز عنوان اصلی 1.5rem با رنگ #0f172a و زیرعنوان 0.875rem
   ========================================================================== */
.rp-bestsellers-header {
    display: flex;
    align-items: center !important; /* وسط‌چین عمودی دکمه با عنوان‌ها */
    justify-content: space-between;
    padding-bottom: 1.25rem !important; /* فاصله تا خط جداکننده */
    margin-bottom: 1.5rem !important; /* فاصله خط جداکننده تا کارت‌ها */
    border-bottom: 1px solid rgb(241 245 249) !important; /* خط جدا کننده طبق دستور کاربر */
}

.rp-bestsellers-title-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: right;
}

.rp-bestsellers-title {
    font-size: 1.5rem !important; /* سایز 1.5rem طبق دستور کاربر */
    font-weight: 900 !important;
    color: #0f172a !important; /* رنگ #0f172a */
    line-height: 1.3 !important;
    margin: 0 0 0.4rem 0 !important;
    letter-spacing: -0.02em;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.rp-bestsellers-title-bar {
    display: inline-block;
    width: 4.5px;
    height: 1.4rem;
    background: var(--rp-bs-primary);
    border-radius: 4px;
    flex-shrink: 0;
}

.rp-bestsellers-desc {
    font-size: 0.875rem !important; /* سایز 0.875rem طبق دستور کاربر */
    font-weight: 500 !important;
    color: var(--rp-bs-text-muted) !important;
    line-height: 1.6 !important;
    margin: 0 !important;
}

/* دکمه مشاهده همه محصولات در سمت چپ - وسط‌چین عمودی و رنگ هاور پالت */
.rp-bestsellers-view-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: rgb(3 44 100 / 0.85) !important;
    font-size: 0.875rem !important;
    font-weight: 700 !important;
    text-decoration: none !important;
    transition: all 0.2s ease;
    align-self: center !important;
    padding: 0 !important;
}

.rp-bestsellers-view-all svg {
    transition: transform 0.2s ease, stroke 0.2s ease;
    flex-shrink: 0;
    stroke: currentColor;
}

.rp-bestsellers-view-all:hover {
    color: rgb(3 44 100 / 1) !important; /* رنگ سازمانی پالت سرمه‌ای در هاور */
}

.rp-bestsellers-view-all:hover svg {
    transform: translateX(-4px);
    stroke: rgb(3 44 100 / 1) !important;
}

/* ==========================================================================
   ۴. شبکه گرید محصولات پرفروش (۳ ستون هماهنگ با ۳ کارت در هر ستون)
   فاصله بین کارت‌ها ۱ رِم (gap: 1rem)
   ========================================================================== */
.rp-bestsellers-grid {
    display: flex;
    flex-direction: row;
    align-items: stretch;
    justify-content: space-between;
    gap: 1rem !important; /* فاصله بین ستون‌ها ۱ رِم */
    width: 100%;
}

.rp-bestsellers-column {
    flex: 1 1 0;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem !important; /* فاصله بین ردیف کارت‌ها ۱ رِم */
}

/* ==========================================================================
   ۵. کارت مینی افقی هر محصول پرفروش
   ========================================================================== */
.rp-bestseller-card {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: var(--rp-bs-card-radius);
    padding: 0.85rem 1rem;
    position: relative;
    transition: border-color 0.25s ease,
                box-shadow 0.25s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
    display: flex;
    align-items: center;
    gap: 0.85rem;
}

/* لایه لینک سراسری روی کل کارت */
.rp-bestseller-overlay-link {
    position: absolute;
    inset: 0;
    z-index: 1;
    border-radius: inherit;
    text-decoration: none !important;
}

/* رقم رتبه در سمت راست کارت:
   سایز 1.25rem، وزن ۹۰۰، رنگ عادی rgb(3 44 100 / 0.7) و هاور rgb(3 44 100 / 1) */
.rp-bestseller-rank {
    font-size: 1.25rem !important; /* سایز 1.25rem طبق دستور */
    font-weight: 900 !important; /* فونت weight 900 */
    color: rgb(3 44 100 / 0.7) !important; /* رنگ عادی */
    line-height: 1;
    min-width: 20px;
    text-align: center;
    transition: color 0.25s ease;
    flex-shrink: 0;
    user-select: none;
    position: relative;
    z-index: 2;
}

/* باکس تصویر محصول: عکس باید کل باکس مربعی را پر کند */
.rp-bestseller-img-wrap {
    width: 76px;
    height: 76px;
    min-width: 76px;
    border-radius: 0.85rem;
    background: #f8fafc;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 !important; /* بدون پدینگ تا عکس تمام باکس را بپوشاند */
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    pointer-events: none;
}

.rp-bestseller-img {
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    object-fit: cover !important; /* پر کردن کامل کادر مربعی */
    display: block;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

/* اطلاعات متنی کارت (عنوان بالا و ردیف قیمت+سبد خرید در پایین) */
.rp-bestseller-info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-start;
    flex: 1;
    min-width: 0;
    gap: 0.5rem;
    min-height: 76px;
    position: relative;
    z-index: 2;
}

.rp-bestseller-title-wrap {
    width: 100%;
}

/* عنوان محصول: سایز 0.75rem، فونت weight 700، لاین هیت 1.375، محدود به ۲ خط، رنگ عادی #0f172a و هاور rgb(3 44 100 / 1) */
.rp-bestseller-title {
    font-size: 0.75rem !important; /* سایز 0.75rem */
    font-weight: 700 !important; /* وزن ۷۰۰ */
    line-height: 1.375 !important; /* لاین هیت 1.375 */
    color: #0f172a !important; /* رنگ عادی #0f172a */
    margin: 0 !important;
    text-align: right;
    display: -webkit-box !important;
    -webkit-line-clamp: 2 !important; /* حداکثر ۲ خط */
    -webkit-box-orient: vertical !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    word-break: break-word;
    max-height: calc(0.75rem * 1.375 * 2) !important;
    transition: color 0.2s ease;
}

/* ردیف پایین کارت شامل قیمت و دکمه سبد خرید */
.rp-bestseller-bottom-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

/* بخش قیمت در سمت راست ردیف پایین:
   عدد قیمت سایز 0.875rem، وزن ۹۰۰، رنگ rgb(3 44 100 / 1)
   واحد تومان رنگ rgb(100 116 139 / 1)، وزن ۵۰۰ و سایز 10px */
.rp-bestseller-price-row {
    display: flex;
    align-items: baseline;
    gap: 4px;
    line-height: 1.2;
}

.rp-bestseller-amount {
    font-size: 0.875rem !important; /* سایز 0.875rem */
    font-weight: 900 !important; /* وزن ۹۰۰ */
    color: rgb(3 44 100 / 1) !important; /* رنگ rgb(3 44 100 / 1) */
    letter-spacing: -0.02em;
}

.rp-bestseller-unit {
    font-size: 10px !important; /* سایز 10px */
    font-weight: 500 !important; /* وزن ۵۰۰ */
    color: rgb(100 116 139 / 1) !important; /* رنگ rgb(100 116 139 / 1) */
}

/* ==========================================================================
   ۶. دکمه سبد خرید در پایین سمت چپ
   فقط آیکون سبد، بدون به‌علاوه
   بک‌گراند عادی rgb(241 245 249 / 1) و هاور rgb(3 44 100 / 1)
   ========================================================================== */
.rp-bestseller-cart-btn {
    all: unset !important;
    box-sizing: border-box !important;
    width: 34px !important;
    height: 34px !important;
    border-radius: 0.65rem !important;
    background: rgb(241 245 249 / 1) !important; /* بکگراند عادی rgb(241 245 249 / 1) */
    color: rgb(100 116 139 / 1) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    cursor: pointer !important;
    flex-shrink: 0 !important;
    position: relative !important;
    z-index: 3 !important;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

.rp-bestseller-cart-icon {
    width: 17px;
    height: 17px;
    stroke: rgb(100 116 139 / 1);
    fill: none;
    transition: transform 0.25s ease, stroke 0.25s ease;
}

/* حالت افزودن ایجکس در حال چرخش / لودینگ */
.rp-bestseller-cart-btn.loading {
    opacity: 0.7;
    pointer-events: none;
}

.rp-bestseller-cart-btn.loading .rp-bestseller-cart-icon {
    animation: rp-bs-spin 0.8s linear infinite;
}

@keyframes rp-bs-spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ==========================================================================
   ۷. حالت هاور کارت طبق دستور کاربر:
      - باکس شدو می‌گیرد
      - رنگ بردر تغییر می‌کند
      - عکس محصول بزرگتر می‌شود (zoom)
      - عدد کنار عکس به رنگ rgb(3 44 100 / 1) پر رنگ می‌شود
      - عنوان محصول به رنگ rgb(3 44 100 / 1) درمی‌آید
      - دکمه سبد خرید بک‌گراندش rgb(3 44 100 / 1) و آیکونش سفید می‌شود
   ========================================================================== */
.rp-bestseller-card:hover {
    border-color: rgba(3, 44, 100, 0.25) !important;
    box-shadow: 0 10px 24px -4px rgba(3, 44, 100, 0.1), 0 4px 10px -2px rgba(3, 44, 100, 0.05) !important;
    transform: translateY(-2px);
}

.rp-bestseller-card:hover .rp-bestseller-rank {
    color: rgb(3 44 100 / 1) !important; /* پر رنگ شدن عدد کنار عکس در هاور */
    font-weight: 900 !important;
}

.rp-bestseller-card:hover .rp-bestseller-img {
    transform: scale(1.08) !important;
}

.rp-bestseller-card:hover .rp-bestseller-title,
.rp-bestseller-title:hover {
    color: rgb(3 44 100 / 1) !important; /* رنگ هاور عنوان */
}

.rp-bestseller-card:hover .rp-bestseller-cart-btn {
    background: rgb(3 44 100 / 1) !important; /* بکگراند هاور دکمه سبد خرید */
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(3, 44, 100, 0.25) !important;
}

.rp-bestseller-card:hover .rp-bestseller-cart-btn .rp-bestseller-cart-icon {
    stroke: #ffffff !important;
    transform: scale(1.06);
}

/* هاور مستقیم روی خود دکمه سبد خرید */
.rp-bestseller-cart-btn:hover {
    transform: scale(1.08) !important;
    background: rgb(3 44 100 / 1) !important;
}

.rp-bestseller-cart-btn:hover .rp-bestseller-cart-icon {
    stroke: #ffffff !important;
}

/* ==========================================================================
   ۸. ریسپانسیو و بهینه‌سازی تبلت و موبایل (عرض حداکثر ۷۶۸ پیکسل طبق طرح)
   - چیدمان افقی و اسکرول نرم ستون‌ها (هر ستون شامل ۳ کارت عمودی)
   - ستون اول کاملاً در کادر و لبه ستون بعدی با ارقام ۴، ۵، ۶ از چپ مشخص
   - فاصله استاندارد ۱ رِم از چپ و راست صفحه
   - حفظ ۱۰۰٪ استایل، رنگ‌ها، متن‌ها و جزئیات کارت‌های دسکتاپ
   ========================================================================== */
@media (max-width: 1024px) {
    .rp-bestsellers-box {
        padding: 1.5rem !important;
    }
    
    .rp-bestsellers-grid {
        gap: 0.75rem !important;
    }
}

@media (max-width: 768px) {
    .rp-bestsellers-section {
        margin-top: 0 !important;
        margin-bottom: 2rem !important;
        width: 100% !important;
    }

    .rp-bestsellers-container {
        padding-left: 1rem !important;  /* فاصله دقیق ۱ رِم از لبه چپ */
        padding-right: 1rem !important; /* فاصله دقیق ۱ رِم از لبه راست */
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    /* حذف کادر سفید بیرونی در موبایل تا کارت‌های محصول شبیه اپلیکیشن روی بک‌گراند بنشینند */
    .rp-bestsellers-box {
        background: transparent !important;
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        border-radius: 0 !important;
        width: 100% !important;
    }

    /* هدر تک‌خطی شیک و هماهنگ: عنوان و نوار عمودی در راست، لینک مشاهده همه در چپ */
    .rp-bestsellers-header {
        display: flex !important;
        flex-direction: row !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding-bottom: 0 !important;
        margin-bottom: 0.85rem !important;
        border-bottom: none !important;
        gap: 0.5rem !important;
        width: 100% !important;
    }

    .rp-bestsellers-title-group {
        display: flex !important;
        flex-direction: column !important;
        align-items: flex-start !important;
        text-align: right !important;
        flex: 1 !important;
        min-width: 0 !important;
        gap: 0.15rem !important;
    }

    .rp-bestsellers-title {
        font-size: 1.05rem !important;
        font-weight: 900 !important;
        color: #0f172a !important;
        line-height: 1.3 !important;
        margin: 0 !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.45rem !important;
        white-space: nowrap !important;
        letter-spacing: -0.02em !important;
    }

    .rp-bestsellers-title-bar {
        display: inline-block !important;
        width: 4px !important;
        height: 1.15rem !important;
        background: var(--rp-bs-primary) !important;
        border-radius: 4px !important;
        flex-shrink: 0 !important;
    }

    .rp-bestsellers-desc {
        font-size: 0.72rem !important;
        font-weight: 500 !important;
        color: #64748b !important;
        line-height: 1.4 !important;
        margin: 0 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
    }

    .rp-bestsellers-view-all {
        font-size: 0.78rem !important;
        font-weight: 800 !important;
        color: var(--rp-bs-primary) !important;
        display: inline-flex !important;
        align-items: center !important;
        gap: 4px !important;
        flex-shrink: 0 !important;
        white-space: nowrap !important;
        text-decoration: none !important;
        align-self: center !important;
    }

    .rp-bestsellers-view-all svg {
        width: 15px !important;
        height: 15px !important;
        stroke-width: 2.5 !important;
        stroke: var(--rp-bs-primary) !important;
    }

    /* نوار اسکرول افقی تراز در خط محتوای موبایل */
    .rp-bestsellers-grid {
        display: flex !important;
        flex-direction: row !important;
        align-items: stretch !important;
        justify-content: flex-start !important;
        overflow-x: auto !important;
        overflow-y: hidden !important;
        -webkit-overflow-scrolling: touch !important;
        touch-action: pan-x pan-y !important;
        scrollbar-width: none !important;
        -ms-overflow-style: none !important;
        scroll-snap-type: x mandatory !important;
        gap: 0.75rem !important;
        margin-right: 0 !important;
        margin-left: 0 !important;
        padding-right: 0 !important;
        padding-left: 0 !important;
        padding-top: 0.25rem !important;
        padding-bottom: 0.75rem !important;
        width: 100% !important;
        box-sizing: border-box !important;
    }

    .rp-bestsellers-grid::-webkit-scrollbar {
        display: none !important;
        width: 0 !important;
        height: 0 !important;
    }

    /* هر ستون شامل ۳ کارت عمودی، هم‌تراز با لبه محتوا */
    .rp-bestsellers-column {
        flex: 0 0 calc(100% - 2.5rem) !important;
        width: calc(100% - 2.5rem) !important;
        min-width: calc(100% - 2.5rem) !important;
        max-width: calc(100% - 2.5rem) !important;
        scroll-snap-align: start !important;
        display: flex !important;
        flex-direction: column !important;
        gap: 0.65rem !important;
        box-sizing: border-box !important;
    }

    /* کارت مینی افقی با پس‌زمینه سفید، گوشه‌های گرد ۱.۲۵ رِم و بوردر نازک */
    .rp-bestseller-card {
        position: relative !important;
        background: #ffffff !important;
        border: 1px solid #f1f5f9 !important;
        border-radius: 1.25rem !important; /* ۲۰ پیکسل گوشه‌های گرد */
        padding: 0.75rem 0.85rem !important;
        display: flex !important;
        align-items: center !important;
        gap: 0.65rem !important;
        box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.03) !important;
        transition: transform 0.2s ease, box-shadow 0.2s ease !important;
        box-sizing: border-box !important;
        width: 100% !important;
    }

    .rp-bestseller-card:active {
        transform: scale(0.99) !important;
    }

    /* رقم رتبه در سمت راست با رنگ ملایم slate طبق نمونه ارسالی */
    .rp-bestseller-rank {
        font-size: 1.35rem !important;
        font-weight: 900 !important;
        color: #94a3b8 !important;
        min-width: 22px !important;
        text-align: center !important;
        flex-shrink: 0 !important;
        line-height: 1 !important;
    }

    /* باکس عکس محصول */
    .rp-bestseller-img-wrap {
        width: 64px !important;
        height: 64px !important;
        min-width: 64px !important;
        border-radius: 0.85rem !important;
        background: #f8fafc !important;
        overflow: hidden !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0 !important;
        flex-shrink: 0 !important;
    }

    .rp-bestseller-img {
        width: 100% !important;
        height: 100% !important;
        object-fit: contain !important;
    }

    /* اطلاعات متنی کارت (عنوان در بالا، قیمت در پایین) */
    .rp-bestseller-info {
        display: flex !important;
        flex-direction: column !important;
        justify-content: center !important;
        align-items: flex-start !important;
        min-height: unset !important;
        height: auto !important;
        gap: 0.35rem !important;
        padding-left: 2.75rem !important; /* ایجاد فضای کافی برای قرارگیری دکمه سبد خرید در چپ */
        flex: 1 !important;
        min-width: 0 !important;
        position: relative !important;
        z-index: 2 !important;
    }

    .rp-bestseller-title-wrap {
        width: 100% !important;
        overflow: hidden !important;
    }

    /* عنوان محصول به صورت تک‌خطی شیک با ellipsis */
    .rp-bestseller-title {
        font-size: 0.78rem !important;
        font-weight: 800 !important;
        color: #0f172a !important;
        line-height: 1.4 !important;
        white-space: nowrap !important;
        overflow: hidden !important;
        text-overflow: ellipsis !important;
        max-width: 100% !important;
        margin: 0 !important;
        display: block !important;
    }

    .rp-bestseller-bottom-row {
        display: block !important;
        width: 100% !important;
    }

    /* قیمت و تومان */
    .rp-bestseller-price-row {
        display: flex !important;
        align-items: baseline !important;
        gap: 4px !important;
        line-height: 1.2 !important;
    }

    .rp-bestseller-amount {
        font-size: 0.85rem !important;
        font-weight: 900 !important;
        color: #0f172a !important;
    }

    .rp-bestseller-unit {
        font-size: 0.65rem !important;
        font-weight: 600 !important;
        color: #64748b !important;
    }

    /* دکمه سبد خرید ثابت در سمت چپ، وسط‌چین عمودی در کارت با آیکون دارای به‌علاوه */
    .rp-bestseller-cart-btn {
        position: absolute !important;
        left: 0.85rem !important;
        top: 50% !important;
        transform: translateY(-50%) !important;
        width: 36px !important;
        height: 36px !important;
        border-radius: 0.75rem !important;
        background: #f1f5f9 !important;
        color: #334155 !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
        z-index: 3 !important;
        margin: 0 !important;
    }

    .rp-bestseller-cart-icon {
        width: 17px !important;
        height: 17px !important;
        stroke: #334155 !important;
    }
}

@media (max-width: 360px) {
    .rp-bestseller-img-wrap {
        width: 56px !important;
        height: 56px !important;
        min-width: 56px !important;
    }
    .rp-bestseller-cart-btn {
        width: 32px !important;
        height: 32px !important;
        left: 0.65rem !important;
    }
    .rp-bestseller-info {
        padding-left: 2.35rem !important;
    }
}
