/**
 * Shop Filters Styles
 * 产品筛选样式
 *
 * @package ToyParadis
 * @since 1.5.0
 */

/* CSS Variables for theme colors */
:root {
    --primary-red: #dc3545; /* Example red for prices/sale */
    --primary-green: #28a745; /* Example green for add to cart */
    --primary-blue: #007bff; /* Existing blue for highlights */
    --text-dark: #333;
    --text-medium: #666;
    --text-light: #999;
    --border-light: #ddd;
    --border-medium: #e0e0e0;
    --background-light: #f8f9fa;
    --background-medium: #f0f0f0;
    --background-dark: #f9f9f9;
}

/* ============================================
   Shop Page Layout
   ============================================ */

.shop-page-with-filters {
    padding: 20px 0;
}

.shop-content-wrapper {
    display: flex;
    gap: 30px;
    align-items: stretch;
}

.shop-filters-sidebar {
    width: 280px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    padding: 20px;
    position: sticky;
    top: 20px;
    /* max-height: calc(100vh - 40px); */
    /* overflow-y: auto; */
}

.shop-main-content {
    flex: 1;
    min-width: 0;
}

/* ============================================
   Filters Sidebar
   ============================================ */

.filters-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--background-medium);
}

.filters-title {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
    color: var(--text-dark);
}

.filters-close-btn {
    display: none;
    background: none;
    border: none;
    cursor: pointer;
    padding: 5px;
    color: var(--text-medium);
    transition: color 0.3s;
}

.filters-close-btn:hover {
    color: var(--text-dark);
}

.filters-content {
    display: flex;
    flex-direction: column;
    gap: 25px;
}

/* Filter Group */
.filter-group {
    border-bottom: 1px solid var(--background-medium);
    padding-bottom: 20px;
}

.filter-group:last-child {
    border-bottom: none;
}

.filter-group-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 15px 0;
    color: var(--text-dark);
    cursor: pointer;
    user-select: none;
}

.filter-toggle {
    background: none;
    border: none;
    width: 24px;
    height: 24px;
    cursor: pointer;
    position: relative;
    padding: 0;
    transition: transform 0.3s;
}

.filter-toggle::before,
.filter-toggle::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 12px;
    height: 2px;
    background: var(--text-medium);
    transform: translate(-50%, -50%);
    transition: transform 0.3s;
}

.filter-toggle::after {
    transform: translate(-50%, -50%) rotate(90deg);
}

.filter-group.expanded .filter-toggle::after {
    transform: translate(-50%, -50%) rotate(0deg);
}

.filter-group-content {
    display: none;
}

.filter-group.expanded .filter-group-content {
    display: block;
}

/* ============================================
   Price Filter
   ============================================ */

.price-range-inputs {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
}

.price-input-wrapper {
    flex: 1;
}

.price-input-wrapper label {
    display: block;
    font-size: 12px;
    color: var(--text-medium);
    margin-bottom: 5px;
}

.price-input {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 14px;
}

.price-separator {
    margin-top: 20px;
    color: var(--text-light);
}

.price-range-slider {
    position: relative;
    height: 6px;
    margin: 20px 0;
    background: var(--border-medium);
    border-radius: 3px;
}

.price-slider {
    position: absolute;
    width: 100%;
    height: 6px;
    background: transparent;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: none;
    z-index: 2;
}

.price-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    background: var(--primary-blue);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.price-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: var(--primary-blue);
    border-radius: 50%;
    cursor: pointer;
    pointer-events: all;
    border: none;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

.price-slider-track {
    position: absolute;
    height: 6px;
    background: var(--primary-blue);
    border-radius: 3px;
    top: 0;
    left: 0;
    right: 0;
}

.price-display {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-dark);
}

/* ============================================
   Checkbox/Radio Filters
   ============================================ */

.filter-checkbox-label,
.filter-radio-label {
    display: flex;
    align-items: center;
    padding: 8px 0;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
}

.filter-checkbox-label:hover,
.filter-radio-label:hover {
    background: var(--background-light);
    border-radius: 4px;
    padding-left: 8px;
    padding-right: 8px;
}

