/* =========================================================
   رگال محصولات - تابع عمومی
   ========================================================= */

.up-ps-section {
    width: 100%;
    padding: 40px 0;
    background: #ffffff;
    margin: 30px 0;
    border-radius: 18px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.04);
    position: relative;
    overflow: hidden;
}

.up-ps-section::before {
    content: '';
    position: absolute;
    top: -100px;
    left: -100px;
    width: 250px;
    height: 250px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(72, 55, 243, 0.05), transparent 70%);
    pointer-events: none;
}

.up-ps-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 25px;
    position: relative;
    z-index: 2;
}

/* ===== هدر ===== */
.up-ps-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 28px;
    gap: 15px;
    flex-wrap: wrap;
}

.up-ps-header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.up-ps-title {
    font-size: 24px;
    font-weight: 800;
    color: #222 !important;
    margin: 0;
    white-space: nowrap;
}

.up-ps-title-line {
    display: inline-block;
    width: 40px;
    height: 4px;
    background: linear-gradient(90deg, #4837F3, #FF6B35);
    border-radius: 3px;
}

.up-ps-view-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: #f4f6f9;
    color: #4837F3 !important;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border: 1.5px solid #e6e8f5;
}

.up-ps-view-all:hover {
    background: linear-gradient(135deg, #4837F3, #6b5bff);
    color: #fff !important;
    border-color: transparent;
    transform: translateY(-2px);
    box-shadow: 0 8px 20px rgba(72, 55, 243, 0.35);
}

.up-ps-view-all svg { transition: transform 0.3s; }
.up-ps-view-all:hover svg { transform: translateX(-3px); }

/* ===== کاروسل ===== */
.up-ps-carousel-wrap {
    position: relative;
    padding: 0 5px;
}

.up-ps-swiper {
    width: 100%;
    overflow: hidden;
    padding: 10px 5px 15px;
}

.up-ps-swiper .swiper-slide {
    height: auto;
    display: flex;
}

/* ===== کارت محصول ===== */
.up-ps-card {
    position: relative;
    width: 100%;
    background: #ffffff;
    border-radius: 16px;
    padding: 12px;
    display: flex;
    flex-direction: column;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    border: 1.5px solid #f0f0f5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.up-ps-card:hover {
    transform: translateY(-6px);
    border-color: rgba(72, 55, 243, 0.2);
    box-shadow:
        0 15px 35px rgba(72, 55, 243, 0.15),
        0 0 0 1px rgba(72, 55, 243, 0.1);
}

/* برچسب تخفیف */
.up-ps-percent {
    position: absolute;
    top: 10px;
    left: 10px;
    background: linear-gradient(145deg, #FF6B35, #e85a2a);
    color: #fff;
    font-size: 12px;
    font-weight: 800;
    padding: 5px 9px;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(255, 107, 53, 0.4);
    z-index: 3;
    line-height: 1.2;
    animation: psPercentPulse 2s ease-in-out infinite;
}

@keyframes psPercentPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* دکمه علاقه‌مندی */
.up-ps-wishlist {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    background: rgba(255, 255, 255, 0.95);
    border: 1.5px solid #eee;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 3;
    transition: all 0.3s;
    padding: 0;
    color: #999;
    backdrop-filter: blur(5px);
}

.up-ps-wishlist:hover {
    background: #e63946;
    color: #fff;
    border-color: #e63946;
    transform: scale(1.15);
}

.up-ps-wishlist svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
}

/* تصویر */
.up-ps-img-link { display: block; text-decoration: none; }

.up-ps-img {
    width: 100%;
    height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f8f9fc, #f0f2f9);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 12px;
    transition: all 0.4s;
}

.up-ps-card:hover .up-ps-img {
    background: linear-gradient(135deg, #f0f2f9, #ede9ff);
}

.up-ps-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 10px;
}

.up-ps-card:hover .up-ps-img img {
    transform: scale(1.1) translateY(-5px);
}

/* اطلاعات */
.up-ps-info {
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 8px;
}

/* برچسب سبز قسطی */
.up-ps-installment-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 9px 12px;
    background: linear-gradient(135deg, #e8f5e9 0%, #d4edda 100%);
    color: #1b5e20 !important;
    font-size: 12px;
    font-weight: 800;
    border-radius: 10px;
    border: 1.5px solid #a5d6a7;
    line-height: 1.3;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(46, 125, 50, 0.12), inset 0 1px 0 rgba(255, 255, 255, 0.5);
    position: relative;
    overflow: hidden;
    letter-spacing: 0.2px;
    transition: all 0.3s;
}

.up-ps-installment-badge::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.6), transparent);
    animation: psBadgeShine 3s ease-in-out infinite;
}

