/* =====================================================================
   PRODUCTS FILTER SYSTEM — برنج پارسی
   ماژول مستقل فیلتر/جستجو/مرتب‌سازی محصولات. این فایل به‌صورت مجزا از
   style.css نگه‌داری می‌شود تا سیستم فیلتر جدا و قابل نگهداری باشد
   و از رنگ‌ها/فونت‌های همان برند (متغیرهای :root در style.css) استفاده می‌کند.
   ===================================================================== */

/* ---------- دکمه‌های موبایل: فیلتر / مرتب‌سازی ---------- */
.products-mobile-actions {
    display: none;
    gap: 0.75rem;
    max-width: 1400px;
    margin: 0 auto 1.25rem;
}

.mobile-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.85rem 1rem;
    min-height: 44px;
    background: white;
    border: 2px solid var(--light-gray);
    border-radius: 14px;
    color: var(--dark);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    position: relative;
    transition: all 0.25s ease;
}

.mobile-action-btn:hover,
.mobile-action-btn:focus-visible {
    border-color: var(--green-primary);
    color: var(--green-dark);
}

.mobile-action-btn:focus-visible {
    outline: 2px solid var(--green-primary);
    outline-offset: 2px;
}

.filter-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 50%;
    background: var(--green-gradient);
    color: white;
    font-size: 0.72rem;
    font-weight: 800;
}

/* ---------- دکمه فیلتر دسکتاپ (کنار مرتب‌سازی) ---------- */
.desktop-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.3rem;
    border: 2px solid var(--light-gray);
    border-radius: 50px;
    background: white;
    color: var(--dark);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    position: relative;
    transition: all 0.25s ease;
}

.desktop-filter-btn:hover,
.desktop-filter-btn.active {
    border-color: var(--green-primary);
    color: var(--green-dark);
}

/* ---------- نوار فیلترهای فعال ---------- */
.active-filters-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.6rem;
    max-width: 1400px;
    margin: -1rem auto 2rem;
    padding: 0.9rem 1.2rem;
    background: var(--off-white);
    border-radius: 16px;
}

.active-filters-bar[hidden] {
    display: none;
}

.active-filters-label {
    font-size: 0.85rem;
    color: #888;
    font-weight: 700;
    white-space: nowrap;
}

.active-filters-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    flex: 1;
}

.active-filter-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    padding: 0.4rem 0.5rem 0.4rem 0.9rem;
    background: white;
    border: 1.5px solid var(--green-light);
    border-radius: 50px;
    color: var(--green-dark);
    font-size: 0.82rem;
    font-weight: 700;
    animation: chipIn 0.2s ease;
}

@keyframes chipIn {
    from { opacity: 0; transform: scale(0.85); }
    to { opacity: 1; transform: scale(1); }
}

.active-filter-chip button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border: none;
    border-radius: 50%;
    background: var(--off-white);
    color: var(--dark);
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    transition: all 0.2s ease;
}

.active-filter-chip button:hover {
    background: var(--error);
    color: white;
}

.clear-all-filters-btn {
    background: none;
    border: none;
    color: var(--error);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    padding: 0.3rem 0.4rem;
}

.clear-all-filters-btn:hover {
    text-decoration: underline;
}

/* ---------- دستیار انتخاب برنج (قانون‌محور، بر پایه داده واقعی) ---------- */
.ai-picker-box {
    max-width: 1400px;
    margin: 0 auto 2rem;
}

.ai-picker-toggle {
    display: inline-flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.75rem 1.4rem;
    border: 1.5px dashed var(--green-primary);
    border-radius: 50px;
    background: rgba(0, 184, 148, 0.06);
    color: var(--green-dark);
    font-family: inherit;
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.25s ease;
}

.ai-picker-toggle:hover {
    background: rgba(0, 184, 148, 0.12);
}

.ai-picker-panel {
    margin-top: 1rem;
    padding: 1.4rem;
    background: white;
    border-radius: 18px;
    box-shadow: 0 8px 25px rgba(0, 184, 148, 0.08);
    border: 1px solid rgba(0, 184, 148, 0.1);
}

.ai-picker-panel[hidden] {
    display: none;
}

.ai-picker-hint {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.9rem;
    line-height: 1.7;
}

.ai-picker-input-row {
    display: flex;
    gap: 0.7rem;
}

.ai-picker-input-row input {
    flex: 1;
    padding: 0.8rem 1.1rem;
    border: 2px solid var(--light-gray);
    border-radius: 50px;
    font-family: inherit;
    font-size: 0.92rem;
    min-width: 0;
}

.ai-picker-input-row input:focus {
    outline: none;
    border-color: var(--green-primary);
}

.ai-picker-input-row button {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.8rem 1.4rem;
    border: none;
    border-radius: 50px;
    background: var(--green-gradient);
    color: white;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: transform 0.2s ease;
}

.ai-picker-input-row button:hover {
    transform: translateY(-2px);
}

