mkdir -p mbsm-glass-pro && cat << 'EOF' > mbsm-glass-pro/mbsm-glass-pro.php
<?php
/**
 * Plugin Name: MBSM Glass Pro
 * Plugin URI: https://www.mbsm.tn/
 * Description: v2.0.0: Night Vision Edition. Enhanced text visibility in Night Mode, Logic-First Keyword Filtering, and Pro Pagination.
 * Version: 2.0.0
 * Author: MBSM Group
 * Author URI: https://www.mbsm.tn/
 * License: GPL2
 * Text Domain: mbsm-glass-pro
 * 
 * @copyright 2025 MBSM Group
 */

if ( ! defined( 'ABSPATH' ) ) exit;

class MBSM_Glass_Pro_v20 {

    private $opt_id = 'mbsm_gp_v20_settings';

    public function __construct() {
        add_action( 'admin_menu', array( $this, 'mbsm_gp_sidebar_menu' ) );
        add_action( 'admin_init', array( $this, 'mbsm_gp_init_options' ) );
        add_filter( 'plugin_action_links_' . plugin_basename(__FILE__), array( $this, 'mbsm_gp_action_buttons' ) );
        add_shortcode( 'mbsm_glass_display', array( $this, 'mbsm_gp_render_engine' ) );
        add_action( 'wp_enqueue_scripts', array( $this, 'mbsm_gp_inject_styles' ) );
    }

    public function mbsm_gp_action_buttons( $links ) {
        $extra = array(
            '<a href="' . admin_url( 'admin.php?page=mbsm-gp-settings' ) . '">Settings</a>',
            '<a href="' . admin_url( 'admin.php?page=mbsm-gp-dashboard&setup=1' ) . '">Setup Wizard</a>'
        );
        return array_merge( $extra, $links );
    }

    public function mbsm_gp_sidebar_menu() {
        add_menu_page( 'MBSM Glass Pro', 'MBSM Glass Pro', 'manage_options', 'mbsm-gp-dashboard', array( $this, 'mbsm_gp_dash_view' ), 'dashicons-visibility', 25 );
        add_submenu_page( 'mbsm-gp-dashboard', 'Settings', 'Settings', 'manage_options', 'mbsm-gp-settings', array( $this, 'mbsm_gp_sett_view' ) );
    }

    public function mbsm_gp_init_options() {
        register_setting( 'mbsm_gp_v20_group', $this->opt_id );
    }

