<?php

/**
 * Generates and returns inline CSS for the active author bio box template.
 *
 * To enhance performance, each template's CSS is cached separately and only regenerated
 * when Customizer settings are updated.
 *
 * @return string Sanitized inline CSS.
 */


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



function author_kit_generate_bio_box_inline_css()
{
	$active_template = get_option('author_kit_author_bio_template', 'template-default');
	$cache_key       = 'author_kit_inline_css_' . $active_template;

	// Retrieve cached CSS and return if available
	$cached_css = get_transient($cache_key);
	if ($cached_css !== false && ! empty($cached_css)) {
		return wp_kses_post($cached_css);
	}

	$custom_css = '';

	switch ($active_template) {
		case 'template-default':
			// Fetch Customizer settings
			$settings = array(
				'border'            => get_theme_mod('author_kit_bio_box_border_thickness_default', '1px'),
				'border_radius'     => get_theme_mod('author_kit_bio_box_border_radius_default', '8px'),
				'border_color'      => get_theme_mod('author_kit_bio_box_border_color_default', '#fcfcfc'),
				'background_color'  => get_theme_mod('author_kit_bio_box_bg_color_default', '#fbfbfb'),
				'name_color'        => get_theme_mod('author_kit_name_txt_color_default', '#000000'),
				'email_color'       => get_theme_mod('author_kit_subinfo_txt_color_default', '#808080'),
				'description_color' => get_theme_mod('author_kit_bio_text_color_default', '#000000'),
				'heading_bg_color'  => get_theme_mod('author_kit_bio_box_heading_bg_color_default', '#36454F'),
				'heading_txt_color' => get_theme_mod('author_kit_bio_box_heading_txt_color_default', '#FFFFFF'),
			);

			// Name font size
			$name   = get_theme_mod('author_kit_name_font_size_default', array());
			$name_d = isset($name['desktop']) ? $name['desktop'] : 16;
			$name_m = isset($name['mobile']) ? $name['mobile'] : 14;

			// Bio font size
			$bio   = get_theme_mod('author_kit_bio_font_size_default', array());
			$bio_d = isset($bio['desktop']) ? $bio['desktop'] : 14;
			$bio_m = isset($bio['mobile']) ? $bio['mobile'] : 12;

			// Sub Info font size
			$sub_info   = get_theme_mod('author_kit_subinfo_font_size_default', array());
			$sub_info_d = isset($sub_info['desktop']) ? $sub_info['desktop'] : 13;
			$sub_info_m = isset($sub_info['mobile']) ? $sub_info['mobile'] : 12;

			// Avatar size
			$avatar   = get_theme_mod('author_kit_avatar_size_default', array());
			$avatar_d = isset($avatar['desktop']) ? $avatar['desktop'] : 120;
			$avatar_m = isset($avatar['mobile']) ? $avatar['mobile'] : 100;

			// Icons gap
			$icons_gap   = get_theme_mod('author_kit_icons_gap_default', array());
			$icons_gap_d = isset($icons_gap['desktop']) ? $icons_gap['desktop'] : 10;
			$icons_gap_m = isset($icons_gap['mobile']) ? $icons_gap['mobile'] : 8;

			// Icons size
			$icons_size   = get_theme_mod('author_kit_icons_size_default', array());
			$icons_size_d = isset($icons_size['desktop']) ? $icons_size['desktop'] : 30;
			$icons_size_m = isset($icons_size['mobile']) ? $icons_size['mobile'] : 24;

			// Initialize inner icon sizes with default safe values
			$icons_inner_size_d = $icons_size_d - 16; // Fallback value
			$icons_inner_size_m = $icons_size_m - 16; // Fallback value

			// Calculate inner icon size based on outer icon size
			// Desktop inner icon size calculation
			if ($icons_size_d > 40 && $icons_size_d <= 50) {
				$icons_inner_size_d = $icons_size_d - 26;
			} elseif ($icons_size_d > 30 && $icons_size_d <= 40) {
				$icons_inner_size_d = $icons_size_d - 16;
			} elseif ($icons_size_d <= 25) {
				$icons_inner_size_d = $icons_size_d - 10;
			}

			// Calculate inner icon size for mobile
			if ($icons_size_m >= 30 && $icons_size_m <= 43) {
				$icons_inner_size_m = $icons_size_m - 16;
			} elseif ($icons_size_m < 30) {
				$icons_inner_size_m = $icons_size_m - 14;
			} else {
				$icons_inner_size_m = $icons_size_m - 18;
			}

			$dimensions = get_theme_mod('author_kit_bio_box_size_default', array());

			// Set default width and height if not present
			$bio_box_width  = isset($dimensions['width']) ? $dimensions['width'] : '100%';
			$bio_box_height = isset($dimensions['height']) ? $dimensions['height'] : 'auto';

			$margins = get_theme_mod('author_kit_bio_box_margin_default', array());

			$margin_top    = isset($margins['margin-top']) ? $margins['margin-top'] : '50px';
			$margin_bottom = isset($margins['margin-bottom']) ? $margins['margin-bottom'] : '50px';

			$paddings = get_theme_mod('author_kit_bio_box_padding_default', array());

			// Retrieve desktop padding values with default values
			$desktop_padding_top    = isset($paddings['desktop']['top']) ? $paddings['desktop']['top'] : '35px';
			$desktop_padding_right  = isset($paddings['desktop']['right']) ? $paddings['desktop']['right'] : '25px';
			$desktop_padding_bottom = isset($paddings['desktop']['bottom']) ? $paddings['desktop']['bottom'] : '35px';
			$desktop_padding_left   = isset($paddings['desktop']['left']) ? $paddings['desktop']['left'] : '25px';

			// Retrieve mobile padding values with default values (set to 10px)
			$mobile_padding_top    = isset($paddings['mobile']['top']) ? $paddings['mobile']['top'] : '20px';
			$mobile_padding_right  = isset($paddings['mobile']['right']) ? $paddings['mobile']['right'] : '10px';
			$mobile_padding_bottom = isset($paddings['mobile']['bottom']) ? $paddings['mobile']['bottom'] : '10px';
			$mobile_padding_left   = isset($paddings['mobile']['left']) ? $paddings['mobile']['left'] : '10px';

			// Combine the Customizer settings into inline CSS
			$custom_css = "
/* --------------------------------------------------
Common Styles (Color, Background, Border, Base Layout)
-------------------------------------------------- */

#author-bio-container {
    margin-top: {$margin_top};
    margin-bottom: {$margin_bottom};
    box-sizing: border-box;
    border-style: solid;
    border-width: {$settings['border']};
    border-color: {$settings['border_color']};
    border-radius: {$settings['border_radius']};
    background-color: {$settings['background_color']};
    width: {$bio_box_width};
    height: {$bio_box_height};
}

#author-bio-container #about-author-heading {
    background-color: {$settings['heading_bg_color']};
    color: {$settings['heading_txt_color']};
}

