<?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_archive_inline_css()
{
    $active_template = get_option('author_kit_author_archive_template', 'arhive-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 'archive-template-default':
            $settings = array(

                'bio_box_bg_color'           => get_theme_mod('author_kit_archive_bio_box_bg_color', '#F8F8FF'),
                'name_color'                 => get_theme_mod('author_kit_archive_name_color', '#334155'),
                'job_title_color'            => get_theme_mod('author_kit_archive_job_title_color', '#5a5a5a'),
                'description_color'          => get_theme_mod('author_kit_archive_description_color', '#5a5a5a'),
                'social_icon_color'          => get_theme_mod('author_kit_archive_social_icon_color', '#5f5f5f'),

                'post_grid_title_color'      => get_theme_mod('author_kit_archive_post_grid_title_color', '#22'),

                'archive_thumbnail_radius'   => get_theme_mod('author_kit_archive_thumbnail_border_radius', 8),

                'grid_bg_color'              => get_theme_mod('author_kit_archive_post_grid_bg_color', '#fff'),
                'archive_grid_gap'           => get_theme_mod('author_kit_archive_grid_gap', 10),
                'archive_posts_per_row'      => get_theme_mod('author_kit_archive_posts_per_row', 3),
                'archive_post_card_bg_color' => get_theme_mod('author_kit_archive_post_card_bg_color', '#FFFFFF'),

                'archive_title_color'        => get_theme_mod('author_kit_archive_title_color', '#222222'),
                'archive_excerpt_color'      => get_theme_mod('author_kit_archive_excerpt_color', '#555555'),
                'archive_post_meta_color'    => get_theme_mod('author_kit_archive_post_meta_color', '#666666'),
                'meta_separator_color'       => get_theme_mod('author_kit_archive_post_meta_separator_color', '#eee'),
                'grid_title_alignment'       => get_theme_mod('author_kit_archive_grid_text_alignment', 'left'),

                'pagination_alignment'       => get_theme_mod('author_kit_archive_pagination_alignment', 'center'),
                'button_color'               => get_theme_mod('author_kit_archive_button_color', '#0073e6'),
                'button_hover_color'         => get_theme_mod('author_kit_archive_button_hover_color', '#005bb5'),
                'button_color_txt'           => get_theme_mod('author_kit_archive_pagination_btn_color', '#ffffff'),
                'numbers_color'              => get_theme_mod('author_kit_archive_pagination_number_color', '#000000'),
                'numbers_bg_color'           => get_theme_mod('author_kit_archive_pagination_number_bg_color', '#FFFFFF'),

            );

            // Get padding settings for bio box
            $bio_padding        = get_theme_mod('author_kit_archive_bio_box_padding', []);
            $bio_padding_top    = isset($bio_padding['desktop']['top']) ? $bio_padding['desktop']['top'] : '80px';
            $bio_padding_right  = isset($bio_padding['desktop']['right']) ? $bio_padding['desktop']['right'] : '120px';
            $bio_padding_bottom = isset($bio_padding['desktop']['bottom']) ? $bio_padding['desktop']['bottom'] : '80px';
            $bio_padding_left   = isset($bio_padding['desktop']['left']) ? $bio_padding['desktop']['left'] : '120px';

            $bio_padding_top_mobile    = isset($bio_padding['mobile']['top']) ? $bio_padding['mobile']['top'] : '30px';
            $bio_padding_right_mobile  = isset($bio_padding['mobile']['right']) ? $bio_padding['mobile']['right'] : '20px';
            $bio_padding_bottom_mobile = isset($bio_padding['mobile']['bottom']) ? $bio_padding['mobile']['bottom'] : '30px';
            $bio_padding_left_mobile   = isset($bio_padding['mobile']['left']) ? $bio_padding['mobile']['left'] : '20px';

            // Get padding settings for post grid container
            $post_grid_padding        = get_theme_mod('author_kit_post_grid_padding', []);
            $post_grid_padding_top    = isset($post_grid_padding['desktop']['top']) ? $post_grid_padding['desktop']['top'] : '20px';
            $post_grid_padding_right  = isset($post_grid_padding['desktop']['right']) ? $post_grid_padding['desktop']['right'] : '120px';
            $post_grid_padding_bottom = isset($post_grid_padding['desktop']['bottom']) ? $post_grid_padding['desktop']['bottom'] : '40px';
            $post_grid_padding_left   = isset($post_grid_padding['desktop']['left']) ? $post_grid_padding['desktop']['left'] : '120px';

            $post_grid_padding_top_mobile    = isset($post_grid_padding['mobile']['top']) ? $post_grid_padding['mobile']['top'] : '10px';
            $post_grid_padding_right_mobile  = isset($post_grid_padding['mobile']['right']) ? $post_grid_padding['mobile']['right'] : '10px';
            $post_grid_padding_bottom_mobile = isset($post_grid_padding['mobile']['bottom']) ? $post_grid_padding['mobile']['bottom'] : '40px';
            $post_grid_padding_left_mobile   = isset($post_grid_padding['mobile']['left']) ? $post_grid_padding['mobile']['left'] : '10px';
            // Name size
            $name   = get_theme_mod('author_kit_archive_name_size', []);
            $name_d = isset($name['desktop']) ? $name['desktop'] : 28;
            $name_m = isset($name['mobile']) ? $name['mobile'] : 20;

            // Job title size
            $title   = get_theme_mod('author_kit_archive_job_title_size', []);
            $title_d = isset($title['desktop']) ? $title['desktop'] : 13;
            $title_m = isset($title['mobile']) ? $title['mobile'] : 12;

            // Description size
            $desc   = get_theme_mod('author_kit_archive_description_size', []);
            $desc_d = isset($desc['desktop']) ? $desc['desktop'] : 14;
            $desc_m = isset($desc['mobile']) ? $desc['mobile'] : 13;

            // Post Grid title size
            $post_archive_title   = get_theme_mod('author_kit_grid_archive_title', []);
            $post_archive_title_d = isset($post_archive_title['desktop']) ? $post_archive_title['desktop'] : 18;
            $post_archive_title_m = isset($post_archive_title['mobile']) ? $post_archive_title['mobile'] : 16;

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

            // Post title size
            $post_title   = get_theme_mod('author_kit_archive_post_title_size', []);
            $post_title_d = isset($post_title['desktop']) ? $post_title['desktop'] : 18;
            $post_title_m = isset($post_title['mobile']) ? $post_title['mobile'] : 16;

            // Excerpt size
            $excerpt   = get_theme_mod('author_kit_archive_excerpt_size', []);
            $excerpt_d = isset($excerpt['desktop']) ? $excerpt['desktop'] : 14;
            $excerpt_m = isset($excerpt['mobile']) ? $excerpt['mobile'] : 13;

            // Meta size
            $meta   = get_theme_mod('author_kit_archive_post_meta_size', []);
            $meta_d = isset($meta['desktop']) ? $meta['desktop'] : 12;
            $meta_m = isset($meta['mobile']) ? $meta['mobile'] : 11;

            // Thumbnail radius
            $thumb   = get_theme_mod('author_kit_archive_thumbnail_border_radius', []);
            $thumb_d = isset($thumb['desktop']) ? $thumb['desktop'] : 8;
            $thumb_m = isset($thumb['mobile']) ? $thumb['mobile'] : 6;

            // Social icon gap
            $icon_gap   = get_theme_mod('author_kit_archive_social_icons_gap', []);
            $icon_gap_d = isset($icon_gap['desktop']) ? $icon_gap['desktop'] : 10;
            $icon_gap_m = isset($icon_gap['mobile']) ? $icon_gap['mobile'] : 8;

            // Social icon size
            $icon   = get_theme_mod('author_kit_archive_social_icons_size', []);
            $icon_d = isset($icon['desktop']) ? $icon['desktop'] : 40;
            $icon_m = isset($icon['mobile']) ? $icon['mobile'] : 32;

            // Inner icon size
            $icon_inner_d = ($icon_d > 43) ? $icon_d - 18 : $icon_d - 16;
            $icon_inner_m = ($icon_m > 43) ? $icon_m - 18 : $icon_m - 14;

            $custom_css .= "
            
/* ================= MOBILE STYLES ================= */
@media (max-width: 899px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top_mobile} {$bio_padding_right_mobile} {$bio_padding_bottom_mobile} {$bio_padding_left_mobile};
    }

    #author-kit-archive-template .author-kit-posts {
        padding: {$post_grid_padding_top_mobile} {$post_grid_padding_right_mobile} {$post_grid_padding_bottom_mobile} {$post_grid_padding_left_mobile};
    }
       .author-kit-pagination-container  {
     
        padding-left:  {$post_grid_padding_left_mobile};
         padding-right:  {$post_grid_padding_right_mobile};
    }    

 #author-kit-archive-template .author-kit-posts-title{
      font-size: {$post_archive_title_m}px; 
 }
    .author-kit-avatar {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

    .author-kit-name {
        font-size: {$name_m}px;
    }

    .author-kit-job-title {
        font-size: {$title_m}px;
    }

    .author-kit-description {
        font-size: {$desc_m}px;
    }

    #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_m}px;
    }

    .author-kit-post-title {
        font-size: {$post_title_m}px;
    }

    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_m}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_m}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_m}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_m}px;
    }
}

