<?php

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

// Include module class files
require_once LOGINDES_MODULES . 'class-login-style.php';


// Include admin settings
require_once LOGINDES_INCLUDES . 'helper.php';
require_once LOGINDES_INCLUDES . 'admin/class-admin-settings.php';


if ( !function_exists('logindes_login_admin_enqueue_assets') ) {
    // Include Js and css Files for admin
    add_action('admin_enqueue_scripts', 'logindes_login_admin_enqueue_assets');

    // Enqueue frontend styles
    function logindes_login_admin_enqueue_assets($hook)
    {

        wp_enqueue_media();

        wp_enqueue_script(
            'logindes-admin-js',
            LOGINDES_URL . 'assets/js/wplc-admin.min.js',
            array('jquery'),
            time(),
            true
        );

        wp_enqueue_style(
            'logindes--admin-css',
            LOGINDES_URL . 'assets/css/wplc-admin.min.css',
            [],
            time()
        );

        wp_enqueue_script(
            'logindes-minicolors',
            LOGINDES_URL . 'assets/js/rgbaColorPicker.min.js',
            array('jquery'),
            time(),
            true
        );

        wp_enqueue_style(
            'logindes-minicolors-css',
            LOGINDES_URL . 'assets/css/rgbaColorPicker.min.css',
            [],
            time()
        );

        if ($hook === 'toplevel_page_wplc-login-customizer') {
            wp_enqueue_style(
                'logindes-fa-css',
                LOGINDES_URL . 'assets/css/fa.min.css',
                [],
                time()
            );
        }

        if ( function_exists('logindes_admin_enject_styles') ) {

            logindes_admin_enject_styles();
        }
    }
}

if ( !function_exists('logindes_login_enqueue_custom_scripts') ) {
    // Enqueue custom JS and CSS for your login page
    add_action('login_enqueue_scripts', 'logindes_login_enqueue_custom_scripts');
    function logindes_login_enqueue_custom_scripts()
    {
        // jQuery is already available
        wp_enqueue_script(
            'logindes-custom-js',
            LOGINDES_URL . 'assets/js/wplc-frontend.min.js',
            array('jquery'),
            time(),
            true
        );

        wp_enqueue_style(
            'logindes--cutom-css',
            LOGINDES_URL . 'assets/css/wplc-frontend.min.css',
            [],
            time()
        );

        if ( function_exists('logindes_frontend_enject_styles') ) {
            logindes_frontend_enject_styles();
        }
    }
}

// Initialize modules on plugins_loaded
if ( !function_exists('logindes_login_init_modules') ) {

    add_action('plugins_loaded', 'logindes_login_init_modules');
    function logindes_login_init_modules()
    {

        if (class_exists('logindes_login_style')) {
            Logindes_login_style::init();
        }

        if (class_exists('logindes_login_customizer_Admin')) {
            Logindes_login_customizer_Admin::init();
        }

    }
}