/* --------------------------------------------------
Desktop Styles (min-width: 1024px)
-------------------------------------------------- */
@media (min-width: 1024px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_d}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_d}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_d}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_d}px;
    }

  #author-bio-container #author-kit-bio-box  .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_d}px;
        height: {$icons_size_d}px;
    }

  #author-bio-container #author-kit-bio-box  .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_d}px;
    }
}

/* --------------------------------------------------
Tablet Styles (min-width: 767px and max-width: 899px)
-------------------------------------------------- */
@media (min-width: 767px) and (max-width: 899px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }
}

/* --------------------------------------------------
Mobile Styles (max-width: 766px)
-------------------------------------------------- */
@media (max-width: 766px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$mobile_padding_top};
        padding-bottom: {$mobile_padding_bottom};
        padding-left: {$mobile_padding_left};
        padding-right: {$mobile_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_m}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_m}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_m}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_m}px;
    }

#author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_m}px;
        height: {$icons_size_m}px;
    }

 #author-bio-container #author-kit-bio-box  .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_m}px;
    }
}


";

			break;

		case 'template-memoir':
			// Fetch Customizer settings

			$settings = array(
				'border'            => get_theme_mod('author_kit_bio_box_border_thickness_memoir', '1px'),
				'border_radius'     => get_theme_mod('author_kit_bio_box_border_radius_memoir', '16px'),
				'border_color'      => get_theme_mod('author_kit_bio_box_border_color_memoir', '#1e73be'),
				'background_color'  => get_theme_mod('author_kit_bio_box_bg_color_memoir', '#fcfcfc'),
				'name_color'        => get_theme_mod('author_kit_name_txt_color_memoir', '#000000'),
				'email_color'       => get_theme_mod('author_kit_subinfo_txt_color_memoir', '#808080'),
				'description_color' => get_theme_mod('author_kit_bio_text_color_memoir', '#000000'),
				'heading_bg_color'  => get_theme_mod('author_kit_bio_box_heading_bg_color_memoir', '#36454F'),
				'heading_txt_color' => get_theme_mod('author_kit_bio_box_heading_txt_color_memoir', '#FFFFFF'),
			);

			// Name font size
			$name   = get_theme_mod('author_kit_name_font_size_memoir', array());
			$name_d = isset($name['desktop']) ? $name['desktop'] : 16;
			$name_m = isset($name['mobile']) ? $name['mobile'] : 14;

			// Bio font size
			$bio   = get_theme_mod('author_kit_bio_font_size_memoir', array());
			$bio_d = isset($bio['desktop']) ? $bio['desktop'] : 14;
			$bio_m = isset($bio['mobile']) ? $bio['mobile'] : 12;

			// Sub Info font size
			$sub_info   = get_theme_mod('author_kit_subinfo_font_size_memoir', array());
			$sub_info_d = isset($sub_info['desktop']) ? $sub_info['desktop'] : 13;
			$sub_info_m = isset($sub_info['mobile']) ? $sub_info['mobile'] : 12;

			// Avatar size
			$avatar   = get_theme_mod('author_kit_avatar_size_memoir', array());
			$avatar_d = isset($avatar['desktop']) ? $avatar['desktop'] : 120;
			$avatar_m = isset($avatar['mobile']) ? $avatar['mobile'] : 100;

			// Icons gap
			$icons_gap   = get_theme_mod('author_kit_icons_gap_memoir', array());
			$icons_gap_d = isset($icons_gap['desktop']) ? $icons_gap['desktop'] : 10;
			$icons_gap_m = isset($icons_gap['mobile']) ? $icons_gap['mobile'] : 8;

			// Get icon sizes from Customizer
			$icons_size   = get_theme_mod('author_kit_icons_size_memoir', array());
			$icons_size_d = isset($icons_size['desktop']) ? (int) $icons_size['desktop'] : 30;
			$icons_size_m = isset($icons_size['mobile']) ? (int) $icons_size['mobile'] : 24;

			// Initialize inner icon sizes with default safe values
			$icons_inner_size_d = $icons_size_d - 16; // Fallback value
			$icons_inner_size_m = $icons_size_m - 16; // Fallback value

			// Desktop inner icon size calculation
			if ($icons_size_d > 40 && $icons_size_d <= 50) {
				$icons_inner_size_d = $icons_size_d - 26;
			} elseif ($icons_size_d > 30 && $icons_size_d <= 40) {
				$icons_inner_size_d = $icons_size_d - 16;
			} elseif ($icons_size_d <= 30) {
				$icons_inner_size_d = $icons_size_d - 10;
			}

			// Mobile inner icon size calculation
			if ($icons_size_m >= 30 && $icons_size_m <= 43) {
				$icons_inner_size_m = $icons_size_m - 16;
			} elseif ($icons_size_m < 30) {
				$icons_inner_size_m = $icons_size_m - 14;
			} else {
				$icons_inner_size_m = $icons_size_m - 18;
			}

			$dimensions = get_theme_mod('author_kit_bio_box_size_memoir', array());

			// Set default width and height if not present
			$bio_box_width  = isset($dimensions['width']) ? $dimensions['width'] : '100%';
			$bio_box_height = isset($dimensions['height']) ? $dimensions['height'] : 'auto';

			$margins       = get_theme_mod('author_kit_bio_box_margin_memoir', array());
			$margin_top    = isset($margins['margin-top']) ? $margins['margin-top'] : '50px';
			$margin_bottom = isset($margins['margin-bottom']) ? $margins['margin-bottom'] : '50px';

			$paddings = get_theme_mod('author_kit_bio_box_padding_memoir', array());

			// Retrieve desktop padding values with default values
			$desktop_padding_top    = isset($paddings['desktop']['top']) ? $paddings['desktop']['top'] : '35px';
			$desktop_padding_right  = isset($paddings['desktop']['right']) ? $paddings['desktop']['right'] : '25px';
			$desktop_padding_bottom = isset($paddings['desktop']['bottom']) ? $paddings['desktop']['bottom'] : '35px';
			$desktop_padding_left   = isset($paddings['desktop']['left']) ? $paddings['desktop']['left'] : '25px';

			// Retrieve mobile padding values with default values (set to 10px)
			$mobile_padding_top    = isset($paddings['mobile']['top']) ? $paddings['mobile']['top'] : '20px';
			$mobile_padding_right  = isset($paddings['mobile']['right']) ? $paddings['mobile']['right'] : '10px';
			$mobile_padding_bottom = isset($paddings['mobile']['bottom']) ? $paddings['mobile']['bottom'] : '10px';
			$mobile_padding_left   = isset($paddings['mobile']['left']) ? $paddings['mobile']['left'] : '10px';

			// Combine the Customizer settings into inline CSS
			$custom_css = "