    public function mbsm_gp_inject_styles() {
        wp_register_style( 'mbsm-gp-v20-style', false );
        wp_enqueue_style( 'mbsm-gp-v20-style' );
        
        $opt = get_option( $this->opt_id );
        $is_night = isset($opt['night_mode']) ? $opt['night_mode'] : 0;
        $d_font   = isset($opt['desk_font']) ? $opt['desk_font'] : '18';
        $m_font   = isset($opt['mob_font']) ? $opt['mob_font'] : '16';

        $bg_main      = $is_night ? '#0f0f0f' : 'transparent';
        $card_bg      = $is_night ? 'rgba(25, 25, 25, 0.95)' : 'rgba(255, 255, 255, 0.85)';
        $title_color  = $is_night ? '#ffffff' : '#1a1a1a';
        $meta_color   = $is_night ? '#00d1ff' : '#666666'; 
        $border_color = $is_night ? 'rgba(255, 255, 255, 0.15)' : 'rgba(0, 0, 0, 0.06)';
        $text_glow    = $is_night ? 'text-shadow: 0 2px 4px rgba(0,0,0,0.8);' : '';

        $css = "
            .mbsm-gp-container { max-width: 1200px; margin: 30px auto; padding: 0 15px; background: $bg_main; }
            .mbsm-gp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 20px; }
            .mbsm-gp-card { 
                background: $card_bg; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
                border: 1px solid $border_color; border-radius: 16px; padding: 25px; transition: 0.4s ease;
                display: flex; flex-direction: column; justify-content: space-between;
                box-shadow: 0 10px 30px rgba(0,0,0,0.05);
            }
            .mbsm-gp-card:hover { transform: translateY(-8px); border-color: #0073aa; box-shadow: 0 15px 45px rgba(0,0,0,0.2); }
            .mbsm-gp-title { color: $title_color; font-weight: 800; font-size: {$d_font}px; margin-bottom: 15px; line-height: 1.4; $text_glow }
            .mbsm-gp-date { font-size: 11px; color: $meta_color; display: block; margin-bottom: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
            .mbsm-gp-footer { display: flex; gap: 10px; border-top: 1px solid $border_color; padding-top: 20px; }
            .mbsm-gp-btn { flex: 1; text-align: center; padding: 11px 5px; border-radius: 9px; text-decoration: none; font-size: 13px; font-weight: 700; transition: 0.3s; }
            .mbsm-gp-btn-1 { border: 2px solid #0073aa; color: #0073aa; }
            .mbsm-gp-btn-1:hover { background: #0073aa; color: #fff; }
            .mbsm-gp-btn-2 { background: #0073aa; color: #fff; box-shadow: 0 4px 10px rgba(0,115,170,0.3); }
            .mbsm-gp-btn-2:hover { background: #005177; }
            .mbsm-gp-pagination { display: flex; justify-content: center; gap: 10px; margin-top: 50px; }
            .mbsm-gp-pagination a, .mbsm-gp-pagination span { padding: 10px 18px; background: #fff; border: 1px solid #ddd; border-radius: 10px; text-decoration: none; color: #333; font-weight: 600; }
            .mbsm-gp-pagination .current { background: #0073aa; color: #fff; border-color: #0073aa; }
            @media (max-width: 768px) { .mbsm-gp-grid { grid-template-columns: 1fr; } .mbsm-gp-title { font-size: {$m_font}px; } }
        ";
        wp_add_inline_style( 'mbsm-gp-v20-style', $css );
    }

    private function mbsm_gp_fetch_filtered_data($paged, $per_page, $keyword = '') {
        $search_args = array( 'post_type' => 'post', 'post_status' => 'publish', 's' => sanitize_text_field($keyword), 'posts_per_page' => -1, 'fields' => 'ids' );
        $initial_ids = get_posts($search_args);
        if ( empty($initial_ids) ) return false;
        $final_ids = array();
        foreach ( $initial_ids as $id ) {
            $zip = get_children(array('post_parent' => $id, 'post_type' => 'attachment', 'post_mime_type' => 'application/zip', 'posts_per_page' => 1));
            if ( !empty($zip) || stripos(get_post_field('post_content', $id), '.zip') !== false ) { $final_ids[] = $id; }
        }
        if ( empty($final_ids) ) return false;
        return new WP_Query(array( 'post_type' => 'post', 'post__in' => $final_ids, 'posts_per_page' => $per_page, 'paged' => $paged, 'orderby' => 'post__in' ));
    }

    public function mbsm_gp_render_engine() {
        $opt = get_option($this->opt_id);
        $per_page = isset($opt['per_page']) ? intval($opt['per_page']) : 8;
        $keyword  = isset($opt['keyword']) ? $opt['keyword'] : '';
        $paged    = max(1, get_query_var('paged'), get_query_var('page'));
        $query = $this->mbsm_gp_fetch_filtered_data($paged, $per_page, $keyword);
        if (!$query || !$query->have_posts()) return '<div class="mbsm-gp-container"><p style="text-align:center; color:#888;">No results found.</p></div>';
        $html = '<div class="mbsm-gp-container"><div class="mbsm-gp-grid">';
        while ($query->have_posts()) {
            $query->the_post();
            $zip_link = '';
            $attachments = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'application/zip', 'posts_per_page' => 1));
            if ( !empty($attachments) ) { $zip_link = wp_get_attachment_url(reset($attachments)->ID); }
            else { preg_match('/https?:\/\/[^"\'>]+\.zip/i', get_the_content(), $matches); if (!empty($matches)) $zip_link = $matches[0]; }
            if ( !empty($zip_link) ) {
                $t = get_the_title();
                $html .= '<div class="mbsm-gp-card">';
                $html .= '<div><span class="mbsm-gp-date">' . get_the_date() . '</span><h3 class="mbsm-gp-title">' . esc_html($t) . '</h3></div>';
                $html .= '<div class="mbsm-gp-footer"><a href="'.get_permalink().'" class="mbsm-gp-btn mbsm-gp-btn-1" target="_blank" rel="noopener">Article</a><a href="'.esc_url($zip_link).'" class="mbsm-gp-btn mbsm-gp-btn-2" target="_blank" rel="noopener">Download</a></div></div>';
            }
        }
        $html .= '</div>';
        if ($query->max_num_pages > 1) { $html .= '<div class="mbsm-gp-pagination">' . paginate_links(array('total' => $query->max_num_pages, 'current' => $paged, 'format' => '?paged=%#%', 'prev_text' => '&laquo;', 'next_text' => '&raquo;')) . '</div>'; }
        $html .= '</div>';
        wp_reset_postdata();
        return $html;
    }

    public function mbsm_gp_dash_view() { echo '<div class="wrap"><h1>MBSM Glass Pro</h1><p>Active Logic: <strong>Keyword Search Filter</strong>.</p></div>'; }
    public function mbsm_gp_sett_view() {
        ?>
        <div class="wrap">
            <h1>MBSM Glass Pro Settings</h1>
            <form method="post" action="options.php">
                <?php settings_fields('mbsm_gp_v20_group'); $opt = get_option($this->opt_id); ?>
                <table class="form-table">
                    <tr><th>Keyword Search</th><td><input type="text" name="mbsm_gp_v20_settings[keyword]" value="<?php echo esc_attr(isset($opt['keyword']) ? $opt['keyword'] : ''); ?>" class="regular-text" /></td></tr>
                    <tr><th>Items Per Page</th><td><input type="number" name="mbsm_gp_v20_settings[per_page]" value="<?php echo esc_attr(isset($opt['per_page']) ? $opt['per_page'] : 8); ?>" /></td></tr>
                    <tr><th>Night Mode</th><td><input type="checkbox" name="mbsm_gp_v20_settings[night_mode]" value="1" <?php checked(1, isset($opt['night_mode']) ? $opt['night_mode'] : 0); ?> /></td></tr>
                    <tr><th>Desk Font Size</th><td><input type="number" name="mbsm_gp_v20_settings[desk_font]" value="<?php echo esc_attr(isset($opt['desk_font']) ? $opt['desk_font'] : 18); ?>" /></td></tr>
                    <tr><th>Mob Font Size</th><td><input type="number" name="mbsm_gp_v20_settings[mob_font]" value="<?php echo esc_attr(isset($opt['mob_font']) ? $opt['mob_font'] : 16); ?>" /></td></tr>
                </table>
                <?php submit_button(); ?>
            </form>
        </div>
        <?php
    }
}
new MBSM_Glass_Pro_v20();
EOF

echo "# MBSM Glass Pro v2.0.0" > mbsm-glass-pro/README.md
echo "Plugin created successfully in /mbsm-glass-pro folder."