if ( !function_exists('logindes_admin_enject_styles') ) {
    function logindes_admin_enject_styles()
    {

        $screen = get_current_screen();

        // Dynamic image and logo options
        $bg_image = esc_url(get_option('logindes_login_bg_image', ''));
        $form_bg_image = esc_url(get_option('logindes_form_bg_image', ''));
        $form_bg_color = sanitize_hex_color(get_option('logindes_form_bg_color', '#ffffff')); // default white form
        $form_bg_transparent = get_option('logindes_form_bg_transparent', 0);
        $form_bg_width = get_option('logindes_form_bg_width', '400');
        $form_bg_size_width = get_option('logindes_form_bg_size_width', '100');
        $form_bg_height = get_option('logindes_form_bg_height', 'auto');
        $form_bg_size_height = get_option('logindes_form_bg_size_height', 'auto');
        $form_bg_repeat = get_option('logindes_form_bg_repeat', 'no-repeat');
        $form_bg_opacity = get_option('logindes_form_bg_opacity', '100');
        $form_bg_opacity = intval($form_bg_opacity);
        $form_bg_image_position = sanitize_text_field(get_option('logindes_formBackgroundImagePosition', 'center'));
        $logo_text_color = sanitize_text_field(get_option('logindes_logo_text_color', '#ffffff'));
        // Logo settings
        $logo_align = esc_attr(get_option('logindes_logo_align', 'center'));
        $logo_text_align = esc_attr(get_option('logindes_logo_text_align', 'center'));
        $logo_top = intval(get_option('logindes_logo_top', 20));
        $logo_bottom = intval(get_option('logindes_logo_bottom', 20));
        $logo_width = intval(get_option('logindes_logo_width', 150));
        $logo_height = intval(get_option('logindes_logo_height', 80));
        $logo_font_size = intval(get_option('logindes_logo_font_size', 18));
        $logo_font_weight = esc_attr(get_option('logindes_logo_font_weight', 'normal'));

        $top = get_option('logindes_form_bg_position_top', '26');
        $bottom = get_option('logindes_form_bg_position_bottom', '26');
        $left = get_option('logindes_form_bg_position_left', '24');
        $right = get_option('logindes_form_bg_position_right', '24');

        // Input styling options
        $input_bg_color = get_option('logindes_input_bg_color', '#fff');
        $input_text_color = get_option('logindes_input_text_color', '#2c3338');
        $input_font_size = get_option('logindes_input_font_size', '14');
        $input_padding_top = get_option('logindes_input_padding_top', '10');
        $input_padding_bottom = get_option('logindes_input_padding_bottom', '10');
        $input_padding_left = get_option('logindes_input_padding_left', '10');
        $input_padding_right = get_option('logindes_input_padding_right', '10');
        $input_border_radius = get_option('logindes_input_border_radius', '4');
        $input_border_width = get_option('logindes_input_border_width', '1');
        $input_border_style = get_option('logindes_input_border_style', 'solid');
        $input_border_color = get_option('logindes_input_border_color', '#8c8f94');

        // Button styling options
        $button_bg_color = get_option('logindes_button_bg_color', '#135e96');
        $button_text_color = get_option('logindes_button_text_color', '#fff');
        $button_font_size = get_option('logindes_button_font_size', '13');
        $button_padding_top = get_option('logindes_button_padding_top', '10');
        $button_padding_bottom = get_option('logindes_button_padding_bottom', '10');
        $button_padding_left = get_option('logindes_button_padding_left', '12');
        $button_padding_right = get_option('logindes_button_padding_right', '12');
        $button_border_radius = get_option('logindes_button_border_radius', '3');
        $button_border_width = get_option('logindes_button_border_width', '1');
        $button_border_style = get_option('logindes_button_border_style', 'solid');
        $button_border_color = get_option('logindes_button_border_color', '#135e96');

        // Label styling options
        $label_text_color = get_option('logindes_label_text_color', '#3c434a');
        $label_font_size = get_option('logindes_label_font_size', '14');

        $forgot_text_color = get_option('logindes_forgot_text_color', '#3c434a');
        $forgot_font_size = get_option('logindes_forgot_font_size', '14');

        // Background controls
        $bg_color = sanitize_hex_color(get_option('logindes_login_bg_color', '#f0f0f1'));
        $bg_w = sanitize_text_field(get_option('logindes_login_bg_size_w', '100'));
        $bg_h = sanitize_text_field(get_option('logindes_login_bg_size_h', 'auto'));
        $bg_repeat = sanitize_text_field(get_option('logindes_login_bg_repeat', 'no-repeat'));
        $bg_opacity = get_option('logindes_login_bg_opacity', '100'); // default 100%
        $bg_op = intval($bg_opacity);
        $bg_op = max(0, min(100, $bg_op)) / 100; // convert 0–100 → 0–1
        $bg_top = sanitize_text_field(get_option('logindes_login_bg_pos_top', ''));
        $bg_bottom = sanitize_text_field(get_option('logindes_login_bg_pos_bottom', ''));
        $bg_left = sanitize_text_field(get_option('logindes_login_bg_pos_left', ''));
        $bg_right = sanitize_text_field(get_option('logindes_login_bg_pos_right', ''));
        $bg_image_position = sanitize_text_field(get_option('logindes_backgroundImagePosition', 'center'));

        //Size Attributes 
        $login_bg_size_w_attr = sanitize_text_field(get_option('logindes_login_bg_size_w_attr', 'px'));
        $login_bg_size_h_attr = sanitize_text_field(get_option('logindes_login_bg_size_h_attr', 'px'));
        $login_padding_attr = sanitize_text_field(get_option('logindes_login_padding_attr', 'px'));

        $form_bg_w_attr = sanitize_text_field(get_option('logindes_form_bg_w_attr', 'px'));
        $form_bg_h_attr = sanitize_text_field(get_option('logindes_form_bg_h_attr', 'px'));
        $form_bg_size_width_attr = sanitize_text_field(get_option('logindes_form_bg_size_width_attr', 'px'));
        $form_bg_size_h_attr = sanitize_text_field(get_option('logindes_form_bg_size_h_attr', 'px'));
        $form_bg_padding_attr = sanitize_text_field(get_option('logindes_form_bg_padding_attr', 'px'));

        $input_font_size_attr = sanitize_text_field(get_option('logindes_input_font_size_attr', 'px'));
        $input_padding_attr = sanitize_text_field(get_option('logindes_input_padding_attr', 'px'));
        $input_border_radius_attr = sanitize_text_field(get_option('logindes_input_border_radius_attr', 'px'));
        $input_border_width_attr = sanitize_text_field(get_option('logindes_input_border_width_attr', 'px'));

        $button_font_size_attr = sanitize_text_field(get_option('logindes_button_font_size_attr', 'px'));
        $button_padding_attr = sanitize_text_field(get_option('logindes_button_padding_attr', 'px'));
        $button_border_radius_attr = sanitize_text_field(get_option('logindes_button_border_radius_attr', 'px'));
        $button_border_width_attr = sanitize_text_field(get_option('logindes_button_border_width_attr', 'px'));

        $label_font_size_attr = sanitize_text_field(get_option('logindes_label_font_size_attr', 'px'));
        $forgot_font_size_attr = sanitize_text_field(get_option('logindes_forgot_font_size_attr', 'px'));


        // Prepare CSS vars
        $bg_size = '';
        if ($bg_w !== '' || $bg_h !== '') {
            $w = $bg_w !== '' ? $bg_w : 'auto';
            $h = $bg_h !== '' ? $bg_h : 'auto';
            $bg_size = $w . $login_bg_size_w_attr . ' ' . $h . $login_bg_size_h_attr;
        }

        $form_bg_size = '';
        if ($form_bg_size_width !== '' || $form_bg_size_height !== '') {
            $w = $form_bg_size_width !== '' ? $form_bg_size_width : 'auto';
            $h = $form_bg_size_height !== '' ? $form_bg_size_height : 'auto';
            $form_bg_size = $w . $form_bg_size_width_attr . ' ' . $h . $form_bg_size_h_attr;
        }

        ob_start();
        ?>
        <style>

            <?php 
                if ( $screen && $screen->id === 'toplevel_page_wplc-login-customizer' ) {
                    ?>
                        #wpfooter, #adminmenumain, #wpadminbar { display: none !important; }
                        html, body { margin: 0; padding: 0; height: 100%; background: #fff; }
                    <?php
                }
            ?>

            .main-preview {
                <?php if ($bg_image): ?>
                    background: url('<?php echo esc_url($bg_image); ?>');
                    background-size:
                        <?php echo $bg_size ? esc_attr($bg_size) : 'cover'; ?>
                    ;
                    background-position:
                        <?php echo esc_attr($bg_image_position); ?>
                    ;
                    background-repeat:
                        <?php echo esc_attr($bg_repeat); ?>
                    ;
                    padding-top:
                        <?php echo esc_attr($bg_top); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-bottom:
                        <?php echo esc_attr($bg_bottom); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-left:
                        <?php echo esc_attr($bg_left); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-right:
                        <?php echo esc_attr($bg_right); echo esc_attr($login_padding_attr); ?>
                    ;
                <?php else:

                    $bg_color = sanitize_hex_color($bg_color);
        
                    if (!$bg_color) {
                        $bg_color = '#000000';
                    }
                    $r = hexdec(substr($bg_color, 1, 2));
                    $g = hexdec(substr($bg_color, 3, 2));
                    $b = hexdec(substr($bg_color, 5, 2));
                    ?>
                    background: rgba(
                            <?php echo esc_attr($r); ?>
                            ,
                            <?php echo esc_attr($g); ?>
                            ,
                            <?php echo esc_attr($b); ?>
                        );
                    ?>padding-top:
                        <?php echo esc_attr($bg_top); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-bottom:
                        <?php echo esc_attr($bg_bottom); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-left:
                        <?php echo esc_attr($bg_left); echo esc_attr($login_padding_attr); ?>
                    ;
                    padding-right:
                        <?php echo esc_attr($bg_right); echo esc_attr($login_padding_attr); ?>
                    ;
                <?php endif; ?>
                position: relative;
            }

            .main-preview .login-box-simple {
                background:
                    <?php echo $form_bg_transparent ? 'transparent' : esc_attr($form_bg_color); ?>
                ;
                <?php if ($form_bg_image): ?>
                    background-image: url('<?php echo esc_url($form_bg_image); ?>');
                    background-size: <?php echo $form_bg_size ? esc_attr($form_bg_size) : 'cover'; ?>;
                    background-repeat:
                        <?php echo esc_attr($form_bg_repeat); ?>
                    ;
                    background-position:
                        <?php echo esc_attr($form_bg_image_position); ?>
                    ;
                <?php endif; ?>
                padding-top:
                    <?php echo esc_attr($top); echo esc_attr($form_bg_padding_attr); ?>
                ;
                padding-bottom:
                    <?php echo esc_attr($bottom); echo esc_attr($form_bg_padding_attr); ?>
                ;
                padding-left:
                    <?php echo esc_attr($left); echo esc_attr($form_bg_padding_attr); ?>
                ;
                padding-right:
                    <?php echo esc_attr($right); echo esc_attr($form_bg_padding_attr); ?>
                ;
                width:
                    <?php echo esc_attr($form_bg_width); echo esc_attr( $form_bg_w_attr ); ?>
                ;
                min-height:
                    <?php echo esc_attr($form_bg_height); echo esc_attr( $form_bg_h_attr ); ?>
                ;
                z-index: 99;
                position: relative;
            }

            .main-preview .logo-wrap {
                text-align:
                    <?php echo esc_attr($logo_align); ?>
                ;
                margin-top:
                    <?php echo esc_attr($logo_top); ?>px;
                margin-bottom:
                    <?php echo esc_attr($logo_bottom); ?>px;
            }

            .main-preview .logo-img {
                max-width:
                    <?php echo esc_attr($logo_width); ?>px;
                max-height:
                    <?php echo esc_attr($logo_height); ?>px;
                object-fit: contain;
                width: 100%;
                height: 100%;
            }

            .main-preview .logo-text {
                font-size:
                    <?php echo esc_attr($logo_font_size); ?>px;
                font-weight:
                    <?php echo esc_attr($logo_font_weight); ?>
                ;
                display: block;
                text-align: <?php echo esc_attr($logo_text_align); ?>;
                color: <?php echo esc_attr($logo_text_color); ?>;
            
            }

            .main-preview .field-label, .keep-me label {
                color:
                    <?php echo esc_attr($label_text_color); ?>
                ;
                font-size:
                    <?php echo esc_attr($label_font_size); echo esc_attr( $label_font_size_attr ) ?>
                ;
            }

            .forget-password a {
                color:
                    <?php echo esc_attr($forgot_text_color); ?>
                ;
                font-size:
                    <?php echo esc_attr($forgot_font_size); echo esc_attr($forgot_font_size_attr) ?>
                ;
            }

            #togglePassword svg path {
                stroke: <?php echo esc_attr($input_text_color); ?>
                    !important;
            } 

            .main-preview .input {
                background:
                    <?php echo esc_attr($input_bg_color); ?>
                ;
                color:
                    <?php echo esc_attr($input_text_color); ?>
                    !important;
                font-size:
                    <?php echo esc_attr($input_font_size);  echo esc_attr($input_font_size_attr);  ?>
                ;
                padding-top:
                    <?php echo esc_attr($input_padding_top); echo esc_attr($input_padding_attr); ?>
                ;
                padding-bottom:
                    <?php echo esc_attr($input_padding_bottom);  echo esc_attr($input_padding_attr);?>
                ;
                padding-left:
                    <?php echo esc_attr($input_padding_left); echo esc_attr($input_padding_attr); ?>
                ;
                padding-right:
                    <?php echo esc_attr($input_padding_right); echo esc_attr($input_padding_attr); ?>
                ;
                border-radius:
                    <?php echo esc_attr($input_border_radius); echo esc_attr($input_border_radius_attr); ?>
                ;
                border-width:
                    <?php echo esc_attr($input_border_width); echo esc_attr($input_border_width_attr); ?>
                ;
                border-style:
                    <?php echo esc_attr($input_border_style); ?>
                ;
                border-color:
                    <?php echo esc_attr($input_border_color); ?>
                ;
                box-sizing: border-box;
                width: 100%;
                outline: none !important;
                box-shadow: none !important;
                min-height: 0 !important;
                line-height: 2 !important;
            }

            .main-preview .login-btn {
                background:
                    <?php echo esc_attr($button_bg_color); ?>
                ;
                color:
                    <?php echo esc_attr($button_text_color); ?>
                ;
                font-size:
                    <?php echo esc_attr($button_font_size); echo esc_attr($button_font_size_attr); ?>
                ;
                padding:
                    <?php echo esc_attr($button_padding_top) . esc_attr($button_padding_attr) . ' ' .
                        esc_attr($button_padding_right) . esc_attr($button_padding_attr) . ' ' .
                        esc_attr($button_padding_bottom) . esc_attr($button_padding_attr) . ' ' .
                        esc_attr($button_padding_left)  . esc_attr($button_padding_attr); ?>
                ;
                border-radius:
                    <?php echo esc_attr($button_border_radius); echo esc_attr($button_border_radius_attr); ?>
                ;
                border:
                    <?php echo esc_attr($button_border_width . $button_border_width_attr . ' ' .
                        $button_border_style . ' ' .
                        $button_border_color); ?>
                ;
                cursor: pointer;
                width: 100%;
                box-sizing: border-box;
            }

            <?php 
                $bg_op = floatval($bg_op); 
                $form_bg_opacity = floatval($form_bg_opacity) / 100;
                
                if ( $form_bg_transparent ) {
                    $form_bg_opacity = 1.0;

                }
            ?> 

            .opacity-div {
                width: 100%;
                height: 100%;
                position: absolute;
                top: 0;
                left: 0;
                background: black;
                z-index: 9;
                opacity: <?php echo 1 - esc_attr($bg_op); ?>;
            }

            .form-opacity-div {
                background: black;
                width: 100%;
                height: 100%;
                position: absolute;
                top: 0;
                left: 0;
                z-index: -1;
                opacity: <?php echo 1 - esc_attr($form_bg_opacity); ?>;
                border-radius: 20px;
            }

        </style> 
        <?php
        $style = ob_get_clean();
        wp_add_inline_style('logindes--admin-css', $style);
    }
}