/* ================= DESKTOP STYLES ================= */
@media (min-width: 900px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top} {$bio_padding_right} {$bio_padding_bottom} {$bio_padding_left};
    }

   #author-kit-archive-template  .author-kit-posts {
        padding: {$post_grid_padding_top} {$post_grid_padding_right} {$post_grid_padding_bottom} {$post_grid_padding_left};
    }
     .author-kit-pagination-container  {
     
        padding-left:  {$post_grid_padding_left};
         padding-right:  {$post_grid_padding_right};
    } 
}



@media (min-width: 1080px) {
    .author-kit-posts-grid {
        display: grid;
        gap: {$settings['archive_grid_gap']}px;
    } 

     #author-kit-archive-template .author-kit-posts-title{
      font-size: {$post_archive_title_d}px; 
 }

    .author-kit-post-title , #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_d}px;
    }
}

/* ============ COMMON STYLES (Mobile First) ============ */
#author-kit-archive-template .author-kit-bio-container {
    background-color: {$settings['bio_box_bg_color']};
}

.author-kit-post-title,
#author-kit-archive-template h4.author-kit-post-title a {
    color: {$settings['archive_title_color']};
}

.author-kit-name {
    color: {$settings['name_color']};
}

.author-kit-job-title {
    color: {$settings['job_title_color']};
}