/* --------------------------------------------------
Common Styles (Color, Background, Border, Base Layout)
-------------------------------------------------- */

#author-bio-container {
    margin-top: {$margin_top};
    margin-bottom: {$margin_bottom};
    box-sizing: border-box;
    border-style: solid;
    border-width: {$settings['border']};
    border-color: {$settings['border_color']};
    border-radius: {$settings['border_radius']};
    background-color: {$settings['background_color']};
    width: {$bio_box_width};
    height: {$bio_box_height};
}

#author-bio-container #about-author-heading {
    background-color: {$settings['heading_bg_color']};
    color: {$settings['heading_txt_color']};
}

/* --------------------------------------------------
Desktop Styles (min-width: 1024px)
-------------------------------------------------- */
@media (min-width: 1024px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_d}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_d}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_d}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_d}px;
    }

  #author-bio-container #author-kit-bio-box  .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_d}px;
        height: {$icons_size_d}px;
    }

   #author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_d}px;
    }
}

/* --------------------------------------------------
Tablet Styles (min-width: 767px and max-width: 899px)
-------------------------------------------------- */
@media (min-width: 767px) and (max-width: 899px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }
}

/* --------------------------------------------------
Mobile Styles (max-width: 766px)
-------------------------------------------------- */
@media (max-width: 766px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$mobile_padding_top};
        padding-bottom: {$mobile_padding_bottom};
        padding-left: {$mobile_padding_left};
        padding-right: {$mobile_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_m}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_m}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_m}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_m}px;
    }

