/* =========================
   Layout
========================= */
.td-plist {
    padding: 1.25rem 0 3rem;
    position: relative;
}

.td-plist__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

/* تب‌های مرتب‌سازی */
.td-sort-tabs {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
    justify-content: flex-start; /* RTL */
    margin-bottom: 1rem;
}

.td-tab {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    padding: .45rem .9rem;
    border-radius: var(--radius-md);
    background: #fff;
    border: 1px solid #eee;
    color: var(--color-black);
    text-decoration: none;
    transition: var(--transition);
    box-shadow: var(--shadow-sm);
}

.td-tab.is-active {
    background: var(--color-rosegold);
    color: #fff;
    border-color: var(--color-rosegold);
}

.td-tab:hover {
    transform: translateY(-2px);
}

/* مرتب‌سازی ۲×۲ روی موبایل */
@media (max-width: 767.98px) {
    .td-products .td-plist__head {
        display: grid;
        grid-template-columns: 1fr auto; /* چپ: فضا/تب‌ها — راست: دکمه */
        align-items: start;
        row-gap: .75rem;
        margin-bottom: 1rem;
        padding-top: 0; /* اگه قبلاً مقدار داده بودیم، صفرش کن */
    }

    /* دکمه فیلترها: داخل هد، نه fixed */
    .td-filter-toggle.d-md-none {
        position: static;
        justify-self: end;
        z-index: auto;
        box-shadow: var(--shadow-sm);
    }

    .td-sort-tabs {
        grid-column: 1 / -1;
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .6rem;
        margin-bottom: 0;
    }

    .td-tab {
        width: 100%;
        border-radius: var(--radius-md);
        height: 42px;
        justify-content: center;
    }
}

/* دکمه همبرگری فیلترها — در موبایل فیکس بالا-راست */
.td-filter-toggle {
    border: 0;
    background: var(--color-black);
    color: var(--color-cream);
    padding: .5rem .85rem;
    border-radius: var(--radius-md);
    font-weight: 700;
}

.td-plist__grid {
    display: grid;
    grid-template-columns: 1fr 3fr;
    gap: 1.25rem;
}

/* =========================
   Sidebar
========================= */
.td-sidebar {
    position: sticky;
    top: calc(var(--tw-header-height) + 12px);
    align-self: start;
    background: #fff;
    border: 1px solid #eee;
    border-radius: var(--radius-lg);
    padding: .9rem;
    box-shadow: var(--shadow-sm);
    height: max-content;
}

/* هدر داخل سایدبار (دکمه بستن فقط موبایل) */
.td-sidebar__top {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    margin-bottom: .5rem;
}

.td-sidebar__close {
    border: 0;
    background: transparent;
    color: var(--color-black);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    padding: .25rem .5rem;
}

.td-sidebar__close:hover {
    color: var(--color-rosegold);
}

.td-filter-card + .td-filter-card {
    margin-top: .9rem;
}

.td-filter-title {
    font-weight: 700;
    margin-bottom: .5rem;
}

/* =========================
   Sidebar: Categories (td-ppm*)
========================= */
.td-ppm {
    list-style: none;
    padding: 0;
    margin: 0;
    line-height: 1.6;
}

.td-ppm > li {
    margin-bottom: 10px;
}

.td-ppm__row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .5rem;
    padding-inline: 2px;
    cursor: default;
    user-select: none;
}

.td-ppm__link {
    display: block;
    padding: 6px 16px;
    color: var(--color-black);
    text-decoration: none;
    font-size: 14px;
    border-radius: 15px;
    transition: background-color .2s, color .2s, box-shadow .2s;
}

.td-ppm__link:hover {
    background: #f5f1e9;
    color: var(--color-rosegold);
    box-shadow: 0 0 0 3px rgba(183, 110, 121, .15);
    font-weight: 500;
}

/* دکمه تاگل (فلش) + چرخش */
.td-ppm__toggle {
    border: 0;
    background: transparent;
    padding: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    transition: background-color .2s;
}

.td-ppm__toggle:hover {
    background: rgba(0, 0, 0, .05);
}

.td-ppm__toggle i {
    transition: transform .25s ease;
}

.td-ppm__item.open .td-ppm__toggle i {
    transform: rotate(180deg);
}

/* زیرمنو با انیمیشن باز/بسته */
.td-ppm__submenu {
    max-height: 0;
    overflow: hidden;
    padding-right: 20px;
    padding-top: 6px;
    opacity: 0;
    transition: max-height .35s ease, opacity .35s ease;
}

.td-ppm__submenu.open {
    max-height: 1000px;
    opacity: 1;
}

/* آیتم‌های فرزند */
.td-ppm__child {
    display: block;
    padding: 6px 14px;
    border-radius: 12px;
    text-decoration: none;
    color: #2b2b2b;
    transition: background-color .2s, color .2s, padding-right .2s;
}

.td-ppm__child:hover {
    background: #faf6f3;
    color: var(--color-rosegold);
    padding-right: 18px;
}

/* =========================
   Price filter
========================= */
.td-price {
    direction: rtl;
}

.td-price__slider {
    position: relative;
    height: 28px;
    margin: .5rem 0 .4rem;
}

.td-price__slider::before {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 50%;
    height: 6px;
    transform: translateY(-50%);
    background: #eee;
    border-radius: 999px;
}

.td-price__slider input[type="range"] {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 28px;
    margin: 0;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
    pointer-events: none;
}

.td-price__slider input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 3px rgba(183, 110, 121, .25);
    cursor: pointer;
    pointer-events: auto;
    position: relative;
    margin-top: -7px;
}

.td-price__slider input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 2px solid #fff;
    box-shadow: 0 0 0 3px rgba(183, 110, 121, .25);
    cursor: pointer;
    pointer-events: auto;
}