.ai-picker-result {
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px dashed var(--light-gray);
}

.ai-picker-result[hidden] {
    display: none;
}

.ai-picker-result-title {
    font-size: 0.85rem;
    color: #888;
    margin-bottom: 0.7rem;
}

.ai-picker-result-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.ai-picker-result-chip {
    padding: 0.4rem 1rem;
    background: var(--off-white);
    border-radius: 50px;
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--dark);
}

.ai-picker-empty {
    font-size: 0.85rem;
    color: #888;
}

.ai-picker-apply-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.7rem 1.3rem;
    border: none;
    border-radius: 50px;
    background: var(--green-gradient);
    color: white;
    font-family: inherit;
    font-weight: 700;
    cursor: pointer;
}

/* ---------- Drawer/Bottom-Sheet مشترک (فیلتر و مرتب‌سازی) ---------- */
.filter-drawer-overlay,
.sort-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(45, 52, 54, 0.55);
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.filter-drawer-overlay.open,
.sort-sheet-overlay.open {
    opacity: 1;
    pointer-events: auto;
}

.filter-drawer,
.sort-sheet {
    position: fixed;
    z-index: 2001;
    background: white;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    /* دسکتاپ: پنل کشویی از راست */
    top: 0;
    bottom: 0;
    right: 0;
    width: 380px;
    max-width: 92vw;
    max-height: none;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0;
}

.sort-sheet {
    width: 320px;
}

.filter-drawer.open,
.sort-sheet.open {
    transform: translateX(0);
}

.filter-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.2rem 1.4rem;
    border-bottom: 1px solid var(--light-gray);
    flex-shrink: 0;
}

.filter-drawer-header h3 {
    font-size: 1.15rem;
    color: var(--dark);
}

.filter-drawer-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 50%;
    background: var(--off-white);
    color: var(--dark);
    font-size: 1rem;
    cursor: pointer;
}

.filter-drawer-close:hover {
    background: var(--error);
    color: white;
}

.filter-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.4rem;
}

.filter-group {
    margin-bottom: 1.8rem;
}

.filter-group-title {
    font-size: 0.95rem;
    color: var(--dark);
    margin-bottom: 0.9rem;
    font-weight: 800;
}

.filter-chip-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
}

.filter-chip-option {
    padding: 0.55rem 1.1rem;
    border: 1.5px solid var(--light-gray);
    border-radius: 50px;
    background: white;
    color: var(--dark);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 40px;
    transition: all 0.2s ease;
}

.filter-chip-option.active {
    background: var(--green-gradient);
    border-color: transparent;
    color: white;
    font-weight: 700;
}

.price-range-inputs {
    display: flex;
    align-items: flex-end;
    gap: 0.7rem;
    margin-bottom: 1rem;
}

.price-input-box {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.price-input-box label {
    font-size: 0.75rem;
    color: #888;
}

.price-input-box input {
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--light-gray);
    border-radius: 10px;
    font-family: inherit;
    font-size: 0.85rem;
    width: 100%;
}

.price-input-box input:focus {
    outline: none;
    border-color: var(--green-primary);
}

.price-range-sep {
    color: #888;
    padding-bottom: 0.7rem;
    font-size: 0.8rem;
}

.price-slider-wrap {
    position: relative;
    height: 36px;
    margin-bottom: 0.6rem;
}

.price-slider-track {
    position: absolute;
    top: 50%;
    right: 0;
    left: 0;
    height: 4px;
    background: var(--light-gray);
    border-radius: 4px;
    transform: translateY(-50%);
}

.price-slider-range {
    position: absolute;
    height: 4px;
    background: var(--green-gradient);
    border-radius: 4px;
}

.price-slider {
    position: absolute;
    top: 0;
    right: 0;
    left: 0;
    width: 100%;
    margin: 0;
    background: none;
    pointer-events: none;
    appearance: none;
    -webkit-appearance: none;
    height: 36px;
}

.price-slider::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    pointer-events: auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--green-primary);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.4);
    cursor: pointer;
    margin-top: 8px;
}

.price-slider::-moz-range-thumb {
    pointer-events: auto;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--green-primary);
    border: 3px solid white;
    box-shadow: 0 2px 8px rgba(0, 184, 148, 0.4);
    cursor: pointer;
}

.price-slider::-webkit-slider-runnable-track,
.price-slider::-moz-range-track {
    background: transparent;
}

.price-presets {
    display: flex;
    gap: 0.5rem;
}

.price-preset-btn {
    flex: 1;
    padding: 0.55rem 0.5rem;
    border: 1.5px solid var(--light-gray);
    border-radius: 10px;
    background: white;
    color: var(--dark);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.price-preset-btn.active {
    background: rgba(0, 184, 148, 0.1);
    border-color: var(--green-primary);
    color: var(--green-dark);
}

.filter-checkbox-row {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    min-height: 44px;
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--dark);
}