#author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_m}px;
        height: {$icons_size_m}px;
    }

   #author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_m}px;
    }
}


";

			break;

		case 'template-monarch':
			// Fetch Customizer settings with dark theme defaults
			$settings = array(
				'border'            => get_theme_mod('author_kit_bio_box_border_thickness_monarch', '1px'),
				'border_radius'     => get_theme_mod('author_kit_bio_box_border_radius_monarch', '8px'),
				'border_color'      => get_theme_mod('author_kit_bio_box_border_color_monarch', '#40534C'), // dark accent border
				'background_color'  => get_theme_mod('author_kit_bio_box_bg_color_monarch', '#1A3636'), // main background
				'name_color'        => get_theme_mod('author_kit_name_txt_color_monarch', '#FFFFFF'), // white text
				'email_color'       => get_theme_mod('author_kit_subinfo_txt_color_monarch', '#FFFFFF'),
				'description_color' => get_theme_mod('author_kit_bio_text_color_monarch', '#FFFFFF'),
				'heading_bg_color'  => get_theme_mod('author_kit_bio_box_heading_bg_color_monarch', '#D6BD98'), // highlight background
				'heading_txt_color' => get_theme_mod('author_kit_bio_box_heading_txt_color_monarch', '#40534C'), // white heading text
			);

			// Name font size
			$name   = get_theme_mod('author_kit_name_font_size_monarch', array());
			$name_d = isset($name['desktop']) ? $name['desktop'] : 16;
			$name_m = isset($name['mobile']) ? $name['mobile'] : 14;

			// Bio font size
			$bio   = get_theme_mod('author_kit_bio_font_size_monarch', array());
			$bio_d = isset($bio['desktop']) ? $bio['desktop'] : 14;
			$bio_m = isset($bio['mobile']) ? $bio['mobile'] : 12;

			// Sub Info font size
			$sub_info   = get_theme_mod('author_kit_subinfo_font_size_monarch', array());
			$sub_info_d = isset($sub_info['desktop']) ? $sub_info['desktop'] : 13;
			$sub_info_m = isset($sub_info['mobile']) ? $sub_info['mobile'] : 12;

			// Avatar size
			$avatar   = get_theme_mod('author_kit_avatar_size_monarch', array());
			$avatar_d = isset($avatar['desktop']) ? $avatar['desktop'] : 120;
			$avatar_m = isset($avatar['mobile']) ? $avatar['mobile'] : 100;

			// Icons gap
			$icons_gap   = get_theme_mod('author_kit_icons_gap_monarch', array());
			$icons_gap_d = isset($icons_gap['desktop']) ? $icons_gap['desktop'] : 10;
			$icons_gap_m = isset($icons_gap['mobile']) ? $icons_gap['mobile'] : 8;

			// Get icon sizes from Customizer
			$icons_size   = get_theme_mod('author_kit_icons_size_monarch', array());
			$icons_size_d = isset($icons_size['desktop']) ? (int) $icons_size['desktop'] : 30;
			$icons_size_m = isset($icons_size['mobile']) ? (int) $icons_size['mobile'] : 24;

			// Initialize inner icon sizes with default safe values
			$icons_inner_size_d = $icons_size_d - 16; // Fallback value
			$icons_inner_size_m = $icons_size_m - 16; // Fallback value

			// Desktop inner icon size calculation
			if ($icons_size_d > 40 && $icons_size_d <= 50) {
				$icons_inner_size_d = $icons_size_d - 26;
			} elseif ($icons_size_d > 30 && $icons_size_d <= 40) {
				$icons_inner_size_d = $icons_size_d - 16;
			} elseif ($icons_size_d <= 30) {
				$icons_inner_size_d = $icons_size_d - 10;
			}

			// Mobile inner icon size calculation
			if ($icons_size_m >= 30 && $icons_size_m <= 43) {
				$icons_inner_size_m = $icons_size_m - 16;
			} elseif ($icons_size_m < 30) {
				$icons_inner_size_m = $icons_size_m - 14;
			} else {
				$icons_inner_size_m = $icons_size_m - 18;
			}

			$dimensions = get_theme_mod('author_kit_bio_box_size_monarch', array());

			// Set default width and height if not present
			$bio_box_width  = isset($dimensions['width']) ? $dimensions['width'] : '100%';
			$bio_box_height = isset($dimensions['height']) ? $dimensions['height'] : 'auto';

			$margins = get_theme_mod('author_kit_bio_box_margin_monarch', array());

			$margin_top    = isset($margins['margin-top']) ? $margins['margin-top'] : '50px';
			$margin_bottom = isset($margins['margin-bottom']) ? $margins['margin-bottom'] : '50px';

			$paddings = get_theme_mod('author_kit_bio_box_padding_monarch', array());

			// Retrieve desktop padding values with default values
			$desktop_padding_top    = isset($paddings['desktop']['top']) ? $paddings['desktop']['top'] : '35px';
			$desktop_padding_right  = isset($paddings['desktop']['right']) ? $paddings['desktop']['right'] : '25px';
			$desktop_padding_bottom = isset($paddings['desktop']['bottom']) ? $paddings['desktop']['bottom'] : '35px';
			$desktop_padding_left   = isset($paddings['desktop']['left']) ? $paddings['desktop']['left'] : '25px';

			// Retrieve mobile padding values with default values (set to 10px)
			$mobile_padding_top    = isset($paddings['mobile']['top']) ? $paddings['mobile']['top'] : '20px';
			$mobile_padding_right  = isset($paddings['mobile']['right']) ? $paddings['mobile']['right'] : '10px';
			$mobile_padding_bottom = isset($paddings['mobile']['bottom']) ? $paddings['mobile']['bottom'] : '10px';
			$mobile_padding_left   = isset($paddings['mobile']['left']) ? $paddings['mobile']['left'] : '10px';

			// Combine the Customizer settings into inline CSS
			$custom_css = "