.filter-checkbox,
.filter-radio {
    margin-right: 10px;
    width: 18px;
    height: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.filter-checkbox-text,
.filter-rating-text {
    flex: 1;
    font-size: 14px;
    color: var(--text-dark);
}

.filter-count {
    font-size: 12px;
    color: var(--text-light);
    margin-left: 5px;
}

/* Category Tree */
.filter-category-list {
    list-style: none;
    padding: 0;
    margin: 0;
    margin-left: 20px;
}

.filter-category-item {
    position: relative;
}

.filter-category-item.has-children {
    padding-right: 30px;
}

.filter-toggle-children {
    position: absolute;
    right: 0;
    top: 8px;
    width: 20px;
    height: 20px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: var(--text-medium);
    transition: transform 0.3s;
}

.filter-toggle-children::before {
    content: '+';
    font-size: 16px;
    font-weight: bold;
}

.filter-toggle-children.expanded::before {
    content: '−';
}

.filter-category-item .filter-category-list {
    display: none;
    margin-top: 5px;
}

.filter-toggle-children.expanded + .filter-category-list {
    display: block;
}

/* Rating Stars */
.filter-rating-stars {
    display: inline-flex;
    gap: 2px;
    margin-right: 8px;
}

.filter-rating-stars .star {
    color: #ddd;
    font-size: 14px;
}

.filter-rating-stars .star.filled {
    color: #ffc107; /* Star yellow */
}

.filter-rating-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

/* ============================================
   Filters Footer
   ============================================ */

.filters-footer {
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--background-medium);
    display: flex;
    gap: 10px;
}

.btn-clear-filters,
.btn-apply-filters {
    flex: 1;
    padding: 12px 20px;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-clear-filters {
    background: var(--background-light);
    color: var(--text-medium);
}

.btn-clear-filters:hover {
    background: #e9ecef; /* slightly darker light background */
}

.btn-apply-filters {
    background: var(--primary-blue);
    color: #fff;
}

.btn-apply-filters:hover {
    background: #0056b3; /* darker primary blue */
}

/* ============================================
   Top Filters Bar
   ============================================ */

.shop-filters-top-bar {
    background: #fff;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    padding: 15px 20px;
    margin-bottom: 20px;
}

.filters-top-wrapper {
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.btn-toggle-filters {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 10px 15px;
    background: var(--primary-blue);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-toggle-filters:hover {
    background: #0056b3;
}

.active-filters-count {
    background: rgba(255,255,255,0.3);
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 12px;
}

.quick-filters {
    display: flex;
    gap: 15px;
    flex: 1;
}

.quick-filter-group {
    display: flex;
    align-items: center;
}

.quick-filter-label {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.quick-filter-checkbox {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.quick-filter-text {
    font-size: 14px;
    color: var(--text-dark);
}

.sort-options {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sort-label {
    font-size: 14px;
    color: var(--text-medium);
    white-space: nowrap;
}

.sort-select {
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 14px;
    background: #fff;
    cursor: pointer;
    min-width: 150px;
}

.view-options {
    display: flex;
    gap: 5px;
}

.view-btn {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--background-light);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.3s;
    color: var(--text-medium);
}

.view-btn:hover {
    background: #e9ecef;
    border-color: var(--primary-blue);
    color: var(--primary-blue);
}

.view-btn.active {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: #fff;
}

/* Active Filters Display */
.active-filters-display {
    display: flex;
    flex-wrap: wrap; /* Ensure tags wrap */
    align-items: center; /* Vertically center items */
    gap: 10px;
    width: 100%;
    padding: 15px 0 0;
    border-top: 1px solid var(--background-medium);
    margin-top: 15px;
}

.active-filters-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-medium);
    white-space: normal; /* Ensure the label can wrap if needed */
    flex-shrink: 0; /* Prevent the label from shrinking too much */
    padding-right: 10px; /* Add some space */
}

.active-filters-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: auto; /* Allow the flex item to shrink if necessary */
}

.active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #e3f2fd; /* light blue */
    color: #1976d2; /* darker blue */
    border-radius: 20px;
    font-size: 13px;
    white-space: normal; /* Allow text to wrap */
    word-break: break-word; /* Break long words */
}

.remove-filter {
    background: none;
    border: none;
    color: #1976d2;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.3s;
}

.remove-filter:hover {
    color: var(--primary-red);
}

.clear-all-filters-btn {
    padding: 6px 12px;
    background: var(--background-light);
    border: 1px solid var(--border-light);
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-medium);
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.clear-all-filters-btn:hover {
    background: #e9ecef;
    border-color: var(--text-light);
}

/* ============================================
   Products Area
   ============================================ */

.shop-results-info {
    margin-bottom: 20px;
}

.results-count {
    font-size: 14px;
    color: var(--text-medium);
    margin: 0;
}

.products-wrapper {
    position: relative;
    min-height: 200px;
}

.products-wrapper.loading {
    opacity: 0.6;
    pointer-events: none;
}

.products-loading {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 10;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-blue);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 0 auto 15px;
}

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

.products-loading p {
    color: var(--text-medium);
    font-size: 14px;
}