.author-kit-description {
    color: {$settings['description_color']};
}

#author-kit-archive-template .author-kit-posts-title {
    justify-content: {$settings['grid_title_alignment']};
}

#author-kit-archive-template .author-kit-posts {
    background-color: {$settings['grid_bg_color']};
}

#author-kit-archive-template .author-kit-posts-title h3 {
    color: {$settings['post_grid_title_color']};
}

.author-kit-pagination-page {
    color: {$settings['numbers_color']};
    background-color: {$settings['numbers_bg_color']};
}

.author-kit-post-item {
    background-color: {$settings['archive_post_card_bg_color']};
}

.author-kit-post-item a img {
    border-radius: {$settings['archive_thumbnail_radius']}px;
}

.author-kit-post-item div.author-kit-post-excerpt {
    color: {$settings['archive_excerpt_color']};
}

.author-kit-post-meta {
    color: {$settings['archive_post_meta_color']};
    border-color: {$settings['meta_separator_color']};
}

.author-kit-post-meta .author-name,
.author-kit-post-meta .post-date {
    color: {$settings['archive_post_meta_color']};
}

#author-kit-archive-template .author-kit-pagination-container {
    justify-content: {$settings['pagination_alignment']};
    background-color: {$settings['grid_bg_color']};
}

.author-kit-pagination-prev,
.author-kit-pagination-next {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container .current .author-kit-pagination-page {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container a:hover .author-kit-pagination-page,
.author-kit-pagination-prev:hover,
.author-kit-pagination-next:hover {
    background: {$settings['button_hover_color']};
    color: {$settings['button_color_txt']};
}
/* ============ DESKTOP STYLES (min-width: 899px) ============ */
@media (min-width: 899px) {
    .author-kit-name {
        font-size: {$name_d}px;
    }

    .author-kit-job-title {
        font-size: {$title_d}px;
    }

    .author-kit-description {
        font-size: {$desc_d}px;
    }

    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_d}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_d}px;
    }

    .author-kit-avatar {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_d}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_d}px;
    }
}