/* --------------------------------------------------
Common Styles (Color, Background, Border, Base Layout)
-------------------------------------------------- */

#author-bio-container {
    margin-top: {$margin_top};
    margin-bottom: {$margin_bottom};
    box-sizing: border-box;
    border-style: solid;
    border-width: {$settings['border']};
    border-color: {$settings['border_color']};
    border-radius: {$settings['border_radius']};
    background-color: {$settings['background_color']};
    width: {$bio_box_width};
    height: {$bio_box_height};
}

#author-bio-container #about-author-heading {
    background-color: {$settings['heading_bg_color']};
    color: {$settings['heading_txt_color']};
}

/* --------------------------------------------------
Desktop Styles (min-width: 1024px)
-------------------------------------------------- */
@media (min-width: 1024px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_d}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_d}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_d}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_d}px;
    }

 #author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_d}px;
        height: {$icons_size_d}px;
    }

   #author-bio-container #author-kit-bio-box .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_d}px;
    }
}

/* --------------------------------------------------
Tablet Styles (min-width: 767px and max-width: 899px)
-------------------------------------------------- */
@media (min-width: 767px) and (max-width: 899px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$desktop_padding_top};
        padding-bottom: {$desktop_padding_bottom};
        padding-left: {$desktop_padding_left};
        padding-right: {$desktop_padding_right};
    }
}