if ( !function_exists('logindes_frontend_enject_styles') ) {
    function logindes_frontend_enject_styles () {
        
        //Size Attributes 
        $login_bg_size_w_attr = sanitize_text_field(get_option('logindes_login_bg_size_w_attr', 'px'));
        $login_bg_size_h_attr = sanitize_text_field(get_option('logindes_login_bg_size_h_attr', 'px'));
        $login_padding_attr = sanitize_text_field(get_option('logindes_login_padding_attr', 'px'));

        $form_bg_w_attr = sanitize_text_field(get_option('logindes_form_bg_w_attr', 'px'));
        $form_bg_h_attr = sanitize_text_field(get_option('logindes_form_bg_h_attr', 'px'));
        $form_bg_size_width_attr = sanitize_text_field(get_option('logindes_form_bg_size_width_attr', 'px'));
        $form_bg_size_h_attr = sanitize_text_field(get_option('logindes_form_bg_size_h_attr', 'px'));
        $form_bg_padding_attr = sanitize_text_field(get_option('logindes_form_bg_padding_attr', 'px'));

        $input_font_size_attr = sanitize_text_field(get_option('logindes_input_font_size_attr', 'px'));
        $input_padding_attr = sanitize_text_field(get_option('logindes_input_padding_attr', 'px'));
        $input_border_radius_attr = sanitize_text_field(get_option('logindes_input_border_radius_attr', 'px'));
        $input_border_width_attr = sanitize_text_field(get_option('logindes_input_border_width_attr', 'px'));

        $button_font_size_attr = sanitize_text_field(get_option('logindes_button_font_size_attr', 'px'));
        $button_padding_attr = sanitize_text_field(get_option('logindes_button_padding_attr', 'px'));
        $button_border_radius_attr = sanitize_text_field(get_option('logindes_button_border_radius_attr', 'px'));
        $button_border_width_attr = sanitize_text_field(get_option('logindes_button_border_width_attr', 'px'));

        $label_font_size_attr = sanitize_text_field(get_option('logindes_label_font_size_attr', 'px'));
        $forgot_font_size_attr = sanitize_text_field(get_option('logindes_forgot_font_size_attr', 'px'));

        $check = true;

        if ( $check ) {
            // Get all custom options
            $bg_image        = get_option('logindes_login_bg_image', '' );
            $bg_color        = get_option('logindes_login_bg_color', '#f0f0f1' );
            $bg_opacity = get_option('logindes_login_bg_opacity', '100'); // default 100%
            $bg_repeat  = sanitize_text_field(get_option('logindes_login_bg_repeat', 'no-repeat'));
            $bg_op = intval($bg_opacity);
            $bg_op = max(0, min(100, $bg_op)) / 100; // convert 0–100 → 0–1
            $bg_w       = sanitize_text_field(get_option('logindes_login_bg_size_w', ''));
            $bg_h       = sanitize_text_field(get_option('logindes_login_bg_size_h', ''));
            $bg_size = '';
            if ($bg_w !== '' || $bg_h !== '') {
                $w       = $bg_w !== '' ? $bg_w : 'auto';
                $h       = $bg_h !== '' ? $bg_h : 'auto';
                $bg_size = $w . $login_bg_size_w_attr . ' ' . $h . $login_bg_size_h_attr;
            }
            $bg_top    = sanitize_text_field(get_option('logindes_login_bg_pos_top', ''));
            $bg_bottom     = sanitize_text_field(get_option('logindes_login_bg_pos_bottom', ''));
            $bg_left     = sanitize_text_field(get_option('logindes_login_bg_pos_left', ''));
            $bg_right     = sanitize_text_field(get_option('logindes_login_bg_pos_right', ''));
            $form_bg_color   = sanitize_hex_color( get_option('logindes_form_bg_color', '#fff' ) );
            $form_bg_image   = esc_url( get_option('logindes_form_bg_image', '' ) );
            $form_bg_transparent = get_option('logindes_form_bg_transparent', 0 );
            $form_bg_opacity = get_option('logindes_form_bg_opacity', 100 );
            $form_bg_opacity = intval(value: $form_bg_opacity);
            $form_bg_width   = get_option('logindes_form_bg_width', '400' );
            $form_bg_height  = get_option('logindes_form_bg_height', '246' );
            $form_bg_repeat  = get_option('logindes_form_bg_repeat', 'no-repeat' );
            $bg_image_position = sanitize_text_field(get_option('logindes_backgroundImagePosition', 'center'));
            $form_bg_image_position = sanitize_text_field(get_option('logindes_formBackgroundImagePosition', 'center'));
            $form_bg_size_width = get_option('logindes_form_bg_size_width', '100');
            $form_bg_size_height = get_option('logindes_form_bg_size_height', 'auto');

            $form_bg_size = '';
            if ($form_bg_size_width !== '' || $form_bg_size_height !== '') {
                $w = $form_bg_size_width !== '' ? $form_bg_size_width : 'auto';
                $h = $form_bg_size_height !== '' ? $form_bg_size_height : 'auto';
                $form_bg_size = $w . $form_bg_size_width_attr . ' ' . $h . $form_bg_size_h_attr;
            }

            // Separate options for position
            $form_bg_position_top    = get_option('logindes_form_bg_position_top', '26');
            $form_bg_position_bottom = get_option('logindes_form_bg_position_bottom', '26');
            $form_bg_position_left   = get_option('logindes_form_bg_position_left', '24');
            $form_bg_position_right  = get_option('logindes_form_bg_position_right', '24');

            $input_bg_color       = get_option('logindes_input_bg_color', '#fff');
            $input_text_color     = get_option('logindes_input_text_color', '#2c3338');
            $input_font_size      = get_option('logindes_input_font_size', '14');
            $input_padding_top    = get_option('logindes_input_padding_top', '10');
            $input_padding_bottom = get_option('logindes_input_padding_bottom', '10');
            $input_padding_left   = get_option('logindes_input_padding_left', '10');
            $input_padding_right  = get_option('logindes_input_padding_right', '10');
            $input_border_radius  = get_option('logindes_input_border_radius', '4');
            $input_border_width   = get_option('logindes_input_border_width', '1');
            $input_border_style   = get_option('logindes_input_border_style', 'solid');
            $input_border_color   = get_option('logindes_input_border_color', '#8c8f94');

            $button_bg_color      = get_option('logindes_button_bg_color', '#135e96');
            $button_text_color    = get_option('logindes_button_text_color', '#fff');
            $button_font_size     = get_option('logindes_button_font_size', '13');
            $button_padding_top   = get_option('logindes_button_padding_top', '10');
            $button_padding_bottom= get_option('logindes_button_padding_bottom', '10');
            $button_padding_left  = get_option('logindes_button_padding_left', '12');
            $button_padding_right = get_option('logindes_button_padding_right', '12');
            $button_border_radius = get_option('logindes_button_border_radius', '3');
            $button_border_width  = get_option('logindes_button_border_width', '1');
            $button_border_style  = get_option('logindes_button_border_style', 'solid');
            $button_border_color  = get_option('logindes_button_border_color', '#135e96');


            $label_text_color    = get_option('logindes_label_text_color', '');
            $label_font_size      = get_option('logindes_label_font_size', '');

            $forgot_text_color    = get_option('logindes_forgot_text_color', '');
            $forgot_font_size      = get_option('logindes_forgot_font_size', '');

            $width           = intval( get_option('logindes_logo_width', 150) );
            $height          = intval( get_option('logindes_logo_height', 80) );
            $top             = intval( get_option('logindes_logo_top', 20) );
            $bottom          = intval( get_option('logindes_logo_bottom', 20) );
            $align           = esc_attr( get_option('logindes_logo_align', 'center') );
            $font            = intval( get_option('logindes_logo_font_size', 18) );
            $weight          = esc_attr( get_option('logindes_logo_font_weight', 'normal') );

            $logo_text_color = sanitize_text_field(get_option('logindes_logo_text_color', '#ffffff'));
            $logo_text_align = esc_attr(get_option('logindes_logo_text_align', 'center'));
        }
        
        ob_start();
        ?>
        <style>
            .login form {
                background: transparent !important;
                margin: 0;
                padding: 0;
                border: none !important;
                box-shadow: none !important;
            }
            .login label{
                display: block;
            }
            body.login {
                <?php if ($bg_image): ?>
                    background-image: url('<?php echo esc_url($bg_image); ?>');
                    background-size: <?php echo $bg_size ? esc_attr($bg_size) : 'cover'; ?>;
                    background-repeat: <?php echo esc_attr($bg_repeat); ?>;
                    padding-top: <?php echo esc_attr($bg_top . $login_padding_attr); ?>;
                    padding-bottom: <?php echo esc_attr($bg_bottom . $login_padding_attr); ?>;
                    padding-left: <?php echo esc_attr($bg_left . $login_padding_attr); ?>;
                    padding-right: <?php echo esc_attr($bg_right . $login_padding_attr); ?>;
                    background-position: <?php echo esc_attr($bg_image_position); ?>;
                <?php else:

                    $bg_color = sanitize_hex_color( $bg_color );
                    $bg_op    = floatval( $bg_op );

                
                    if ( ! $bg_color ) {
                        $bg_color = '#000000';
                    }

                    $r = hexdec( substr( $bg_color, 1, 2 ) );
                    $g = hexdec( substr( $bg_color, 3, 2 ) );
                    $b = hexdec( substr( $bg_color, 5, 2 ) );
                    ?>
                    background: rgba(
                        <?php echo esc_attr( $r ); ?>,
                        <?php echo esc_attr( $g ); ?>,
                        <?php echo esc_attr( $b ); ?>
                    );
                <?php endif; ?>
                display: flex;
                align-items: center !important;
                justify-content: center !important;
                height: 100vh;
                position: relative;
            }

            .custom-login-wrapper{
                background: <?php echo $form_bg_transparent ? 'transparent' : esc_attr($form_bg_color); ?>;
                <?php if ($form_bg_image): ?>
                    background-image: url('<?php echo esc_url($form_bg_image); ?>');
                    background-size: <?php echo esc_attr($form_bg_size) ?>;
                    background-repeat: <?php echo esc_attr($form_bg_repeat); ?>;
                    background-position: <?php echo esc_attr($form_bg_image_position); ?>;
                <?php endif; ?>
                padding-top: <?php echo esc_attr($form_bg_position_top . $form_bg_padding_attr) ?>;
                padding-bottom: <?php echo esc_attr($form_bg_position_bottom . $form_bg_padding_attr) ?>;
                padding-left: <?php echo esc_attr($form_bg_position_left . $form_bg_padding_attr) ?>;
                padding-right: <?php echo esc_attr($form_bg_position_right . $form_bg_padding_attr) ?>;
                width: <?php echo esc_attr($form_bg_width . $form_bg_w_attr) ?>;
                min-height: <?php echo esc_attr($form_bg_height . $form_bg_h_attr) ?>;
                border-radius: 20px;
                box-shadow: 0 5px 25px rgba(0,0,0,.2);
                text-align: center;
                margin: 0 auto;
                z-index: 99;
                position: relative;
            }
            .submit-btn{
                margin-top: 20px !important;
            }
            .custom-login-wrapper .logo { 
                margin-top: <?php echo esc_attr($top); ?>px;
                margin-bottom: <?php echo esc_attr($bottom); ?>px;
                text-align: <?php echo esc_attr($align); ?>;
            }
            .custom-login-wrapper .logo img {
                max-width: <?php echo esc_attr($width); ?>px;
                max-height: <?php echo esc_attr($height); ?>px;
                object-fit: contain;
            }
            .custom-login-wrapper .logo-text {
                font-size: <?php echo esc_attr($font); ?>px;
                font-weight: <?php echo esc_attr($weight); ?>;
                text-align: <?php echo esc_attr($logo_text_align); ?>;
                color: <?php echo esc_attr($logo_text_color); ?>;
            }

            .login-title {
                text-align: center;
                margin-bottom: 30px;
                font-size: 28px;
                font-weight: 600;
                color: #101828;
                margin-top: 0 !important;
                line-height: normal;
            }

            .forget-password {
                display: flex;
                align-items: center;
                justify-content: space-between;
                padding-bottom: 10px;
            }
            .forget-password label{
                padding-bottom: 0;
            }

            .forget-password a {
                color: <?php echo esc_attr($forgot_text_color); ?> !important;
                font-size:  <?php echo esc_attr($forgot_font_size . $forgot_font_size_attr); ?> !important;
                outline:none;
                border:none;
                text-decoration:none;
            }

            .single-field-input input {
                width: 100%;
                background: <?php echo esc_attr($input_bg_color); ?> !important;
                color: <?php echo esc_attr($input_text_color); ?> !important;
                font-size: <?php echo esc_attr($input_font_size . $input_font_size_attr); ?> !important;
                padding-top: <?php echo esc_attr($input_padding_top . $input_padding_attr); ?> !important;
                padding-bottom: <?php echo esc_attr($input_padding_bottom . $input_padding_attr); ?> !important;
                padding-left: <?php echo esc_attr($input_padding_left . $input_padding_attr); ?> !important;
                padding-right: <?php echo esc_attr($input_padding_right . $input_padding_attr); ?> !important;
                border-radius: <?php echo esc_attr($input_border_radius . $input_border_radius_attr); ?> !important;
                border-width: <?php echo esc_attr($input_border_width . $input_border_width_attr); ?> !important;
                border-style: <?php echo esc_attr($input_border_style); ?> !important;
                border-color: <?php echo esc_attr($input_border_color); ?> !important;
                outline:none !important;
                box-shadow:none !important;
                min-height: 0 !important;
                line-height: 2 !important;
                height:auto !important;
                margin: 0px 0px 20px !important;
            }

            #togglePassword svg path {
                stroke: <?php echo esc_attr($input_text_color); ?>
                    !important;
            } 

            .single-field-input label{
                margin: 0 !important;
                display: block;
                padding-bottom: 3px;
                text-align: left;
                color: <?php echo esc_attr($label_text_color); ?>; 
                font-size: <?php echo esc_attr($label_font_size . $label_font_size_attr); ?>;
            }
            .submit-btn input{
                background: <?php echo esc_attr($button_bg_color); ?> !important;
                color: <?php echo esc_attr($button_text_color); ?> !important;
                font-size: <?php echo esc_attr($button_font_size . $button_font_size_attr); ?> !important;
                padding: <?php echo esc_attr($button_padding_top . $button_padding_attr) . ' ' . esc_attr($button_padding_right . $button_padding_attr) . ' ' . esc_attr($button_padding_bottom . $button_padding_attr) . ' ' . esc_attr($button_padding_left . $button_padding_attr); ?> !important;
                border-radius: <?php echo esc_attr($button_border_radius . $button_border_radius_attr); ?> !important;
                border: <?php echo esc_attr($button_border_width . $button_border_width_attr . ' ' . $button_border_style . ' ' . $button_border_color); ?> !important;
                cursor: pointer;
                width: 100%;
                box-sizing: border-box;
                outline:none;
            }
            .keep-me {
                text-align: left;
            }
            .keep-me label{
                color: <?php echo esc_attr($label_text_color); ?>; 
                font-size: <?php echo esc_attr($label_font_size . $label_font_size_attr); ?>;
            }
            .single-field-input{
                position: relative;
            }
            #togglePassword {
                position: absolute;
                top: 57%;
                right: 20px;
                transform: translateY(-50%);
                cursor: pointer;
                width: 24px;
                height: 24px;
            }

            .eye-closed{
                display: none;
            }

            <?php 
                $bg_op = floatval($bg_op); 
                $form_bg_opacity = floatval($form_bg_opacity) / 100;
                if ( $form_bg_transparent ) {
                    $form_bg_opacity = 1.0;
                }
            ?> 

            .opacity-div {
                width: 100%;
                height: 100%;
                position: absolute;
                top: 0;
                left: 0;
                background: black;
                z-index: 9;
                opacity: <?php echo 1 - esc_attr($bg_op); ?>;
            }

            .form-opacity-div {
                background: black;
                width: 100%;
                height: 100%;
                position: absolute;
                top: 0;
                left: 0;
                z-index: -1;
                opacity: <?php echo 1 - esc_attr($form_bg_opacity); ?>;
                border-radius: 20px;
            }
        </style>
        <?php
        $style = ob_get_clean();
        wp_add_inline_style('logindes--cutom-css', $style);
    }
}