";

            break;

        case 'archive-template-scribe':
            $settings = array(

                // Bio section
                'bio_box_bg_color'           => get_theme_mod('author_kit_archive_bio_box_bg_color_scribe', '#28283c'),
                'name_color'                 => get_theme_mod('author_kit_archive_name_color_scribe', '#ffffff'),
                'job_title_color'            => get_theme_mod('author_kit_archive_job_title_color_scribe', '#dfdfdf'),
                'description_color'          => get_theme_mod('author_kit_archive_description_color_scribe', '#f8f8f8'),
                'social_icon_color'          => get_theme_mod('author_kit_archive_social_icon_color_scribe', '#5f5f5f'),

                // Post grid
                'post_grid_title_color'      => get_theme_mod('author_kit_archive_post_grid_title_color_scribe', '#c2c2c2'),

                'archive_thumbnail_radius'   => get_theme_mod('author_kit_archive_thumbnail_border_radius_scribe', 8),
                'grid_bg_color'              => get_theme_mod('author_kit_archive_post_grid_bg_color_scribe', '#3c3c50'),
                'archive_grid_gap'           => get_theme_mod('author_kit_archive_grid_gap_scribe', 10),
                'archive_posts_per_row'      => get_theme_mod('author_kit_archive_posts_per_row_scribe', 3),
                'archive_post_card_bg_color' => get_theme_mod('author_kit_archive_post_card_bg_color_scribe', '#28283c'),

                // Post card content
                'archive_title_color'        => get_theme_mod('author_kit_archive_title_color_scribe', '#f5f5f5'),
                'archive_excerpt_color'      => get_theme_mod('author_kit_archive_excerpt_color_scribe', '#b8b8b8'),
                'archive_post_meta_color'    => get_theme_mod('author_kit_archive_post_meta_color_scribe', '#929292'),
                'meta_separator_color'       => get_theme_mod('author_kit_archive_post_meta_separator_color_scribe', '#3c3c50'),
                'grid_title_alignment'       => get_theme_mod('author_kit_archive_grid_text_alignment_scribe', 'center'),

                // Pagination
                'pagination_alignment'       => get_theme_mod('author_kit_archive_pagination_alignment_scribe', 'center'),
                'button_color'               => get_theme_mod('author_kit_archive_button_color_scribe', '#28283c'),
                'button_hover_color'         => get_theme_mod('author_kit_archive_button_hover_color_scribe', '#3c3c50'),
                'button_color_txt'           => get_theme_mod('author_kit_archive_pagination_btn_color_scribe', '#ffffff'),
                'numbers_color'              => get_theme_mod('author_kit_archive_pagination_number_color_scribe', '#000000'),
                'numbers_bg_color'           => get_theme_mod('author_kit_archive_pagination_number_color_bg_scribe', '#FFFFFF'),

            );

            // Get padding settings for bio box
            $bio_padding        = get_theme_mod('author_kit_archive_bio_box_padding_scribe', []);
            $bio_padding_top    = isset($bio_padding['desktop']['top']) ? $bio_padding['desktop']['top'] : '80px';
            $bio_padding_right  = isset($bio_padding['desktop']['right']) ? $bio_padding['desktop']['right'] : '120px';
            $bio_padding_bottom = isset($bio_padding['desktop']['bottom']) ? $bio_padding['desktop']['bottom'] : '80px';
            $bio_padding_left   = isset($bio_padding['desktop']['left']) ? $bio_padding['desktop']['left'] : '120px';

            $bio_padding_top_mobile    = isset($bio_padding['mobile']['top']) ? $bio_padding['mobile']['top'] : '30px';
            $bio_padding_right_mobile  = isset($bio_padding['mobile']['right']) ? $bio_padding['mobile']['right'] : '20px';
            $bio_padding_bottom_mobile = isset($bio_padding['mobile']['bottom']) ? $bio_padding['mobile']['bottom'] : '30px';
            $bio_padding_left_mobile   = isset($bio_padding['mobile']['left']) ? $bio_padding['mobile']['left'] : '20px';

            // Get padding settings for post grid container
            $post_grid_padding        = get_theme_mod('author_kit_post_grid_padding_scribe', []);
            $post_grid_padding_top    = isset($post_grid_padding['desktop']['top']) ? $post_grid_padding['desktop']['top'] : '20px';
            $post_grid_padding_right  = isset($post_grid_padding['desktop']['right']) ? $post_grid_padding['desktop']['right'] : '120px';
            $post_grid_padding_bottom = isset($post_grid_padding['desktop']['bottom']) ? $post_grid_padding['desktop']['bottom'] : '40px';
            $post_grid_padding_left   = isset($post_grid_padding['desktop']['left']) ? $post_grid_padding['desktop']['left'] : '120px';

            $post_grid_padding_top_mobile    = isset($post_grid_padding['mobile']['top']) ? $post_grid_padding['mobile']['top'] : '10px';
            $post_grid_padding_right_mobile  = isset($post_grid_padding['mobile']['right']) ? $post_grid_padding['mobile']['right'] : '10px';
            $post_grid_padding_bottom_mobile = isset($post_grid_padding['mobile']['bottom']) ? $post_grid_padding['mobile']['bottom'] : '40px';
            $post_grid_padding_left_mobile   = isset($post_grid_padding['mobile']['left']) ? $post_grid_padding['mobile']['left'] : '10px';
            // Name size
            $name   = get_theme_mod('author_kit_archive_name_size_scribe', []);
            $name_d = isset($name['desktop']) ? $name['desktop'] : 28;
            $name_m = isset($name['mobile']) ? $name['mobile'] : 20;

            // Job title size
            $title   = get_theme_mod('author_kit_archive_job_title_size_scribe', []);
            $title_d = isset($title['desktop']) ? $title['desktop'] : 13;
            $title_m = isset($title['mobile']) ? $title['mobile'] : 12;

            // Description size
            $desc   = get_theme_mod('author_kit_archive_description_size_scribe', []);
            $desc_d = isset($desc['desktop']) ? $desc['desktop'] : 14;
            $desc_m = isset($desc['mobile']) ? $desc['mobile'] : 13;

            // Post title size
            $post_title   = get_theme_mod('author_kit_archive_post_title_size_scribe', []);
            $post_title_d = isset($post_title['desktop']) ? $post_title['desktop'] : 18;
            $post_title_m = isset($post_title['mobile']) ? $post_title['mobile'] : 16;

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

            // Archive title size
            $archive_title   = get_theme_mod('author_kit_archive_post_grid_title_size_scribe', []);
            $archive_title_d = isset($archive_title['desktop']) ? $archive_title['desktop'] : 18;
            $archive_title_m = isset($archive_title['mobile']) ? $archive_title['mobile'] : 16;

            // Excerpt size
            $excerpt   = get_theme_mod('author_kit_archive_excerpt_size_scribe', []);
            $excerpt_d = isset($excerpt['desktop']) ? $excerpt['desktop'] : 14;
            $excerpt_m = isset($excerpt['mobile']) ? $excerpt['mobile'] : 13;

            // Meta size
            $meta   = get_theme_mod('author_kit_archive_post_meta_size_scribe', []);
            $meta_d = isset($meta['desktop']) ? $meta['desktop'] : 12;
            $meta_m = isset($meta['mobile']) ? $meta['mobile'] : 11;

            // Thumbnail radius
            $thumb   = get_theme_mod('author_kit_archive_thumbnail_border_radius_scribe', []);
            $thumb_d = isset($thumb['desktop']) ? $thumb['desktop'] : 8;
            $thumb_m = isset($thumb['mobile']) ? $thumb['mobile'] : 6;

            // Social icon gap
            $icon_gap   = get_theme_mod('author_kit_archive_social_icons_gap_scribe', []);
            $icon_gap_d = isset($icon_gap['desktop']) ? $icon_gap['desktop'] : 10;
            $icon_gap_m = isset($icon_gap['mobile']) ? $icon_gap['mobile'] : 8;

            // Social icon size
            $icon   = get_theme_mod('author_kit_archive_social_icons_size_scribe', []);
            $icon_d = isset($icon['desktop']) ? $icon['desktop'] : 40;
            $icon_m = isset($icon['mobile']) ? $icon['mobile'] : 32;

            // Inner icon size
            $icon_inner_d = ($icon_d > 43) ? $icon_d - 18 : $icon_d - 16;
            $icon_inner_m = ($icon_m > 43) ? $icon_m - 18 : $icon_m - 14;

            $custom_css .= "
 /* ================= MOBILE STYLES ================= */