@keyframes psBadgeShine {
    0%   { left: -100%; }
    50%  { left: 100%; }
    100% { left: 100%; }
}

.up-ps-card:hover .up-ps-installment-badge {
    background: linear-gradient(135deg, #d4edda 0%, #c8e6c9 100%);
    border-color: #81c784;
    box-shadow: 0 4px 12px rgba(46, 125, 50, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.5);
}

.up-ps-installment-badge svg {
    stroke: #1b5e20;
    flex-shrink: 0;
    width: 13px;
    height: 13px;
    background: rgba(46, 125, 50, 0.15);
    border-radius: 50%;
    padding: 1.5px;
    stroke-width: 3;
    position: relative;
    z-index: 2;
}

.up-ps-installment-badge > * { position: relative; z-index: 2; }

/* نام محصول */
.up-ps-name {
    display: -webkit-box;
    font-size: 13.5px;
    font-weight: 600;
    color: #222 !important;
    line-height: 1.6;
    text-decoration: none;
    overflow: hidden;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    min-height: 43px;
    transition: color 0.2s;
}

.up-ps-name:hover { color: #4837F3 !important; }

/* قیمت */
.up-ps-prices {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px dashed #eee;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.up-ps-old-price {
    color: #b0b0bc;
    font-size: 11.5px;
    text-decoration: line-through;
    font-weight: 500;
    order: 1;
}

.up-ps-new-price {
    color: #222;
    font-size: 16px;
    font-weight: 800;
    order: 2;
}

.up-ps-new-price ins,
.up-ps-new-price .woocommerce-Price-amount {
    color: #222 !important;
    text-decoration: none !important;
    font-weight: 800 !important;
}

.up-ps-new-price del { display: none; }

/* دکمه افزودن به سبد */
.up-ps-add-cart {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: linear-gradient(135deg, #4837F3 0%, #6b5bff 50%, #4837F3 100%);
    background-size: 200% 100%;
    color: #fff !important;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 800;
    text-decoration: none;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 6px 18px rgba(72, 55, 243, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
    margin-top: 10px;
    border: none;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    letter-spacing: 0.3px;
}

.up-ps-add-cart::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
    transition: left 0.6s;
}

.up-ps-add-cart:hover::after { left: 100%; }

.up-ps-add-cart:hover {
    background-position: 100% 0;
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(72, 55, 243, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.3);
    color: #fff !important;
}

.up-ps-add-cart:active { transform: translateY(-1px); }

.up-ps-add-cart svg {
    stroke: #fff;
    width: 17px;
    height: 17px;
    flex-shrink: 0;
    position: relative;
    z-index: 2;
    transition: transform 0.3s;
}

.up-ps-add-cart:hover svg { transform: scale(1.15) rotate(-8deg); }

.up-ps-add-cart span {
    position: relative;
    z-index: 2;
    font-weight: 800;
}

.up-ps-add-cart.loading { opacity: 0.75; pointer-events: none; }
.up-ps-add-cart.added {
    background: linear-gradient(135deg, #2e7d32, #4caf50);
    background-size: 100% 100%;
}

/* فلش‌ها */
.up-ps-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 42px;
    height: 42px;
    background: #ffffff;
    border: 1.5px solid #e6e8f5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 10;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    color: #4837F3;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    opacity: 0;
    visibility: hidden;
}

.up-ps-carousel-wrap:hover .up-ps-nav {
    opacity: 1;
    visibility: visible;
}

.up-ps-nav:hover {
    background: linear-gradient(135deg, #4837F3, #6b5bff);
    color: #fff;
    border-color: transparent;
    transform: translateY(-50%) scale(1.1);
    box-shadow: 0 8px 22px rgba(72, 55, 243, 0.4);
}

.up-ps-nav svg { stroke: currentColor; }

.up-ps-prev { right: -15px; }
.up-ps-next { left: -15px; }

/* ===== ریسپانسیو ===== */
@media (max-width: 1200px) {
    .up-ps-img { height: 180px; }
    .up-ps-prev { right: -10px; }
    .up-ps-next { left: -10px; }
}

@media (max-width: 992px) {
    .up-ps-section { padding: 30px 0; margin: 20px 0; border-radius: 14px; }
    .up-ps-container { padding: 0 20px; }
    .up-ps-title { font-size: 20px; }
    .up-ps-view-all { padding: 8px 16px; font-size: 12px; }
    .up-ps-img { height: 160px; }
    .up-ps-name { font-size: 12.5px; min-height: 40px; }
    .up-ps-new-price { font-size: 14px; }
    .up-ps-nav { width: 38px; height: 38px; }
    .up-ps-add-cart { font-size: 11.5px; padding: 10px 10px; }
}

@media (max-width: 768px) {
    .up-ps-section { padding: 22px 0; margin: 15px 0; border-radius: 12px; }
    .up-ps-container { padding: 0 15px; }
    .up-ps-header { margin-bottom: 20px; }
    .up-ps-title { font-size: 16px; }
    .up-ps-title-line { width: 30px; height: 3px; }
    .up-ps-view-all { padding: 7px 13px; font-size: 11px; }
    .up-ps-img { height: 150px; }
    .up-ps-card { padding: 10px; border-radius: 12px; }
    .up-ps-name { font-size: 12px; min-height: 38px; }
    .up-ps-new-price { font-size: 13px; }
    .up-ps-old-price { font-size: 10.5px; }
    .up-ps-installment-badge { font-size: 10px; padding: 7px 8px; }
    .up-ps-percent { font-size: 11px; padding: 4px 7px; }
    .up-ps-wishlist { width: 28px; height: 28px; }
    .up-ps-wishlist svg { width: 14px; height: 14px; }
    .up-ps-nav { display: none; }
    .up-ps-add-cart { font-size: 11px; padding: 9px 8px; }
    .up-ps-add-cart svg { width: 14px; height: 14px; }
}

@media (max-width: 480px) {
    .up-ps-img { height: 130px; }
    .up-ps-title { font-size: 15px; }
    .up-ps-view-all { padding: 6px 10px; }
    .up-ps-view-all span { display: none; }
    .up-ps-view-all svg { width: 16px; height: 16px; }
    .up-ps-installment-badge { font-size: 9.5px; padding: 6px 6px; }
}
/* =========================================
   نمایش Grid وسط‌چین (تعداد کم محصولات)
   ========================================= */
.up-ps-grid-view {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 15px;
    justify-content: center;
    padding: 10px 5px 15px;
}

.up-ps-grid-item {
    display: flex;
    min-width: 0;
}

.up-ps-grid-item .up-ps-card {
    width: 100%;
}

/* ═══ وقتی تعداد محصولات کم است، ستون‌ها را محدود کن تا وسط‌چین شوند ═══ */
.up-ps-grid-view.up-ps-grid-count-5 {
    grid-template-columns: repeat(5, minmax(0, calc((100% - 60px) / 6)));
    justify-content: center;
}

.up-ps-grid-view.up-ps-grid-count-4 {
    grid-template-columns: repeat(4, minmax(0, calc((100% - 60px) / 6)));
    justify-content: center;
}

.up-ps-grid-view.up-ps-grid-count-3 {
    grid-template-columns: repeat(3, minmax(0, calc((100% - 60px) / 6)));
    justify-content: center;
}

.up-ps-grid-view.up-ps-grid-count-2 {
    grid-template-columns: repeat(2, minmax(0, calc((100% - 60px) / 6)));
    justify-content: center;
}

.up-ps-grid-view.up-ps-grid-count-1 {
    grid-template-columns: minmax(0, calc((100% - 60px) / 6));
    justify-content: center;
}

/* ═══ ریسپانسیو ═══ */
@media (max-width: 992px) {
    .up-ps-grid-view.up-ps-grid-count-1,
    .up-ps-grid-view.up-ps-grid-count-2,
    .up-ps-grid-view.up-ps-grid-count-3,
    .up-ps-grid-view.up-ps-grid-count-4,
    .up-ps-grid-view.up-ps-grid-count-5 {
        grid-template-columns: repeat(3, 1fr);
        justify-content: stretch;
    }
}

@media (max-width: 768px) {
    .up-ps-grid-view.up-ps-grid-count-1,
    .up-ps-grid-view.up-ps-grid-count-2,
    .up-ps-grid-view.up-ps-grid-count-3,
    .up-ps-grid-view.up-ps-grid-count-4,
    .up-ps-grid-view.up-ps-grid-count-5 {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
    }
}

@media (max-width: 480px) {
    .up-ps-grid-view.up-ps-grid-count-1,
    .up-ps-grid-view.up-ps-grid-count-2,
    .up-ps-grid-view.up-ps-grid-count-3,
    .up-ps-grid-view.up-ps-grid-count-4,
    .up-ps-grid-view.up-ps-grid-count-5 {
        grid-template-columns: 1fr;
    }
}