/* ============================================================
 * FILTERS & SORT COMPONENTS
 * Version: 1.0.0
 * Description: Advanced filtering and sorting UI
 * ============================================================ */

/* ====================
 * 1. FILTER BAR
 * ==================== */

.filter-bar {
    background: #fff;
    padding: 20px 25px;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    justify-content: space-between;
}

.filter-bar.sticky {
    position: sticky;
    top: 0;
    z-index: 100;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.filter-group {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.filter-label {
    font-size: 14px;
    font-weight: 600;
    color: #333;
    margin-right: 5px;
}

/* ====================
 * 2. SORT DROPDOWN
 * ==================== */

.sort-dropdown {
    position: relative;
    display: inline-block;
}

.sort-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 16px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    color: #333;
    cursor: pointer;
    transition: all 0.3s ease;
}

.sort-button:hover {
    border-color: #667eea;
    color: #667eea;
}

.sort-button.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
}

.sort-button i {
    font-size: 16px;
    transition: transform 0.3s ease;
}

.sort-button.open i {
    transform: rotate(180deg);
}

.sort-menu {
    position: absolute;
    top: calc(100% + 5px);
    left: 0;
    min-width: 200px;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 1000;
}

.sort-menu.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.sort-menu-item {
    padding: 12px 16px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 10px;
}

.sort-menu-item:first-child {
    border-radius: 8px 8px 0 0;
}

.sort-menu-item:last-child {
    border-radius: 0 0 8px 8px;
}

.sort-menu-item:hover {
    background: #f5f7fa;
    color: #667eea;
    padding-left: 20px;
}

.sort-menu-item.active {
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    color: #667eea;
    font-weight: 600;
}

.sort-menu-item i {
    font-size: 16px;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.sort-menu-item.active i {
    opacity: 1;
}

/* ====================
 * 3. VIEW MODE SWITCHER
 * ==================== */

.view-switcher {
    display: flex;
    gap: 5px;
    background: #f5f7fa;
    padding: 4px;
    border-radius: 8px;
}

.view-btn {
    padding: 8px 12px;
    background: transparent;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.view-btn:hover {
    color: #333;
    background: rgba(255, 255, 255, 0.5);
}

.view-btn.active {
    background: #fff;
    color: #667eea;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

/* ====================
 * 4. FILTER CHIPS
 * ==================== */

.filter-chips {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-chip {
    padding: 8px 14px;
    background: #fff;
    border: 2px solid #e0e0e0;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    gap: 6px;
}

.filter-chip:hover {
    border-color: #667eea;
    color: #667eea;
    transform: translateY(-2px);
}

.filter-chip.active {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border-color: transparent;
}

.filter-chip i {
    font-size: 14px;
}

/* ====================
 * 5. SEARCH BOX (In Filter Bar)
 * ==================== */

.filter-search {
    position: relative;
    flex: 1;
    min-width: 250px;
    max-width: 400px;
}

.filter-search input {
    width: 100%;
    padding: 10px 40px 10px 16px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
    outline: none;
    transition: all 0.3s ease;
}

.filter-search input:focus {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.filter-search .search-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: #999;
    pointer-events: none;
}

.filter-search .clear-icon {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 16px;
    color: #999;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.filter-search.has-value .clear-icon {
    opacity: 1;
    visibility: visible;
}

.filter-search.has-value .search-icon {
    opacity: 0;
    visibility: hidden;
}

/* ====================
 * 6. ACTIVE FILTERS DISPLAY
 * ==================== */

.active-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    padding: 15px 0;
    border-bottom: 1px solid #e0e0e0;
    margin-bottom: 20px;
}

.active-filters.empty {
    display: none;
}

.active-filter-label {
    font-size: 13px;
    font-weight: 600;
    color: #666;
    margin-right: 5px;
}

.active-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: linear-gradient(135deg, #667eea15 0%, #764ba215 100%);
    color: #667eea;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
}

.active-filter-tag .remove {
    cursor: pointer;
    font-size: 14px;
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.active-filter-tag .remove:hover {
    opacity: 1;
}

.clear-all-filters {
    padding: 6px 12px;
    background: transparent;
    border: 1px solid #e0e0e0;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    color: #666;
    cursor: pointer;
    transition: all 0.2s ease;
}

.clear-all-filters:hover {
    background: #fff;
    border-color: #f5576c;
    color: #f5576c;
}

/* ====================
 * 7. RESULTS COUNTER
 * ==================== */

.results-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 14px;
    color: #666;
}

.results-count {
    font-weight: 700;
    color: #667eea;
}

/* ====================
 * 8. MOBILE RESPONSIVE
 * ==================== */

@media (max-width: 991px) {
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group {
        justify-content: space-between;
    }
    
    .filter-search {
        max-width: 100%;
        width: 100%;
    }
    
    .view-switcher {
        justify-content: center;
    }
}

@media (max-width: 767px) {
    .filter-bar {
        padding: 15px;
    }
    
    .sort-button,
    .filter-chip {
        font-size: 13px;
        padding: 8px 12px;
    }
    
    .view-btn {
        padding: 6px 10px;
        font-size: 14px;
    }
    
    .sort-menu {
        left: auto;
        right: 0;
    }
}

@media (max-width: 575px) {
    .filter-chips {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }
    
    .filter-chips::-webkit-scrollbar {
        display: none;
    }
    
    .filter-chip {
        white-space: nowrap;
    }
}

/* ====================
 * 9. TOGGLE FILTERS (Mobile)
 * ==================== */

.toggle-filters-btn {
    display: none;
    width: 100%;
    padding: 12px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 15px;
    transition: all 0.3s ease;
}

.toggle-filters-btn i {
    margin-right: 8px;
}

@media (max-width: 767px) {
    .toggle-filters-btn {
        display: block;
    }
    
    .filter-bar {
        max-height: 0;
        overflow: hidden;
        padding: 0 15px;
        opacity: 0;
        transition: all 0.3s ease;
    }
    
    .filter-bar.expanded {
        max-height: 1000px;
        padding: 15px;
        opacity: 1;
        margin-bottom: 15px;
    }
}

/* ====================
 * 10. LOADING STATE
 * ==================== */

.filter-bar.loading {
    pointer-events: none;
    opacity: 0.6;
}

.filter-bar.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 30px;
    height: 30px;
    border: 3px solid #e0e0e0;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: translate(-50%, -50%) rotate(360deg); }
}