@media (max-width: 899px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top_mobile} {$bio_padding_right_mobile} {$bio_padding_bottom_mobile} {$bio_padding_left_mobile};
    }

    #author-kit-archive-template .author-kit-posts {
        padding: {$post_grid_padding_top_mobile} {$post_grid_padding_right_mobile} {$post_grid_padding_bottom_mobile} {$post_grid_padding_left_mobile};
    }
      #author-kit-archive-template .author-kit-pagination-container  {
     
        padding-left:  {$post_grid_padding_left_mobile};
         padding-right:  {$post_grid_padding_right_mobile};
    }     
  
        

    .author-kit-avatar {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

    .author-kit-name {
        font-size: {$name_m}px;
    }

    .author-kit-job-title {
        font-size: {$title_m}px;
    }

    .author-kit-description {
        font-size: {$desc_m}px;
    }

     #author-kit-archive-template .author-kit-posts-title{
      font-size: {$archive_title_m}px; 
     }


     #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_m}px;
    }


    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_m}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_m}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_m}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_m}px;
    }
}

/* ================= DESKTOP STYLES ================= */
@media (min-width: 900px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top} {$bio_padding_right} {$bio_padding_bottom} {$bio_padding_left};
    }


  #author-kit-archive-template   .author-kit-posts {
        padding: {$post_grid_padding_top} {$post_grid_padding_right} {$post_grid_padding_bottom} {$post_grid_padding_left};
    }
    #author-kit-archive-template .author-kit-pagination-container  {
     
        padding-left:  {$post_grid_padding_left};
         padding-right:  {$post_grid_padding_right};
    }     

}

@media (min-width: 1080px) {
    .author-kit-posts-grid {
        display: grid;
        gap: {$settings['archive_grid_gap']}px;
    }

       #author-kit-archive-template .author-kit-posts-title{
      font-size: {$archive_title_d}px; 
 }

  .author-kit-post-title , #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_d}px;
    }

}

/* ================= COMMON STYLES ================= */

#author-kit-archive-template .author-kit-bio-container {
    background-color: {$settings['bio_box_bg_color']};
}

.author-kit-post-title,
#author-kit-archive-template h4.author-kit-post-title a {
    color: {$settings['archive_title_color']};
}

.author-kit-name {
    color: {$settings['name_color']};
}

.author-kit-job-title {
    color: {$settings['job_title_color']};
}

.author-kit-description {
    color: {$settings['description_color']};
}

#author-kit-archive-template .author-kit-posts-title {
    justify-content: {$settings['grid_title_alignment']};
}

#author-kit-archive-template .author-kit-posts {
    background-color: {$settings['grid_bg_color']};
}

#author-kit-archive-template .author-kit-posts-title h3 {
    color: {$settings['post_grid_title_color']};
}

.author-kit-pagination-page {
    color: {$settings['numbers_color']};
    background-color: {$settings['numbers_bg_color']};
}

.author-kit-post-item {
    background-color: {$settings['archive_post_card_bg_color']};
}

.author-kit-post-item a img {
    border-radius: {$settings['archive_thumbnail_radius']}px;
}

.author-kit-post-item div.author-kit-post-excerpt {
    color: {$settings['archive_excerpt_color']};
}

.author-kit-post-meta {
    color: {$settings['archive_post_meta_color']};
    border-color: {$settings['meta_separator_color']};
}

.author-kit-post-meta .author-name,
.author-kit-post-meta .post-date {
    color: {$settings['archive_post_meta_color']};
}

#author-kit-archive-template .author-kit-pagination-container {
    justify-content: {$settings['pagination_alignment']};
    background-color: {$settings['grid_bg_color']};
}

.author-kit-pagination-prev,
.author-kit-pagination-next {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container .current .author-kit-pagination-page {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container a:hover .author-kit-pagination-page,
.author-kit-pagination-prev:hover,
.author-kit-pagination-next:hover {
    background: {$settings['button_hover_color']};
    color: {$settings['button_color_txt']};
}
/* ============ DESKTOP STYLES (min-width: 899px) ============ */
@media (min-width: 899px) {
    .author-kit-name {
        font-size: {$name_d}px;
    }

    .author-kit-job-title {
        font-size: {$title_d}px;
    }

    .author-kit-description {
        font-size: {$desc_d}px;
    }

    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_d}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_d}px;
    }

    .author-kit-avatar {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_d}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_d}px;
    }
}