.td-price__slider input[type="range"]::-webkit-slider-runnable-track {
    background: transparent;
    height: 6px;
}

.td-price__slider input[type="range"]::-moz-range-track {
    background: transparent;
    border: none;
}

/* رنگ انگشتک‌ها */
#priceMin::-webkit-slider-thumb {
    background: #7a9e9f;
}

#priceMax::-webkit-slider-thumb {
    background: #b76e79;
}

#priceMin::-moz-range-thumb {
    background: #7a9e9f;
}

#priceMax::-moz-range-thumb {
    background: #b76e79;
}

/* متن مقادیر */
.td-price__label {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font-weight: 600;
    color: #333;
}

.td-price__label strong {
    font-weight: 800;
}

.td-apply {
    position: relative;
    overflow: hidden;
    width: 100%;
    background: var(--color-black);
    color: var(--color-cream);
    border: 0;
    padding: .5rem .75rem;
    border-radius: var(--radius-md);
    margin-top: 8px;
    transition: background-color .2s ease, transform .15s ease, box-shadow .2s ease;
}

.td-apply:hover {
    background: var(--color-rosegold);
    color: #fff;
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 8px 22px rgba(183, 110, 121, .25);
}

.td-apply:active {
    transform: translateY(0);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .12);
}

.td-apply:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(183, 110, 121, .35);
}

.td-apply[disabled] {
    opacity: .6;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.td-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin-bottom: .5rem;
}

/* =========================
   Grid
========================= */
.td-grid {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(3, 1fr);
}

@media (max-width: 1199.98px) {
    .td-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* در موبایل هم ۲ستونه بماند */
@media (max-width: 575.98px) {
    .td-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

.td-grid-skeleton {
    display: grid;
    gap: 1rem;
    grid-template-columns: inherit;
}

.td-skel-card {
    height: 320px;
    border-radius: var(--radius-lg);
    background: linear-gradient(90deg, #eee 25%, #f5f5f5 37%, #eee 63%);
    background-size: 400% 100%;
    animation: tdShimmer 1.2s infinite;
    box-shadow: var(--shadow-sm);
}

@keyframes tdShimmer {
    0% {
        background-position: 100% 0;
    }
    100% {
        background-position: 0 0;
    }
}

.td-loadmore-wrap {
    display: flex;
    justify-content: center;
    margin-top: 1rem;
}

.td-loadmore {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .6rem;
    padding: .65rem 1.1rem;
    border: 0;
    border-radius: var(--radius-lg);
    background: var(--color-rosegold);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: background .25s ease, transform .2s ease;
}

.td-loadmore:hover:not(:disabled) {
    transform: translateY(-2px);
}

.td-loadmore:disabled {
    opacity: .7;
    cursor: not-allowed;
}

.td-loadmore__spinner {
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, .4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tdSpin 0.8s linear infinite;
}

@keyframes tdSpin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 991.98px) {

    /* Overlay mobile drawer */
    .td-plist::after {
        content: "";
        position: fixed;
        inset: 0;
        background: rgba(0, 0, 0, .35);
        backdrop-filter: blur(1px);
        z-index: 1055;
        opacity: 0;
        visibility: hidden;
        transition: opacity .2s ease, visibility .2s ease;
    }

    .td-plist.has-overlay::after {
        opacity: 1;
        visibility: visible;
    }

    /* Filter toggle fixed bottom */
    .td-filter-toggle.d-md-none {
        position: fixed;
        left: 12px;
        right: 12px;
        bottom: calc(env(safe-area-inset-bottom, 0) + 12px);
        top: auto;
        width: auto;
        z-index: 1070;
        padding: .85rem 1rem;
        border-radius: var(--radius-lg);
        box-shadow: 0 10px 24px rgba(0, 0, 0, .15);
        display: flex;
        justify-content: center;
    }

    .td-products {
        padding-bottom: 84px;
    }

    /* Hide button when sidebar open */
    .td-sidebar.open + .td-products .td-filter-toggle {
        display: none !important;
    }

    /* Sidebar drawer */
    .td-sidebar {
        position: fixed;
        right: 0;
        top: 0;
        bottom: 0;
        width: min(88vw, 360px);
        transform: translateX(100%);
        transition: transform .25s ease;
        z-index: 1060;
        height: 100vh;
        overflow: auto;
        border-left: 1px solid #eee;
        box-shadow: -12px 0 30px rgba(0, 0, 0, .08);
    }

    .td-sidebar.open {
        transform: translateX(0);
    }

    /* Product grid */
    .td-plist__grid {
        grid-template-columns: 1fr;
    }

    .td-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    /* Head spacing */
    .td-products .td-plist__head {
        padding-top: 0;
    }
}

/* حالت لودینگ اولیه: اسکلتون‌ها دیده بشن، گرید مخفی */
.td-products.is-loading #tdGrid {
    opacity: 0;
    pointer-events: none;
}

.td-products.is-loading #tdGridSkeleton,
.td-products.is-loading #tdGridSkeletonSlider {
    display: block !important;
}

/* انیمیشن ورود کارت‌ها (stagger) */
.td-grid [data-card] {
    opacity: 0;
    transform: translateY(14px);
    will-change: opacity, transform;
}

.td-grid [data-card].is-in {
    opacity: 1;
    transform: translateY(0);
    transition: opacity .5s ease, transform .5s ease;
}

/* نسخه‌ی کوچک‌ترِ کارت‌ها داخل اسلاید اسکلتون (برای هماهنگی موبایل) */
#tdGridSkeletonSlider .td-skel-card {
    height: 280px;
    border-radius: var(--radius-lg);
    margin: .25rem .15rem;
}