/* --------------------------------------------------
Mobile Styles (max-width: 766px)
-------------------------------------------------- */
@media (max-width: 766px) {
    #author-bio-container #author-kit-bio-box {
        padding-top: {$mobile_padding_top};
        padding-bottom: {$mobile_padding_bottom};
        padding-left: {$mobile_padding_left};
        padding-right: {$mobile_padding_right};
    }

    #author-bio-container #author-name {
        color: {$settings['name_color']};
        font-size: {$name_m}px;
    }

    #author-bio-container #author-info-placeholder {
        color: {$settings['email_color']};
        font-size: {$sub_info_m}px;
    }

    #author-bio-container #author-bio-text {
        color: {$settings['description_color']};
        font-size: {$bio_m}px;
    }

    #author-bio-container #author-kit-bio-box div #author-avatar-container {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

   #author-bio-container #author-kit-bio-box  div.author-kit-social-icons-list {
        gap: {$icons_gap_m}px;
    }

 #author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a.author-kit-social-icon {
        width: {$icons_size_m}px;
        height: {$icons_size_m}px;
    }

   #author-bio-container #author-kit-bio-box   .author-kit-social-icons-list a i {
        font-size: {$icons_inner_size_m}px;
    }
}

";
			break;

		default:
			return '';
	}

	// Store generated CSS in cache for 1 month
	set_transient($cache_key, $custom_css, MONTH_IN_SECONDS);

	return  $custom_css;
}





/**
 * Enqueues necessary stylesheets for the author bio box based on the active template.
 *
 * This function ensures styles are only loaded on single posts and pages,
 * but NOT on the author archive.
 *
 * @param string $template_name The active author bio box template name.
 */

/**
 * Enqueues necessary stylesheets for the author bio box based on the active template.
 *
 * This function ensures styles are only loaded on single posts and pages,
 * but NOT on the author archive.
 *
 * @param string $template_name The active author bio box template name.
 */
function author_kit_enqueue_bio_box_styles($template_name)
{
	// Load only on single posts and pages, but NOT on the author archive
	if ((! is_single() && ! is_page()) || is_author()) {
		return;
	}

	// Define the base plugin URL
	$base_url = AUTHOR_KIT_PLUGIN_URL . 'public/templates/author-bio-box/asset/css/';
	$handle   = "author-kit-$template_name";

	// Enqueue styles based on template name
	switch ($template_name) {
		case 'template-default':
		case 'template-memoir':
		case 'template-monarch':
			wp_enqueue_style($handle, $base_url . 'template-default.css', array(), AUTHOR_KIT_VERSION, 'all');
			break;
	}

	// Enqueue a common RTL stylesheet if RTL is enabled
	if (is_rtl()) {
		wp_enqueue_style('author-kit-bio-box-rtl', $base_url . 'template-default-rtl.css', array(), AUTHOR_KIT_VERSION, 'all');
	}
}


/**
 * Loads the inline styles for the active author bio box template.
 *
 * Retrieves the active template from the database and enqueues its stylesheet.
 * Additionally, generates and applies custom inline CSS.
 */
function author_kit_load_bio_box_inline_styles()
{
	// Get the active author bio box template
	$active_template = get_option('author_kit_author_bio_template', 'template-default');

	// Enqueue styles for the active template
	author_kit_enqueue_bio_box_styles($active_template);

	// Generate custom inline CSS and add it to the enqueued stylesheet
	$custom_css = author_kit_generate_bio_box_inline_css();
	if (! empty($custom_css)) {

		// Escaping custom inline CSS with wp_kses to prevent XSS.
		// CSS is user-defined via Kirki controls and sanitized before being stored.
		// We escape again here (late) to ensure secure rendering.	
		wp_add_inline_style("author-kit-$active_template",  wp_kses($custom_css, array('style' => array('type' => true))));
	}
}

// Hook into 'wp_enqueue_scripts' to load styles and inline CSS for the active template
add_action('wp_enqueue_scripts', 'author_kit_load_bio_box_inline_styles', 999);