";

            break;

        case 'archive-template-quill':
            $settings = array(

                // Bio section
                'bio_box_bg_color'           => get_theme_mod('author_kit_archive_bio_box_bg_color_quill', '#fdfbee'), // From .author-kit-bio-container
                'name_color'                 => get_theme_mod('author_kit_archive_name_color_quill', '#015551'),       // From .author-kit-name
                'job_title_color'            => get_theme_mod('author_kit_archive_job_title_color_quill', '#015551'),  // From .author-kit-job-title
                'description_color'          => get_theme_mod('author_kit_archive_description_color_quill', '#015551'), // From .author-kit-description
                'social_icon_color'          => get_theme_mod('author_kit_archive_social_icon_color_quill', '#015551'), // Matches icon/text color

                // Post grid
                'post_grid_title_color'      => get_theme_mod('author_kit_archive_post_grid_title_color_quill', '#015551'), // From .author-kit-posts-title h3
                'archive_thumbnail_radius'   => get_theme_mod('author_kit_archive_thumbnail_border_radius_quill', 37),       // From .author-kit-post-item img
                'grid_bg_color'              => get_theme_mod('author_kit_archive_post_grid_bg_color_quill', '#fdfbee'),     // From .author-kit-posts
                'archive_grid_gap'           => get_theme_mod('author_kit_archive_grid_gap_quill', 38),                      // From .author-kit-posts-grid gap
                'archive_posts_per_row'      => get_theme_mod('author_kit_archive_posts_per_row_quill', 3),
                'archive_post_card_bg_color' => get_theme_mod('author_kit_archive_post_card_bg_color_quill', '#ffffff'),   // From .author-kit-post-item

                // Post card content
                'archive_title_color'        => get_theme_mod('author_kit_archive_title_color_quill', '#015551'), // From .author-kit-post-title
                'archive_excerpt_color'      => get_theme_mod('author_kit_archive_excerpt_color_quill', '#015551'), // From .author-kit-post-excerpt
                'archive_post_meta_color'    => get_theme_mod('author_kit_archive_post_meta_color_quill', '#015551'), // From .author-kit-post-meta
                'meta_separator_color'       => get_theme_mod('author_kit_archive_post_meta_separator_color_quill', '#015551'), // Matches border
                'grid_title_alignment'       => get_theme_mod('author_kit_archive_grid_text_alignment_quill', 'left'), // From justify-content: left

                // Pagination
                'pagination_alignment'       => get_theme_mod('author_kit_archive_pagination_alignment_quill', 'center'), // From justify-content: center
                'button_color'               => get_theme_mod('author_kit_archive_button_color_quill', '#fe4f2d'), // From .pagination-prev/next background
                'button_hover_color'         => get_theme_mod('author_kit_archive_button_hover_color_quill', '#fe4f2d'), // Hover state uses same color
                'button_color_txt'           => get_theme_mod('author_kit_archive_pagination_btn_color_quill', '#ffffff'), // Button text
                'numbers_color'              => get_theme_mod('author_kit_archive_pagination_number_color_quill', '#000000'),
                'numbers_bg_color'           => get_theme_mod('author_kit_archive_pagination_number_bg_color_quill', '#FFFFFF'),

            );

            // Get padding settings for bio box
            $bio_padding        = get_theme_mod('author_kit_archive_bio_box_padding_quill', []);
            $bio_padding_top    = isset($bio_padding['desktop']['top']) ? $bio_padding['desktop']['top'] : '80px';
            $bio_padding_right  = isset($bio_padding['desktop']['right']) ? $bio_padding['desktop']['right'] : '120px';
            $bio_padding_bottom = isset($bio_padding['desktop']['bottom']) ? $bio_padding['desktop']['bottom'] : '80px';
            $bio_padding_left   = isset($bio_padding['desktop']['left']) ? $bio_padding['desktop']['left'] : '120px';

            $bio_padding_top_mobile    = isset($bio_padding['mobile']['top']) ? $bio_padding['mobile']['top'] : '30px';
            $bio_padding_right_mobile  = isset($bio_padding['mobile']['right']) ? $bio_padding['mobile']['right'] : '20px';
            $bio_padding_bottom_mobile = isset($bio_padding['mobile']['bottom']) ? $bio_padding['mobile']['bottom'] : '30px';
            $bio_padding_left_mobile   = isset($bio_padding['mobile']['left']) ? $bio_padding['mobile']['left'] : '20px';

            // Get padding settings for post grid container
            $post_grid_padding        = get_theme_mod('author_kit_post_grid_padding_quill', []);
            $post_grid_padding_top    = isset($post_grid_padding['desktop']['top']) ? $post_grid_padding['desktop']['top'] : '20px';
            $post_grid_padding_right  = isset($post_grid_padding['desktop']['right']) ? $post_grid_padding['desktop']['right'] : '120px';
            $post_grid_padding_bottom = isset($post_grid_padding['desktop']['bottom']) ? $post_grid_padding['desktop']['bottom'] : '40px';
            $post_grid_padding_left   = isset($post_grid_padding['desktop']['left']) ? $post_grid_padding['desktop']['left'] : '120px';

            $post_grid_padding_top_mobile    = isset($post_grid_padding['mobile']['top']) ? $post_grid_padding['mobile']['top'] : '10px';
            $post_grid_padding_right_mobile  = isset($post_grid_padding['mobile']['right']) ? $post_grid_padding['mobile']['right'] : '10px';
            $post_grid_padding_bottom_mobile = isset($post_grid_padding['mobile']['bottom']) ? $post_grid_padding['mobile']['bottom'] : '40px';
            $post_grid_padding_left_mobile   = isset($post_grid_padding['mobile']['left']) ? $post_grid_padding['mobile']['left'] : '10px';
            // Name size
            $name   = get_theme_mod('author_kit_archive_name_size_quill', []);
            $name_d = isset($name['desktop']) ? $name['desktop'] : 28;
            $name_m = isset($name['mobile']) ? $name['mobile'] : 20;

            // Job title size
            $title   = get_theme_mod('author_kit_archive_job_title_size_quill', []);
            $title_d = isset($title['desktop']) ? $title['desktop'] : 13;
            $title_m = isset($title['mobile']) ? $title['mobile'] : 12;

            // Description size
            $desc   = get_theme_mod('author_kit_archive_description_size_quill', []);
            $desc_d = isset($desc['desktop']) ? $desc['desktop'] : 14;
            $desc_m = isset($desc['mobile']) ? $desc['mobile'] : 13;

            // Post title size
            $post_title   = get_theme_mod('author_kit_archive_post_title_size_quill', []);
            $post_title_d = isset($post_title['desktop']) ? $post_title['desktop'] : 18;
            $post_title_m = isset($post_title['mobile']) ? $post_title['mobile'] : 16;

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

            // Archive title size
            $archive_title   = get_theme_mod('author_kit_archive_post_grid_title_size_quill', []);
            $archive_title_d = isset($archive_title['desktop']) ? $archive_title['desktop'] : 18;
            $archive_title_m = isset($archive_title['mobile']) ? $archive_title['mobile'] : 16;

            // Excerpt size
            $excerpt   = get_theme_mod('author_kit_archive_excerpt_size_quill', []);
            $excerpt_d = isset($excerpt['desktop']) ? $excerpt['desktop'] : 14;
            $excerpt_m = isset($excerpt['mobile']) ? $excerpt['mobile'] : 13;

            // Meta size
            $meta   = get_theme_mod('author_kit_archive_post_meta_size_quill', []);
            $meta_d = isset($meta['desktop']) ? $meta['desktop'] : 12;
            $meta_m = isset($meta['mobile']) ? $meta['mobile'] : 11;

            // Thumbnail radius
            $thumb   = get_theme_mod('author_kit_archive_thumbnail_border_radius_quill', []);
            $thumb_d = isset($thumb['desktop']) ? $thumb['desktop'] : 8;
            $thumb_m = isset($thumb['mobile']) ? $thumb['mobile'] : 6;

            // Social icon gap
            $icon_gap   = get_theme_mod('author_kit_archive_social_icons_gap_quill', []);
            $icon_gap_d = isset($icon_gap['desktop']) ? $icon_gap['desktop'] : 10;
            $icon_gap_m = isset($icon_gap['mobile']) ? $icon_gap['mobile'] : 8;

            // Social icon size
            $icon   = get_theme_mod('author_kit_archive_social_icons_size_quill', []);
            $icon_d = isset($icon['desktop']) ? $icon['desktop'] : 40;
            $icon_m = isset($icon['mobile']) ? $icon['mobile'] : 32;

            // Inner icon size
            $icon_inner_d = ($icon_d > 43) ? $icon_d - 18 : $icon_d - 16;
            $icon_inner_m = ($icon_m > 43) ? $icon_m - 18 : $icon_m - 14;

            $custom_css .= "
            
    /* ================= MOBILE STYLES ================= */