/* View Modes */
#products-list.view-list {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

#products-list.view-list li.product {
    width: 100%;
    max-width: 100%;
}

/* ============================================
   Filters Overlay (Mobile)
   ============================================ */

.filters-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 9998;
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 1024px) {
    .shop-filters-sidebar {
        width: 250px;
    }
}

@media (max-width: 768px) {
    .shop-content-wrapper {
        flex-direction: column;
    }

    .shop-filters-sidebar {
        width: 100%;
        position: fixed;
        top: 0;
        left: -100%;
        height: 100vh;
        max-height: 100vh;
        z-index: 9999;
        border-radius: 0;
        transition: left 0.3s ease;
        overflow-y: auto;
    }

    .shop-filters-sidebar.active {
        left: 0;
    }

    .filters-close-btn {
        display: block;
    }

    .btn-toggle-filters {
        display: flex;
    }

    .filters-top-wrapper {
        flex-wrap: wrap;
    }

    .quick-filters {
        order: 3;
        width: 100%;
        flex-wrap: wrap;
    }

    .sort-options {
        order: 2;
    }

    .view-options {
        order: 1;
    }

    .filter-group-content {
        display: block;
    }

    .filter-group.expanded .filter-group-content {
        display: block;
    }

    .filter-toggle::after {
        display: none;
    }
}

@media (max-width: 480px) {
    .shop-filters-top-bar {
        padding: 12px 15px;
    }

    .filters-top-wrapper {
        gap: 10px;
    }

    .quick-filters {
        gap: 10px;
    }

    .sort-select {
        min-width: 120px;
        font-size: 13px;
    }

    .active-filters-display {
        flex-direction: column;
        align-items: flex-start;
    }

    .active-filters-tags {
        width: 100%;
    }
}

/* ============================================
   WooCommerce Integration
   ============================================ */

.shop-page-with-filters .woocommerce-products-header {
    margin-bottom: 20px;
}

.shop-page-with-filters .woocommerce-result-count,
.shop-page-with-filters .woocommerce-ordering {
    margin-bottom: 20px;
}

.shop-page-with-filters .products {
    display: grid;
    /* Increased min-width for product cards */
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.shop-page-with-filters .products li.product {
    margin: 0;
    background-color: #fff;
    border: 1px solid var(--border-medium);
    border-radius: 8px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    transition: all 0.3s ease;
}

.shop-page-with-filters .products li.product:hover {
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    transform: translateY(-2px);
}

/* Adjust default WooCommerce product image and title styles */
.shop-page-with-filters .products li.product img {
    max-width: 100%;
    height: auto;
    border-radius: 4px;
    margin-bottom: 10px;
}

.shop-page-with-filters .products li.product h2.woocommerce-loop-product__title {
    font-size: 20px; /* Larger title */
    font-weight: 700; /* Bolder title */
    line-height: 1.3;
    margin: 0 0 12px;
    color: var(--text-dark);
}

.shop-page-with-filters .products li.product .price {
    font-size: 22px; /* Even larger price */
    font-weight: 800; /* Bolder price */
    color: var(--primary-red);
    margin-bottom: 15px;
}

.shop-page-with-filters .products li.product .button.add_to_cart_button {
    background-color: var(--primary-green);
    color: #fff;
    padding: 12px 25px; /* Even larger button */
    border-radius: 6px;
    text-decoration: none;
    display: inline-block;
    transition: background-color 0.3s ease;
}

.shop-page-with-filters .products li.product .button.add_to_cart_button:hover {
    background-color: #008f43; /* darker green */
}

/* Pagination */
.shop-pagination-wrapper {
    margin-top: 40px;
}

.shop-pagination-wrapper .woocommerce-pagination {
    text-align: center;
}

.shop-pagination-wrapper .woocommerce-pagination .page-numbers {
    display: inline-flex;
    gap: 5px;
    list-style: none;
    padding: 0;
    margin: 0;
}

.shop-pagination-wrapper .woocommerce-pagination .page-numbers li {
    margin: 0;
}

.shop-pagination-wrapper .woocommerce-pagination .page-numbers a,
.shop-pagination-wrapper .woocommerce-pagination .page-numbers span {
    display: block;
    padding: 8px 12px;
    border: 1px solid var(--border-light);
    border-radius: 4px;
    text-decoration: none;
    color: var(--text-dark);
    transition: all 0.3s;
}

.shop-pagination-wrapper .woocommerce-pagination .page-numbers a:hover,
.shop-pagination-wrapper .woocommerce-pagination .page-numbers .current {
    background: var(--primary-blue);
    border-color: var(--primary-blue);
    color: #fff;
}
