<?php
// phpcs:disable WordPress.DB.DirectDatabaseQuery,WordPress.NamingConventions.PrefixAllGlobals -- Shortcode template uses plugin-owned data and local rendering variables.

if (! defined('ABSPATH')) exit; // Exit if accessed directly

// Include the reusable close button component
require_once plugin_dir_path(__FILE__) . 'components/close-button.php';

$instant_popup_builder_active_license = get_option('subscription_license_active');
$instant_popup_builder_ipd_active_plugin = get_option('instant_popup_subscription_activated');
if($instant_popup_builder_active_license != 'yes' || $instant_popup_builder_ipd_active_plugin == 'no'){

    global $wpdb;
    $instant_popup_builder_id = get_transient('instant_popup_builder_popup_id');
    $instant_popup_builder_is_active = get_transient('instant_popup_builder_popup_class' . $instant_popup_builder_id);
    $instant_popup_builder_delay = json_decode(get_transient('instant_popup_builder_delay'));
    $instant_popup_builder_class_hover = get_transient('instant_popup_builder_class_hover' . $instant_popup_builder_id);
    $instant_popup_builder_class_click = get_transient('instant_popup_builder_class_click' . $instant_popup_builder_id);
    $instant_popup_builder_trigger_option = get_transient('instant_popup_builder_trigger' . $instant_popup_builder_id);
    $instant_popup_builder_exit_sensivity = get_transient('exit_sensivity' . $instant_popup_builder_id);
    $instant_popup_builder_exit_intent_options = json_decode(get_transient('exit_intent_options' . $instant_popup_builder_id), true);
    if (!is_array($instant_popup_builder_exit_intent_options)) {
        $instant_popup_builder_exit_intent_options = array(
            'mouse_leave' => '1', // Default enabled
            'lost_focus' => '0',
            'back_button' => '0',
            'link_click' => '0',
        );
    }
    $instant_popup_builder_scroll_type = get_transient('instant_popup_builder_scroll_type'. $instant_popup_builder_id);
    $instant_popup_builder_scroll_distance = get_transient('instant_popup_builder_scroll_distance'. $instant_popup_builder_id);
    $instant_popup_builder_scroll_trigger_settings = get_transient('instant_popup_builder_scroll_trigger'. $instant_popup_builder_id);
    $instant_popup_builder_woo_trigger = get_transient('instant_popup_builder_woo_trigger'. $instant_popup_builder_id);
    $instant_popup_builder_woo_condition = get_transient('instant_popup_builder_woo_condition'. $instant_popup_builder_id);
    $instant_popup_builder_woo_trigger_settings = get_transient('instant_popup_builder_woocommerce_trigger'. $instant_popup_builder_id);
    $instant_popup_builder_target_device = get_transient('instant_popup_builder_target_device' . $instant_popup_builder_id);
    $instant_popup_builder_row = $wpdb->get_results($wpdb->prepare("SELECT * FROM  {$wpdb->prefix}instant_popup_builder where id=%d", $instant_popup_builder_id));
    // Validate array access before using
    if (empty($instant_popup_builder_row) || !isset($instant_popup_builder_row[0])) {
        return; // Exit early if no popup data found
    }
    $instant_popup_builder_image_url = json_decode($instant_popup_builder_row[0]->content);
    $instant_popup_builder_title = isset($instant_popup_builder_row[0]->title) ? $instant_popup_builder_row[0]->title : '';
    $ipb_closing_parsed = function_exists( 'ipb_parse_closing_settings_from_json' )
        ? ipb_parse_closing_settings_from_json( isset( $instant_popup_builder_row[0]->closing ) ? (string) $instant_popup_builder_row[0]->closing : '' )
        : array(
            'position' => 'top-right',
            'escape'   => 'no',
            'outside'  => 'no',
            'hide'     => 'no',
        );
    $instant_popup_builder_close_position = $ipb_closing_parsed['position'];
    $instant_popup_builder_close_escape     = $ipb_closing_parsed['escape'];
    $instant_popup_builder_close_outside    = $ipb_closing_parsed['outside'];
    $instant_popup_builder_hide_close       = $ipb_closing_parsed['hide'];
    $instant_popup_builder_hover_close = get_transient('instant_popup_builder_hover_close');
    $instant_popup_builder_limit_count = get_transient('instant_popup_builder_limit_count');
    $instant_popup_builder_limit_expiry = get_transient('instant_popup_builder_limit_expiry');
    $instant_popup_builder_popup_position = get_transient('instant_popup_builder_popup_position');
    $instant_popup_builder_back_color_toggle = get_transient('back_color_toggle');
    $instant_popup_builder_popup_theme = get_transient('popup_theme');
    $instant_popup_builder_background_color = get_transient('background_color');
    $instant_popup_builder_back_image_toggle = get_transient('back_image_toggle');
    $instant_popup_builder_background_image = get_transient('background_image');
    $instant_popup_builder_back_image_pos_toggle = get_transient('back_image_pos_toggle');
    $instant_popup_builder_back_img_position = get_transient('back_img_position');
    $instant_popup_builder_back_image_size = get_transient('back_image_size');
    $instant_popup_builder_backcolor_opacity = get_transient('backcolor_opacity');
    $instant_popup_builder_backimage_opacity = get_transient('backimage_opacity');
    $instant_popup_builder_design_width = get_transient('design_width' . $instant_popup_builder_id);
    $instant_popup_builder_design_height = get_transient('design_height' . $instant_popup_builder_id);
    $instant_popup_builder_design_percentage = get_transient('design_percentage' . $instant_popup_builder_id);
    $instant_popup_builder_design_percentage_toggle = get_transient('design_percentage_toggle' . $instant_popup_builder_id);
    $instant_popup_builder_animate_type = get_transient('animate_type');
    $instant_popup_builder_animate_speed = get_transient('animate_speed');
    $instant_popup_builder_animate_origin = get_transient('animate_origin');
    $instant_popup_builder_action = get_transient('action');
    $instant_popup_builder_action_type = get_transient('action_type') ?: 'redirect';
    $instant_popup_builder_action_popup_id = get_transient('action_popup_id') ?: '';
    $instant_popup_builder_url = get_transient('url');
    $instant_popup_builder_redirect_delay_seconds = get_transient('redirect_delay_seconds') !== false ? absint(get_transient('redirect_delay_seconds')) : 0;
    $instant_popup_builder_sound_open = get_transient('sound_open');
    $instant_popup_builder_sound_close = get_transient('sound_close');
    $instant_popup_builder_sound_open_file = get_transient('sound_open_file');
    $instant_popup_builder_sound_close_file = get_transient('sound_close_file');

    // Template-specific variables
    $instant_popup_builder_template_style = get_transient('template_style') ?: 'basic';
    $instant_popup_builder_popup_main_title = get_transient('popup_main_title') ?: 'Subscribe Our Newsletter';
    $instant_popup_builder_popup_description = get_transient('popup_description');
    $instant_popup_builder_first_label = get_transient('first_label');
    $instant_popup_builder_first_placeholder = get_transient('first_placeholder');
    $instant_popup_builder_email_placeholder = get_transient('email_placeholder');
    $instant_popup_builder_email_label = get_transient('email_label');
    $instant_popup_builder_privacy_label = get_transient('privacy_label');
    $instant_popup_builder_privacy_url = get_transient('pricacy_url');
    $instant_popup_builder_terms_url = get_transient('terms_url');
    $instant_popup_builder_button_text = get_transient('button_text') ?: 'Subscribe';



    // Template-specific design options
    $instant_popup_builder_primary_color = get_transient('primary_color');
    $instant_popup_builder_secondary_color = get_transient('secondary_color');
    $instant_popup_builder_text_color = get_transient('text_color');
    $instant_popup_builder_button_color = get_transient('button_color');
    $instant_popup_builder_accent_color = get_transient('accent_color');
    $instant_popup_builder_background_color_custom = get_transient('background_color_custom');

    // Exit intent is now handled by the extension plugin

    if (!$instant_popup_builder_sound_open_file) {
        $instant_popup_builder_sound_open_file = plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/uploads/sound.mp3';
    }
    if (!$instant_popup_builder_sound_close_file) {
        $instant_popup_builder_sound_close_file = plugin_dir_url(dirname(dirname(__FILE__))) . 'assets/uploads/sound.mp3';
    }
    $instant_popup_builder_new_tab = get_transient('tab');
    $instant_popup_builder_back_zindex = get_transient('back_zindex');
$instant_popup_builder_border_enabled = get_transient('border_enabled');
$instant_popup_builder_border_width = get_transient('border_width');
$instant_popup_builder_border_color = get_transient('border_color');
    // Get popup date from database if available, otherwise use current date
    $popup_date_from_db = isset($instant_popup_builder_row[0]->Date) ? $instant_popup_builder_row[0]->Date : null;
    if ($popup_date_from_db) {
        try {
            $instant_popup_builder_date = new DateTime($popup_date_from_db);
        } catch (Exception $e) {
            $instant_popup_builder_date = new DateTime();
        }
    } else {
        $instant_popup_builder_date = new DateTime();
    }

    $instant_popup_builder_currentDate = new DateTime();
    $instant_popup_builder_currentDate->modify('+20 days');

    // Calculate difference between current date + 20 days and popup date
    $instant_popup_builder_diff = $instant_popup_builder_currentDate->diff($instant_popup_builder_date);
    $instant_popup_builder_days_diff = $instant_popup_builder_diff->days;
    $instant_popup_builder_views = get_transient('instant_popup_builder_popup_views');

    $instant_popup_builder_margins = explode('-', (string) ( $instant_popup_builder_popup_position ?? '' ));
    $instant_popup_builder_marginy = isset($instant_popup_builder_margins[0]) ? $instant_popup_builder_margins[0] : '';
    $instant_popup_builder_marginx = isset($instant_popup_builder_margins[1]) ? $instant_popup_builder_margins[1] : '';

    $instant_popup_builder_margin_style = '';

    if ($instant_popup_builder_marginy === 'end' && $instant_popup_builder_marginx === 'start') {
        $instant_popup_builder_margin_style .= 'margin-left: 70px; ';
        $instant_popup_builder_margin_style .= 'margin-bottom: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'end' && $instant_popup_builder_marginx === 'end') {
        $instant_popup_builder_margin_style .= 'margin-right: 70px; ';
        $instant_popup_builder_margin_style .= 'margin-bottom: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'end' && $instant_popup_builder_marginx === 'center') {
        $instant_popup_builder_margin_style .= 'margin-bottom: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'center' && $instant_popup_builder_marginx === 'end') {
        $instant_popup_builder_margin_style .= 'margin-right: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'start' && $instant_popup_builder_marginx === 'start') {
        $instant_popup_builder_margin_style .= 'margin-left: 70px; ';
        $instant_popup_builder_margin_style .= 'margin-top: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'start' && $instant_popup_builder_marginx === 'center') {
        $instant_popup_builder_margin_style .= 'margin-top: 70px; ';
    } elseif ($instant_popup_builder_marginy === 'start' && $instant_popup_builder_marginx === 'end') {
        $instant_popup_builder_margin_style .= 'margin-right: 70px; ';
        $instant_popup_builder_margin_style .= 'margin-top: 70px; ';
    }

    // Template CSS classes
    $instant_popup_builder_template_classes = "subscription_popup {$instant_popup_builder_template_style}_template";
?>
    <?php if ($instant_popup_builder_is_active == 'yes'): ?>
        <?php if ($instant_popup_builder_template_style === 'bottom'): ?>
            <!-- Floating Bottom Popup - Special handling outside overlay structure -->
            <div class="instant_popup-front instant-popup bottom-popup"
                data-id="<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-close-positon="<?php echo esc_attr($instant_popup_builder_close_position); ?>"
                data-action="<?php echo esc_attr($instant_popup_builder_action); ?>"
                data-action-type="<?php echo esc_attr($instant_popup_builder_action_type); ?>"
                data-action-popup-id="<?php echo esc_attr($instant_popup_builder_action_popup_id); ?>"
                data-action-url="<?php echo esc_attr($instant_popup_builder_url); ?>"
                data-action-tab="<?php echo esc_attr($instant_popup_builder_new_tab); ?>"
                data-redirect-delay-seconds="<?php echo esc_attr($instant_popup_builder_redirect_delay_seconds); ?>"
                data-close-escape="<?php echo esc_attr($instant_popup_builder_close_escape); ?>"
                data-close-outside="<?php echo esc_attr($instant_popup_builder_close_outside); ?>"
                data-back_zindex="<?php echo esc_attr($instant_popup_builder_back_zindex); ?>"
                data-border-enabled="<?php echo esc_attr($instant_popup_builder_border_enabled); ?>"
                data-border-width="<?php echo esc_attr($instant_popup_builder_border_width); ?>"
                data-border-color="<?php echo esc_attr($instant_popup_builder_border_color); ?>"
                data-close-hide="<?php echo esc_attr($instant_popup_builder_hide_close); ?>"
                data-close-hover="<?php echo esc_attr($instant_popup_builder_hover_close); ?>"
                data-hover="<?php echo esc_attr($instant_popup_builder_class_hover); ?>"
                data-click="<?php echo esc_attr($instant_popup_builder_class_click); ?>"
                data-trigger="<?php echo esc_attr($instant_popup_builder_trigger_option); ?>"
                data-target="<?php echo esc_attr($instant_popup_builder_target_device); ?>"
                data-sensitivity="<?php echo esc_attr($instant_popup_builder_exit_sensivity); ?>"
                data-exit-mouse-leave="<?php echo esc_attr($instant_popup_builder_exit_intent_options['mouse_leave']); ?>"
                data-exit-lost-focus="<?php echo esc_attr($instant_popup_builder_exit_intent_options['lost_focus']); ?>"
                data-exit-back-button="<?php echo esc_attr($instant_popup_builder_exit_intent_options['back_button']); ?>"
                data-exit-link-click="<?php echo esc_attr($instant_popup_builder_exit_intent_options['link_click']); ?>"
                data-scroll-type = "<?php echo esc_attr($instant_popup_builder_scroll_type)?>"
                data-scroll-distance = "<?php echo esc_attr($instant_popup_builder_scroll_distance)?>"
                data-scroll-trigger-settings = "<?php echo esc_attr($instant_popup_builder_scroll_trigger_settings)?>"
                <?php
                $extension_attributes = apply_filters('ipb_popup_data_attributes', [], $instant_popup_builder_id, $instant_popup_builder_trigger_option);
                if (!empty($extension_attributes) && is_array($extension_attributes)) {
                    foreach ($extension_attributes as $attr_name => $attr_value) {
                        echo 'data-' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '" ';
                    }
                }
                ?>
                data-limit-count="<?php echo esc_attr($instant_popup_builder_limit_count); ?>"
                data-views-count="<?php echo esc_attr($instant_popup_builder_views); ?>"
                data-limit-expiry="<?php echo esc_attr($instant_popup_builder_days_diff); ?>"
                data-position="<?php echo esc_attr($instant_popup_builder_popup_position); ?>"
                data-template="<?php echo esc_attr($instant_popup_builder_template_style); ?>"
                id="instant-<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-form-id="<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-delay="<?php echo $instant_popup_builder_delay != '' ? esc_attr($instant_popup_builder_delay) : ''; ?>"
                style="display: none;">

                <div class="audio_wrapper">
                    <?php if ($instant_popup_builder_sound_open): ?>
                        <audio id="ipb_audioOpen" class="audio_file" src="<?php echo esc_url($instant_popup_builder_sound_open_file); ?>" display="none"></audio>
                    <?php endif; ?>
                    <?php if ($instant_popup_builder_sound_close): ?>
                        <audio id="ipb_audioClose" class="audio_file" src="<?php echo esc_url($instant_popup_builder_sound_close_file); ?>" display="none"></audio>
                    <?php endif; ?>
                </div>

                <?php include plugin_dir_path(__FILE__) . 'templates/frontend-bottom.php'; ?>
            </div>
        <?php else: ?>
            <!-- Standard Modal Popup Structure for other templates -->
            <div class="instant_popup-front instant-popup"
                data-id="<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-close-positon="<?php echo esc_attr($instant_popup_builder_close_position); ?>"
                data-action="<?php echo esc_attr($instant_popup_builder_action); ?>"
                data-action-type="<?php echo esc_attr($instant_popup_builder_action_type); ?>"
                data-action-popup-id="<?php echo esc_attr($instant_popup_builder_action_popup_id); ?>"
                data-action-url="<?php echo esc_attr($instant_popup_builder_url); ?>"
                data-action-tab="<?php echo esc_attr($instant_popup_builder_new_tab); ?>"
                data-redirect-delay-seconds="<?php echo esc_attr($instant_popup_builder_redirect_delay_seconds); ?>"
                data-close-escape="<?php echo esc_attr($instant_popup_builder_close_escape); ?>"
                data-close-outside="<?php echo esc_attr($instant_popup_builder_close_outside); ?>"
                data-back_zindex="<?php echo esc_attr($instant_popup_builder_back_zindex); ?>"
                data-border-enabled="<?php echo esc_attr($instant_popup_builder_border_enabled); ?>"
                data-border-width="<?php echo esc_attr($instant_popup_builder_border_width); ?>"
                data-border-color="<?php echo esc_attr($instant_popup_builder_border_color); ?>"
                data-close-hide="<?php echo esc_attr($instant_popup_builder_hide_close); ?>"
                data-close-hover="<?php echo esc_attr($instant_popup_builder_hover_close); ?>"
                data-hover="<?php echo esc_attr($instant_popup_builder_class_hover); ?>"
                data-click="<?php echo esc_attr($instant_popup_builder_class_click); ?>"
                data-trigger="<?php echo esc_attr($instant_popup_builder_trigger_option); ?>"
                data-target="<?php echo esc_attr($instant_popup_builder_target_device); ?>"
                data-sensitivity="<?php echo esc_attr($instant_popup_builder_exit_sensivity); ?>"
                data-exit-mouse-leave="<?php echo esc_attr($instant_popup_builder_exit_intent_options['mouse_leave']); ?>"
                data-exit-lost-focus="<?php echo esc_attr($instant_popup_builder_exit_intent_options['lost_focus']); ?>"
                data-exit-back-button="<?php echo esc_attr($instant_popup_builder_exit_intent_options['back_button']); ?>"
                data-exit-link-click="<?php echo esc_attr($instant_popup_builder_exit_intent_options['link_click']); ?>"
                data-scroll-type = "<?php echo esc_attr($instant_popup_builder_scroll_type)?>"
                data-scroll-distance = "<?php echo esc_attr($instant_popup_builder_scroll_distance)?>"
                data-scroll-trigger-settings = "<?php echo esc_attr($instant_popup_builder_scroll_trigger_settings)?>"
                <?php
                $extension_attributes = apply_filters('ipb_popup_data_attributes', [], $instant_popup_builder_id, $instant_popup_builder_trigger_option);
                if (!empty($extension_attributes) && is_array($extension_attributes)) {
                    foreach ($extension_attributes as $attr_name => $attr_value) {
                        echo 'data-' . esc_attr($attr_name) . '="' . esc_attr($attr_value) . '" ';
                    }
                }
                ?>
                data-limit-count="<?php echo esc_attr($instant_popup_builder_limit_count); ?>"
                data-views-count="<?php echo esc_attr($instant_popup_builder_views); ?>"
                data-limit-expiry="<?php echo esc_attr($instant_popup_builder_days_diff); ?>"
                data-position="<?php echo esc_attr($instant_popup_builder_popup_position); ?>"
                data-back_color_toggle="<?php echo esc_attr($instant_popup_builder_back_color_toggle); ?>"
                data-popup_theme="<?php echo esc_attr($instant_popup_builder_popup_theme); ?>"
                data-background_color="<?php echo esc_attr($instant_popup_builder_background_color); ?>"
                data-back_image_toggle="<?php echo esc_attr($instant_popup_builder_back_image_toggle); ?>"
                data-background_image="<?php echo esc_attr($instant_popup_builder_background_image); ?>"
                data-back_image_pos_toggle="<?php echo esc_attr($instant_popup_builder_back_image_pos_toggle); ?>"
                data-back_img_position="<?php echo esc_attr($instant_popup_builder_back_img_position); ?>"
                data-back_image_size="<?php echo esc_attr($instant_popup_builder_back_image_size); ?>"
                data-backcolor_opacity="<?php echo esc_attr($instant_popup_builder_backcolor_opacity); ?>"
                data-backimage_opacity="<?php echo esc_attr($instant_popup_builder_backimage_opacity); ?>"
                data-design_width="<?php echo esc_attr($instant_popup_builder_design_width); ?>"
                data-design_height="<?php echo esc_attr($instant_popup_builder_design_height); ?>"
                data-design_percentage="<?php echo esc_attr($instant_popup_builder_design_percentage); ?>"
                data-design_percentage_toggle="<?php echo esc_attr($instant_popup_builder_design_percentage_toggle); ?>"
                data-animate_type="<?php echo esc_attr($instant_popup_builder_animate_type); ?>"
                data-animate_speed="<?php echo esc_attr($instant_popup_builder_animate_speed); ?>"
                data-animate_origin="<?php echo esc_attr($instant_popup_builder_animate_origin); ?>"
                id="instant-<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-form-id="<?php echo esc_attr($instant_popup_builder_id); ?>"
                data-template="<?php echo esc_attr($instant_popup_builder_template_style); ?>"
                data-delay="<?php echo $instant_popup_builder_delay != '' ? esc_attr($instant_popup_builder_delay) : ''; ?>">
                <div class="instant_overlay">
                    <div class="audio_wrapper">
                        <?php if ($instant_popup_builder_sound_open): ?>
                            <audio id="ipb_audioOpen" class="audio_file" src="<?php echo esc_url($instant_popup_builder_sound_open_file); ?>" display="none"></audio>
                        <?php endif; ?>
                        <?php if ($instant_popup_builder_sound_close): ?>
                            <audio id="ipb_audioClose" class="audio_file" src="<?php echo esc_url($instant_popup_builder_sound_close_file); ?>" display="none"></audio>
                        <?php endif; ?>
                    </div>
                    <div class="intant-popup-type-subscription instant-popup-content subscription-popup-wrapper" style="<?php echo esc_attr($instant_popup_builder_margin_style); ?>">
                        <?php ipb_render_close_button( array( 
                            'popup_type' => 'subscription',
                            'has_image'  => ! empty( $instant_popup_builder_image_url )
                        ) ); ?>

                        <form action="" method="post" id="subscription_form">
                            <?php
                            // Include template-specific HTML based on template style
                            switch ($instant_popup_builder_template_style) {
                                case 'simple_subscribe':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-simple_subscribe.php';
                                    break;
                                case 'christmas':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-christmas.php';
                                    break;
                                case 'black_friday':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-black_friday.php';
                                    break;
                                case 'glassmorphism':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-glassmorphism.php';
                                    break;
                                case 'dark':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-dark.php';
                                    break;
                                case 'exit_intent':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-exit_intent.php';
                                    break;
                                case 'newsletter_horizontal':
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-newsletter_horizontal.php';
                                    break;
                                case 'colorful':
                                case 'classic':
                                case 'creative':
                                case 'basic':
                                default:
                                    include plugin_dir_path(__FILE__) . 'templates/frontend-basic.php';
                                    break;
                            }
                            ?>
                        </form>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <style>
        /* Fix popup display while removing white overlay background */
        .instant_popup-front.instant-popup {
            background: rgba(0, 0, 0, 0.5) !important; /* Semi-transparent dark overlay */
        }

        .instant_popup-front.instant-popup .instant_overlay {
            background: transparent !important;
            display: flex !important;
            min-height: 100vh !important;
            padding: 20px !important;
            box-sizing: border-box !important;
        }

        .intant-popup-type-subscription.instant-popup-content.subscription-popup-wrapper {
            background: transparent !important;
            position: relative !important;
            margin: 0 auto !important;
            padding: 0 !important;
            display: inline-block !important; /* Make wrapper fit content size */
            width: auto !important;
            max-width: 100% !important;
        }

        .intant-popup-type-subscription.instant-popup-content.subscription-popup-wrapper #subscription_form {
            margin: 0 !important;
            padding: 0 !important;
            width: 100% !important;
            height: 100% !important;
            background: transparent !important;
            display: block !important;
        }

        /* Ensure basic newsletter container maintains its width constraints */
        .intant-popup-type-subscription .basic-newsletter-container {
            width: 100% !important;
            max-width: 850px !important; /* With image */
            margin: 0 auto !important;
        }

        .intant-popup-type-subscription .basic-newsletter-container:not(.has-image) {
            max-width: 500px !important; /* Without image */
        }

        /* Specific positioning for basic newsletter template - wrapper now matches container size */
        .intant-popup-type-subscription.subscription-popup-wrapper:has(.basic-newsletter-container) {
            position: relative !important;
        }

        /* Ensure basic newsletter container is positioned relative for proper alignment */
        .intant-popup-type-subscription .basic-newsletter-container {
            position: relative !important;
        }

        /* Close button styles are now centralized in instant-popup-builder-public.css */

        /* Ensure image displays properly in basic template */
        .intant-popup-type-subscription .basic-newsletter-container .newsletter-image-section .newsletter-image {
            display: block !important;
            width: 100% !important;
            height: 100% !important;
            object-fit: cover !important;
        }

        /* Ensure popup content is visible and properly styled */
        .newsletter-popup-container,
        .simple-subscribe-container,
        .newsletter-horizontal-wrapper {
            display: block !important;
            visibility: visible !important;
            opacity: 1 !important;
            position: relative !important;
            z-index: 1 !important;
        }

        /* Responsive adjustments */
        @media (max-width: 768px) {
            .instant_popup-front.instant-popup .instant_overlay {
                padding: 10px !important;
            }

            .newsletter-popup-container,
            .simple-subscribe-container {
                max-width: calc(100vw - 20px) !important;
            }
        }
        </style>
    <?php endif;
}else{

    include WP_PLUGIN_DIR . '/instant-popup-subscription/public/partials/shortcode-subscription.php';
}
    ?>