@media (max-width: 899px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top_mobile} {$bio_padding_right_mobile} {$bio_padding_bottom_mobile} {$bio_padding_left_mobile};
    }

    #author-kit-archive-template .author-kit-posts {
        padding: {$post_grid_padding_top_mobile} {$post_grid_padding_right_mobile} {$post_grid_padding_bottom_mobile} {$post_grid_padding_left_mobile};
    }

     .author-kit-pagination-container  {
        padding-left:  {$post_grid_padding_left_mobile};
         padding-right:  {$post_grid_padding_right_mobile};
    }     


    .author-kit-avatar {
        width: {$avatar_m}px;
        height: {$avatar_m}px;
    }

    .author-kit-name {
        font-size: {$name_m}px;
    }

    .author-kit-job-title {
        font-size: {$title_m}px;
    }

    .author-kit-description {
        font-size: {$desc_m}px;
    }

     #author-kit-archive-template .author-kit-posts-title{
      font-size: {$archive_title_m}px; 
     }


     #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_m}px;
    }


    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_m}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_m}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_m}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_m}px;
    }
}

/* ================= DESKTOP STYLES ================= */
@media (min-width: 900px) {
    #author-kit-archive-template .author-kit-bio-container {
        padding: {$bio_padding_top} {$bio_padding_right} {$bio_padding_bottom} {$bio_padding_left};
    }


    #author-kit-archive-template  .author-kit-posts {
        padding: {$post_grid_padding_top} {$post_grid_padding_right} {$post_grid_padding_bottom} {$post_grid_padding_left};
    }
       .author-kit-pagination-container  {
     
        padding-left:  {$post_grid_padding_left};
         padding-right:  {$post_grid_padding_right};
    }     


}

@media (min-width: 1080px) {
    .author-kit-posts-grid {
        display: grid;
        gap: {$settings['archive_grid_gap']}px;
    }

       #author-kit-archive-template .author-kit-posts-title{
      font-size: {$archive_title_d}px; 
 }

  .author-kit-post-title , #author-kit-archive-template h4.author-kit-post-title a{
        font-size: {$post_title_d}px;
    }

}