.filter-checkbox-row input {
    width: 20px;
    height: 20px;
    accent-color: var(--green-primary);
    cursor: pointer;
}

.filter-drawer-footer {
    display: flex;
    gap: 0.8rem;
    padding: 1.1rem 1.4rem;
    border-top: 1px solid var(--light-gray);
    flex-shrink: 0;
}

.filter-drawer-btn {
    flex: 1;
    padding: 0.85rem 1rem;
    border-radius: 50px;
    font-family: inherit;
    font-weight: 700;
    font-size: 0.92rem;
    cursor: pointer;
    min-height: 46px;
    border: none;
}

.filter-drawer-btn.secondary {
    background: var(--off-white);
    color: var(--dark);
}

.filter-drawer-btn.primary {
    background: var(--green-gradient);
    color: white;
}

.sort-sheet-options {
    padding: 0.6rem;
    overflow-y: auto;
}

.sort-sheet-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.95rem 1.1rem;
    border: none;
    background: none;
    text-align: right;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--dark);
    cursor: pointer;
    border-radius: 12px;
    min-height: 44px;
}

.sort-sheet-option:hover {
    background: var(--off-white);
}

.sort-sheet-option.active {
    color: var(--green-dark);
    font-weight: 800;
    background: rgba(0, 184, 148, 0.08);
}

.sort-sheet-option i {
    color: var(--green-primary);
    opacity: 0;
}

.sort-sheet-option.active i {
    opacity: 1;
}

/* ---------- Skeleton Loading ---------- */
.product-skeleton-card {
    background: white;
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 8px 25px rgba(0, 184, 148, 0.06);
}

.product-skeleton-media {
    aspect-ratio: 4 / 3;
    background: linear-gradient(90deg, var(--off-white) 25%, #eef1f1 37%, var(--off-white) 63%);
    background-size: 400% 100%;
    animation: skeletonShine 1.4s ease infinite;
}

.product-skeleton-lines {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.product-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, var(--off-white) 25%, #eef1f1 37%, var(--off-white) 63%);
    background-size: 400% 100%;
    animation: skeletonShine 1.4s ease infinite;
}

.product-skeleton-line.w-60 { width: 60%; }
.product-skeleton-line.w-40 { width: 40%; }
.product-skeleton-line.w-80 { width: 80%; height: 20px; }

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

/* ---------- خطای دریافت محصولات ---------- */
.products-error-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    color: #888;
}

.products-error-state i {
    font-size: 2.6rem;
    color: var(--error);
    margin-bottom: 1rem;
}

.products-error-state .action-btn-sm {
    display: inline-flex;
    margin-top: 1rem;
}

body.drawer-lock {
    overflow: hidden;
}

/* =========================================================
   موبایل: Drawer/Sheet به‌صورت Bottom Sheet نمایش داده شود
   ========================================================= */
@media (max-width: 768px) {
    .products-mobile-actions {
        display: flex;
    }

    .desktop-filter-btn {
        display: none;
    }

    .filter-drawer,
    .sort-sheet {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        width: 100%;
        max-width: none;
        max-height: 85vh;
        border-radius: 22px 22px 0 0;
        transform: translateY(100%);
    }

    .filter-drawer.open,
    .sort-sheet.open {
        transform: translateY(0);
    }

    .filter-drawer-header::before,
    .sort-sheet::before {
        content: '';
    }

    .filter-drawer::before,
    .sort-sheet::before {
        content: '';
        position: absolute;
        top: 0.6rem;
        right: 50%;
        transform: translateX(50%);
        width: 42px;
        height: 5px;
        border-radius: 4px;
        background: var(--light-gray);
    }

    .active-filters-bar {
        margin: -0.6rem auto 1.5rem;
    }

    .ai-picker-input-row {
        flex-direction: column;
    }

    .ai-picker-input-row button {
        justify-content: center;
    }
}

@media (max-width: 480px) {
    .products-mobile-actions {
        gap: 0.5rem;
    }

    .mobile-action-btn {
        font-size: 0.85rem;
        padding: 0.75rem 0.5rem;
    }

    .price-presets {
        flex-wrap: wrap;
    }

    .price-preset-btn {
        flex: 1 1 30%;
    }
}

/* حالت تیره (در صورت فعال بودن دارک‌تم سایت) */
.dark-theme .mobile-action-btn,
.dark-theme .desktop-filter-btn,
.dark-theme .filter-drawer,
.dark-theme .sort-sheet,
.dark-theme .ai-picker-panel {
    background: #1e2a28;
    color: #eee;
    border-color: #2f403d;
}

.dark-theme .active-filters-bar {
    background: #1e2a28;
}

.dark-theme .active-filter-chip {
    background: #16201e;
}

.dark-theme .filter-chip-option,
.dark-theme .price-preset-btn,
.dark-theme .price-input-box input {
    background: #16201e;
    color: #eee;
    border-color: #2f403d;
}