/* ================= COMMON STYLES ================= */
#author-kit-archive-template .author-kit-bio-container {
    background-color: {$settings['bio_box_bg_color']};
}

.author-kit-post-title,
#author-kit-archive-template h4.author-kit-post-title a {
    color: {$settings['archive_title_color']};
}

.author-kit-name {
    color: {$settings['name_color']};
}

.author-kit-job-title {
    color: {$settings['job_title_color']};
}

.author-kit-description {
    color: {$settings['description_color']};
}

#author-kit-archive-template .author-kit-posts-title {
    justify-content: {$settings['grid_title_alignment']};
}

#author-kit-archive-template .author-kit-posts {
    background-color: {$settings['grid_bg_color']};
}

#author-kit-archive-template .author-kit-posts-title h3 {
    color: {$settings['post_grid_title_color']};
}

.author-kit-pagination-page {
    color: {$settings['numbers_color']};
    background-color: {$settings['numbers_bg_color']};
}

.author-kit-post-item {
    background-color: {$settings['archive_post_card_bg_color']};
}

.author-kit-post-item a img {
    border-radius: {$settings['archive_thumbnail_radius']}px;
}

.author-kit-post-item div.author-kit-post-excerpt {
    color: {$settings['archive_excerpt_color']};
}

.author-kit-post-meta {
    color: {$settings['archive_post_meta_color']};
    border-color: {$settings['meta_separator_color']};
}

.author-kit-post-meta .author-name,
.author-kit-post-meta .post-date {
    color: {$settings['archive_post_meta_color']};
}

#author-kit-archive-template .author-kit-pagination-container {
    justify-content: {$settings['pagination_alignment']};
    background-color: {$settings['grid_bg_color']};
}

.author-kit-pagination-prev,
.author-kit-pagination-next {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container .current .author-kit-pagination-page {
    background: {$settings['button_color']};
    color: {$settings['button_color_txt']};
}

.author-kit-pagination-container a:hover .author-kit-pagination-page,
.author-kit-pagination-prev:hover,
.author-kit-pagination-next:hover {
    background: {$settings['button_hover_color']};
    color: {$settings['button_color_txt']};
}
/* ============ DESKTOP STYLES (min-width: 899px) ============ */
@media (min-width: 899px) {
    .author-kit-name {
        font-size: {$name_d}px;
    }

    .author-kit-job-title {
        font-size: {$title_d}px;
    }

    .author-kit-description {
        font-size: {$desc_d}px;
    }

    .author-kit-post-item div.author-kit-post-excerpt {
        font-size: {$excerpt_d}px;
    }

    .author-kit-post-meta {
        font-size: {$meta_d}px;
    }

    .author-kit-avatar {
        width: {$avatar_d}px;
        height: {$avatar_d}px;
    }

    .author-kit-social-icons-list {
        gap: {$icon_gap_d}px;
    }

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

    .author-kit-social-icons-list i {
        font-size: {$icon_inner_d}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 archive based on the active template.
 *
 * Ensures styles are only loaded on author archive pages.
 *
 * @param string $template_name The active author archive template name.
 */
function author_kit_enqueue_archive_styles($template_name)
{
    if (! is_author() || ! get_option('author_kit_archive_display', true)) {
        return;
    }

    // Define the base plugin URLs for styles
    $base_url_css = AUTHOR_KIT_PLUGIN_URL . 'public/templates/archive-pages/asset/css/';
    $handle       = "author-kit-$template_name";

    // Enqueue styles based on template name
    switch ($template_name) {
        case 'archive-template-default':
            wp_enqueue_style($handle, $base_url_css . 'archive-template-default-styles.css', array(), AUTHOR_KIT_VERSION, 'all');
            if (is_rtl()) {
                wp_enqueue_style($handle . '-rtl', $base_url_css . 'archive-template-default-styles-rtl.css', array(), AUTHOR_KIT_VERSION, 'all');
            }
            break;

        case 'archive-template-quill':
            wp_enqueue_style($handle, $base_url_css . 'archive-template-default-styles.css', array(), AUTHOR_KIT_VERSION, 'all');
            if (is_rtl()) {
                wp_enqueue_style($handle . '-rtl', $base_url_css . 'archive-template-default-styles-rtl.css', array(), AUTHOR_KIT_VERSION, 'all');
            }
            break;

        case 'archive-template-scribe':
            wp_enqueue_style($handle, $base_url_css . 'archive-template-default-styles.css', array(), AUTHOR_KIT_VERSION, 'all');
            if (is_rtl()) {
                wp_enqueue_style($handle . '-rtl', $base_url_css . 'archive-template-default-styles-rtl.css', array(), AUTHOR_KIT_VERSION, 'all');
            }
            break;
    }
}



/**
 * Loads the inline styles for the active author archive template.
 *
 * Retrieves the active template from the database and enqueues its stylesheet.
 * Additionally, generates and applies custom inline CSS.
 */
function author_kit_load_archive_inline_styles()
{
    if (! is_author() || ! get_option('author_kit_archive_display', true)) {
        return;
    }
    // Retrieve the active author archive template
    $active_template = get_option('author_kit_author_archive_template', 'archive-template-default');

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

    // Generate and add custom inline CSS
    $custom_css = author_kit_generate_archive_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_archive_inline_styles', 999);
