<?php
/**
 * Theme Customizer
 *
 * @package ChaletMontagne
 * @since 1.0.0
 */

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

/**
 * Register customizer settings
 *
 * @param WP_Customize_Manager $wp_customize Theme Customizer object.
 */
function chaletmontagne_customize_register($wp_customize) {

    // Remove default Colors section to avoid conflict with our preset system
    $wp_customize->remove_section('colors');

    /**
     * Panel: Apparence et Style
     */
    $wp_customize->add_panel('chaletmontagne_identity', array(
        'title'       => __('Apparence et Style', 'chalet-montagne'),
        'description' => __('Personnalisez l\'apparence et le style de votre site de location.', 'chalet-montagne'),
        'priority'    => 30,
    ));

    /**
     * Section: Style du thème (Thème Luxury Presets)
     */
    $wp_customize->add_section('chaletmontagne_theme_style', array(
        'title'       => __('Style du thème', 'chalet-montagne'),
        'panel'       => 'chaletmontagne_identity',
        'priority'    => 5,
        'description' => __('Choisissez un style prédéfini ou personnalisez les couleurs manuellement.', 'chalet-montagne'),
    ));

    // Luxury Theme Preset with custom control
    $wp_customize->add_setting('chaletmontagne_luxury_preset', array(
        'default'           => 'marron-sobre',
        'sanitize_callback' => 'chaletmontagne_sanitize_luxury_preset',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control(new ChaletMontagne_Luxury_Preset_Control($wp_customize, 'chaletmontagne_luxury_preset', array(
        'label'       => __('Thème Luxury', 'chalet-montagne'),
        'description' => __('Sélectionnez un thème prédéfini haut de gamme. Cliquez sur une carte pour changer de thème.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_theme_style',
    )));

    // Typography Preset (for luxury themes)
    $wp_customize->add_setting('chaletmontagne_typography_preset', array(
        'default'           => 'playfair-montserrat',
        'sanitize_callback' => 'chaletmontagne_sanitize_typography_preset',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_typography_preset', array(
        'label'       => __('Typographie', 'chalet-montagne'),
        'description' => __('Police de caractères pour le thème.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_theme_style',
        'type'        => 'select',
        'choices'     => array(
            // Serif + Sans-serif
            'playfair-montserrat'    => __('Playfair Display + Montserrat (Classique)', 'chalet-montagne'),
            'cormorant-raleway'      => __('Cormorant Garamond + Raleway (Élégant)', 'chalet-montagne'),
            'dmserif-dmsans'         => __('DM Serif Display + DM Sans (Contemporain)', 'chalet-montagne'),
            'lora-inter'             => __('Lora + Inter (Lisible)', 'chalet-montagne'),
            'crimsonpro-worksans'    => __('Crimson Pro + Work Sans (Éditorial)', 'chalet-montagne'),
            // 100% Sans-serif
            'montserrat-inter'       => __('Montserrat + Inter (Moderne)', 'chalet-montagne'),
            'raleway-dmsans'         => __('Raleway + DM Sans (Épuré)', 'chalet-montagne'),
            'outfit-worksans'        => __('Outfit + Work Sans (Minimal)', 'chalet-montagne'),
        ),
    ));

    /**
     * Section: Couleurs du thème
     */
    $wp_customize->add_section('chaletmontagne_colors', array(
        'title'       => __('Couleurs personnalisées', 'chalet-montagne'),
        'panel'       => 'chaletmontagne_identity',
        'priority'    => 10,
        'description' => __('Personnalisez les couleurs du thème. Ces réglages s\'appliquent à tous les thèmes.', 'chalet-montagne'),
    ));

    // Get current luxury preset for dynamic defaults
    $current_preset = get_theme_mod('chaletmontagne_luxury_preset', 'marron-sobre');
    $preset_colors = chaletmontagne_get_luxury_colors($current_preset);

    // Primary Color
    $wp_customize->add_setting('chaletmontagne_primary_color', array(
        'default'           => $preset_colors['primary'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_primary_color', array(
        'label'       => __('Couleur principale', 'chalet-montagne'),
        'description' => __('Utilisée pour les liens, boutons et éléments importants.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_primary_color',
    )));

    // Secondary Color
    $wp_customize->add_setting('chaletmontagne_secondary_color', array(
        'default'           => $preset_colors['secondary'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_secondary_color', array(
        'label'       => __('Couleur secondaire', 'chalet-montagne'),
        'description' => __('Utilisée pour les accents et éléments décoratifs.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_secondary_color',
    )));

    // Accent Color
    $wp_customize->add_setting('chaletmontagne_accent_color', array(
        'default'           => $preset_colors['accent'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_accent_color', array(
        'label'       => __('Couleur d\'accentuation', 'chalet-montagne'),
        'description' => __('Utilisée pour les survols et états actifs.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_accent_color',
    )));

    // Text Color
    $wp_customize->add_setting('chaletmontagne_text_color', array(
        'default'           => $preset_colors['text'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_text_color', array(
        'label'       => __('Couleur du texte', 'chalet-montagne'),
        'description' => __('Couleur du texte principal.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_text_color',
    )));

    // Headings Color (NEW)
    $wp_customize->add_setting('chaletmontagne_headings_color', array(
        'default'           => $preset_colors['dark'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_headings_color', array(
        'label'       => __('Couleur des titres (H1, H2, H3...)', 'chalet-montagne'),
        'description' => __('Couleur des titres.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_headings_color',
    )));

    // Background Color (NEW)
    $wp_customize->add_setting('chaletmontagne_background_color', array(
        'default'           => $preset_colors['bg'],
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_background_color', array(
        'label'       => __('Couleur de fond général', 'chalet-montagne'),
        'description' => __('Couleur de fond du site.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_background_color',
    )));

    // Content Background Color (NEW)
    $wp_customize->add_setting('chaletmontagne_content_bg_color', array(
        'default'           => isset($preset_colors['content_bg']) ? $preset_colors['content_bg'] : '#FFFFFF',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_content_bg_color', array(
        'label'       => __('Couleur de fond du contenu', 'chalet-montagne'),
        'description' => __('Couleur de fond des zones de contenu, cartes, widgets.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_colors',
        'settings'    => 'chaletmontagne_content_bg_color',
    )));

    /**
     * Section: Hero / Bannière d'accueil
     */
    $wp_customize->add_section('chaletmontagne_hero', array(
        'title'    => __('Bannière d\'accueil', 'chalet-montagne'),
        'panel'    => 'chaletmontagne_identity',
        'priority' => 20,
    ));

    // Hero Title
    $wp_customize->add_setting('chaletmontagne_hero_title', array(
        'default'           => __('Locations de charme à la montagne', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hero_title', array(
        'label'    => __('Titre principal', 'chalet-montagne'),
        'description' => __('Un retour à la ligne dans ce champ crée une nouvelle ligne dans le titre.', 'chalet-montagne'),
        'section'  => 'chaletmontagne_hero',
        'settings' => 'chaletmontagne_hero_title',
        'type'     => 'textarea',
    ));

    // Hero Title Size
    $wp_customize->add_setting('chaletmontagne_hero_title_size', array(
        'default'           => 0,
        'sanitize_callback' => 'chaletmontagne_sanitize_hero_title_size',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hero_title_size', array(
        'label'       => __('Taille du titre principal (px)', 'chalet-montagne'),
        'description' => __('0 = taille automatique du thème. Sur mobile, la taille est réduite automatiquement pour ne pas déborder.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_title_size',
        'type'        => 'range',
        'input_attrs' => array('min' => 0, 'max' => 150, 'step' => 1),
    ));

    // Hero Subtitle
    $wp_customize->add_setting('chaletmontagne_hero_subtitle', array(
        'default'           => __('Des hébergements d\'exception pour vos séjours à la montagne', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hero_subtitle', array(
        'label'    => __('Sous-titre / Slogan', 'chalet-montagne'),
        'section'  => 'chaletmontagne_hero',
        'settings' => 'chaletmontagne_hero_subtitle',
        'type'     => 'text',
    ));

    // Hero CTA Text
    $wp_customize->add_setting('chaletmontagne_hero_cta_text', array(
        'default'           => __('Découvrir nos locations', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hero_cta_text', array(
        'label'    => __('Texte du bouton CTA', 'chalet-montagne'),
        'section'  => 'chaletmontagne_hero',
        'settings' => 'chaletmontagne_hero_cta_text',
        'type'     => 'text',
    ));

    // Hero CTA URL
    $wp_customize->add_setting('chaletmontagne_hero_cta_url', array(
        'default'           => '',
        'sanitize_callback' => 'esc_url_raw',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_hero_cta_url', array(
        'label'       => __('URL du bouton CTA', 'chalet-montagne'),
        'description' => __('Laissez vide pour masquer le bouton.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_cta_url',
        'type'        => 'url',
    ));

    // Hero Background Image
    $wp_customize->add_setting('chaletmontagne_hero_bg', array(
        'default'           => '',
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control(new WP_Customize_Media_Control($wp_customize, 'chaletmontagne_hero_bg', array(
        'label'       => __('Image de fond', 'chalet-montagne'),
        'description' => __('Recommandé : 1920x800px. Utilisé uniquement si le slider est désactivé.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_bg',
        'mime_type'   => 'image',
    )));

    // Hero Title Color
    $wp_customize->add_setting('chaletmontagne_hero_title_color', array(
        'default'           => '#ffffff',
        'sanitize_callback' => 'sanitize_hex_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_hero_title_color', array(
        'label'       => __('Couleur du titre principal', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_title_color',
    )));

    // Hero Overlay Opacity
    $wp_customize->add_setting('chaletmontagne_hero_overlay_opacity', array(
        'default'           => 70,
        'sanitize_callback' => 'absint',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hero_overlay_opacity', array(
        'label'       => __('Opacité de l\'overlay', 'chalet-montagne'),
        'description' => __('Réglez l\'intensité du voile sombre sur l\'image de fond (0 = transparent, 100 = opaque).', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_overlay_opacity',
        'type'        => 'range',
        'input_attrs' => array(
            'min'  => 0,
            'max'  => 100,
            'step' => 5,
        ),
    ));

    // Hero Subtitle Color
    $wp_customize->add_setting('chaletmontagne_hero_subtitle_color', array(
        'default'           => 'rgba(255,255,255,0.9)',
        'sanitize_callback' => 'chaletmontagne_sanitize_rgba_color',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control(new WP_Customize_Color_Control($wp_customize, 'chaletmontagne_hero_subtitle_color', array(
        'label'       => __('Couleur du slogan', 'chalet-montagne'),
        'section'     => 'chaletmontagne_hero',
        'settings'    => 'chaletmontagne_hero_subtitle_color',
    )));

    /**
     * Section: Slider d'accueil
     */
    $wp_customize->add_section('chaletmontagne_slider', array(
        'title'       => __('Slider d\'accueil', 'chalet-montagne'),
        'description' => __('Configurez un diaporama d\'images sur la page d\'accueil.', 'chalet-montagne'),
        'panel'       => 'chaletmontagne_identity',
        'priority'    => 25,
    ));

    // Enable slider
    $wp_customize->add_setting('chaletmontagne_slider_enable', array(
        'default'           => false,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_enable', array(
        'label'       => __('Activer le slider', 'chalet-montagne'),
        'description' => __('Remplace l\'image de fond unique par un diaporama.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
        'type'        => 'checkbox',
    ));

    // Slider images gallery
    $wp_customize->add_setting('chaletmontagne_slider_images', array(
        'default'           => '',
        'sanitize_callback' => 'chaletmontagne_sanitize_gallery',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control(new ChaletMontagne_Gallery_Control($wp_customize, 'chaletmontagne_slider_images', array(
        'label'       => __('Images du slider', 'chalet-montagne'),
        'description' => __('Sélectionnez les images du diaporama. Recommandé : 1920x800px. L\'ordre des images détermine l\'ordre d\'affichage.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
    )));

    // Slider transition type
    $wp_customize->add_setting('chaletmontagne_slider_transition', array(
        'default'           => 'fade',
        'sanitize_callback' => 'chaletmontagne_sanitize_slider_transition',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_transition', array(
        'label'   => __('Type de transition', 'chalet-montagne'),
        'section' => 'chaletmontagne_slider',
        'type'    => 'select',
        'choices' => array(
            'fade'       => __('Fondu (Fade)', 'chalet-montagne'),
            'slide'      => __('Glissement (Slide)', 'chalet-montagne'),
            'zoom'       => __('Zoom', 'chalet-montagne'),
            'blur'       => __('Flou (Blur)', 'chalet-montagne'),
            'flip'       => __('Retournement (Flip)', 'chalet-montagne'),
        ),
    ));

    // Slider speed (pause duration)
    $wp_customize->add_setting('chaletmontagne_slider_speed', array(
        'default'           => 5,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_speed', array(
        'label'       => __('Durée d\'affichage (secondes)', 'chalet-montagne'),
        'description' => __('Temps de pause entre chaque slide. Entre 2 et 15 secondes.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
        'type'        => 'number',
        'input_attrs' => array(
            'min'  => 2,
            'max'  => 15,
            'step' => 1,
        ),
    ));

    // Slider transition duration
    $wp_customize->add_setting('chaletmontagne_slider_transition_speed', array(
        'default'           => 1000,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_transition_speed', array(
        'label'       => __('Durée de la transition (ms)', 'chalet-montagne'),
        'description' => __('Vitesse de l\'animation de transition. Entre 300 et 3000 ms.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
        'type'        => 'number',
        'input_attrs' => array(
            'min'  => 300,
            'max'  => 3000,
            'step' => 100,
        ),
    ));

    // Show slider navigation dots
    $wp_customize->add_setting('chaletmontagne_slider_dots', array(
        'default'           => true,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_dots', array(
        'label'   => __('Afficher les points de navigation', 'chalet-montagne'),
        'section' => 'chaletmontagne_slider',
        'type'    => 'checkbox',
    ));

    // Show slider arrows
    $wp_customize->add_setting('chaletmontagne_slider_arrows', array(
        'default'           => true,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_arrows', array(
        'label'   => __('Afficher les flèches de navigation', 'chalet-montagne'),
        'section' => 'chaletmontagne_slider',
        'type'    => 'checkbox',
    ));

    // Autoplay
    $wp_customize->add_setting('chaletmontagne_slider_autoplay', array(
        'default'           => true,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_autoplay', array(
        'label'       => __('Lecture automatique', 'chalet-montagne'),
        'description' => __('Défilement automatique des slides.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
        'type'        => 'checkbox',
    ));

    // Pause on hover
    $wp_customize->add_setting('chaletmontagne_slider_pause_hover', array(
        'default'           => true,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_pause_hover', array(
        'label'   => __('Pause au survol', 'chalet-montagne'),
        'section' => 'chaletmontagne_slider',
        'type'    => 'checkbox',
    ));

    // Slider overlay opacity
    $wp_customize->add_setting('chaletmontagne_slider_overlay', array(
        'default'           => 40,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_slider_overlay', array(
        'label'       => __('Opacité de l\'overlay (%)', 'chalet-montagne'),
        'description' => __('Assombrit les images pour améliorer la lisibilité du texte. 0 = transparent, 100 = opaque.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_slider',
        'type'        => 'range',
        'input_attrs' => array(
            'min'  => 0,
            'max'  => 80,
            'step' => 5,
        ),
    ));

    /**
     * Panel: Informations de contact
     */
    $wp_customize->add_panel('chaletmontagne_contact_panel', array(
        'title'       => __('Contact & Informations', 'chalet-montagne'),
        'description' => __('Vos coordonnées et informations pratiques.', 'chalet-montagne'),
        'priority'    => 40,
    ));

    /**
     * Section: Coordonnées
     */
    $wp_customize->add_section('chaletmontagne_contact', array(
        'title'    => __('Coordonnées', 'chalet-montagne'),
        'panel'    => 'chaletmontagne_contact_panel',
        'priority' => 10,
    ));

    // Phone
    $wp_customize->add_setting('chaletmontagne_phone', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_phone', array(
        'label'    => __('Téléphone', 'chalet-montagne'),
        'section'  => 'chaletmontagne_contact',
        'settings' => 'chaletmontagne_phone',
        'type'     => 'tel',
    ));

    // Email
    $wp_customize->add_setting('chaletmontagne_email', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_email',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_email', array(
        'label'    => __('Email', 'chalet-montagne'),
        'section'  => 'chaletmontagne_contact',
        'settings' => 'chaletmontagne_email',
        'type'     => 'email',
    ));

    // Address
    $wp_customize->add_setting('chaletmontagne_address', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_address', array(
        'label'       => __('Adresse', 'chalet-montagne'),
        'description' => __('Adresse de votre point d\'accueil (optionnel).', 'chalet-montagne'),
        'section'     => 'chaletmontagne_contact',
        'settings'    => 'chaletmontagne_address',
        'type'        => 'textarea',
    ));

    // Business Hours
    $wp_customize->add_setting('chaletmontagne_hours', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_hours', array(
        'label'       => __('Horaires de disponibilité', 'chalet-montagne'),
        'description' => __('Ex: "Lun-Sam 9h-18h"', 'chalet-montagne'),
        'section'     => 'chaletmontagne_contact',
        'settings'    => 'chaletmontagne_hours',
        'type'        => 'text',
    ));

    /**
     * Section: Informations station
     */
    $wp_customize->add_section('chaletmontagne_station', array(
        'title'    => __('Informations station', 'chalet-montagne'),
        'panel'    => 'chaletmontagne_contact_panel',
        'priority' => 20,
    ));

    // Station Name
    $wp_customize->add_setting('chaletmontagne_station_name', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_station_name', array(
        'label'       => __('Nom de la station', 'chalet-montagne'),
        'description' => __('Ex: "Chamonix Mont-Blanc"', 'chalet-montagne'),
        'section'     => 'chaletmontagne_station',
        'settings'    => 'chaletmontagne_station_name',
        'type'        => 'text',
    ));

    // Distance to slopes
    $wp_customize->add_setting('chaletmontagne_distance_slopes', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_distance_slopes', array(
        'label'       => __('Distance des pistes', 'chalet-montagne'),
        'description' => __('Ex: "100m" ou "Pied des pistes"', 'chalet-montagne'),
        'section'     => 'chaletmontagne_station',
        'settings'    => 'chaletmontagne_distance_slopes',
        'type'        => 'text',
    ));

    // Distance to center
    $wp_customize->add_setting('chaletmontagne_distance_center', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_distance_center', array(
        'label'       => __('Distance du centre-ville', 'chalet-montagne'),
        'description' => __('Ex: "500m"', 'chalet-montagne'),
        'section'     => 'chaletmontagne_station',
        'settings'    => 'chaletmontagne_distance_center',
        'type'        => 'text',
    ));

    // Activities
    $wp_customize->add_setting('chaletmontagne_activities', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_textarea_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_activities', array(
        'label'       => __('Activités à proximité', 'chalet-montagne'),
        'description' => __('Décrivez brièvement les activités disponibles.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_station',
        'settings'    => 'chaletmontagne_activities',
        'type'        => 'textarea',
    ));

    /**
     * Section: Arguments de vente
     */
    $wp_customize->add_section('chaletmontagne_features', array(
        'title'    => __('Arguments de vente', 'chalet-montagne'),
        'panel'    => 'chaletmontagne_contact_panel',
        'priority' => 30,
    ));

    // Feature 1
    $wp_customize->add_setting('chaletmontagne_feature_1', array(
        'default'           => __('Wifi gratuit inclus', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_feature_1', array(
        'label'    => __('Argument 1', 'chalet-montagne'),
        'section'  => 'chaletmontagne_features',
        'settings' => 'chaletmontagne_feature_1',
        'type'     => 'text',
    ));

    // Feature 2
    $wp_customize->add_setting('chaletmontagne_feature_2', array(
        'default'           => __('Parking privé gratuit', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_feature_2', array(
        'label'    => __('Argument 2', 'chalet-montagne'),
        'section'  => 'chaletmontagne_features',
        'settings' => 'chaletmontagne_feature_2',
        'type'     => 'text',
    ));

    // Feature 3
    $wp_customize->add_setting('chaletmontagne_feature_3', array(
        'default'           => __('Ménage final offert', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_feature_3', array(
        'label'    => __('Argument 3', 'chalet-montagne'),
        'section'  => 'chaletmontagne_features',
        'settings' => 'chaletmontagne_feature_3',
        'type'     => 'text',
    ));

    // Feature 4
    $wp_customize->add_setting('chaletmontagne_feature_4', array(
        'default'           => __('Réservation directe - meilleurs tarifs', 'chalet-montagne'),
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'postMessage',
    ));

    $wp_customize->add_control('chaletmontagne_feature_4', array(
        'label'    => __('Argument 4', 'chalet-montagne'),
        'section'  => 'chaletmontagne_features',
        'settings' => 'chaletmontagne_feature_4',
        'type'     => 'text',
    ));

    // (Options commerciales supprimées — non utilisées par le thème)

    /**
     * Section: Réseaux sociaux
     */
    $wp_customize->add_section('chaletmontagne_social', array(
        'title'       => __('Réseaux sociaux', 'chalet-montagne'),
        'description' => __('Liens vers vos profils sociaux et plateformes de réservation.', 'chalet-montagne'),
        'priority'    => 50,
    ));

    // Social media fields
    $social_networks = array(
        'facebook'  => 'Facebook',
        'instagram' => 'Instagram',
        'twitter'   => 'Twitter (X)',
        'youtube'   => 'YouTube',
        'chalet-montagne'    => 'Chalet-montagne.com',
        'airbnb'    => 'Airbnb',
        'booking'   => 'Booking.com',
    );

    foreach ($social_networks as $network => $label) {
        $wp_customize->add_setting("chaletmontagne_social_{$network}", array(
            'default'           => '',
            'sanitize_callback' => 'esc_url_raw',
            'transport'         => 'refresh',
        ));

        $wp_customize->add_control("chaletmontagne_social_{$network}", array(
            'label'    => $label,
            'section'  => 'chaletmontagne_social',
            'settings' => "chaletmontagne_social_{$network}",
            'type'     => 'url',
        ));
    }

    /**
     * Section: Pied de page
     */
    $wp_customize->add_section('chaletmontagne_footer', array(
        'title'       => __('Pied de page', 'chalet-montagne'),
        'description' => __('Personnalisez le pied de page. Le contenu des colonnes se gère dans Widgets (zones Footer colonne 1/2/3).', 'chalet-montagne'),
        'priority'    => 120,
    ));

    // Copyright text
    $wp_customize->add_setting('chaletmontagne_footer_copyright', array(
        'default'           => '',
        'sanitize_callback' => 'sanitize_text_field',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_footer_copyright', array(
        'label'       => __('Texte copyright', 'chalet-montagne'),
        'description' => __('Personnalisez le texte copyright. Si vide, affiche « © Nom du site Année. Tous droits réservés. »', 'chalet-montagne'),
        'section'     => 'chaletmontagne_footer',
        'type'        => 'text',
    ));

    // Hide theme credit
    $wp_customize->add_setting('chaletmontagne_hide_theme_credit', array(
        'default'           => false,
        'sanitize_callback' => 'chaletmontagne_sanitize_checkbox',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_hide_theme_credit', array(
        'label'   => __('Masquer le crédit thème', 'chalet-montagne'),
        'section' => 'chaletmontagne_footer',
        'type'    => 'checkbox',
    ));

    // Mentions légales page
    $wp_customize->add_setting('chaletmontagne_mentions_legales_page', array(
        'default'           => 0,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_mentions_legales_page', array(
        'label'       => __('Page Mentions légales', 'chalet-montagne'),
        'description' => __('Sélectionnez la page contenant vos mentions légales.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_footer',
        'type'        => 'dropdown-pages',
    ));

    // Politique de confidentialité page
    $wp_customize->add_setting('chaletmontagne_privacy_policy_page', array(
        'default'           => 0,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_privacy_policy_page', array(
        'label'       => __('Page Politique de confidentialité', 'chalet-montagne'),
        'description' => __('Sélectionnez la page RGPD / confidentialité. Si vide, utilise la page de confidentialité WordPress par défaut.', 'chalet-montagne'),
        'section'     => 'chaletmontagne_footer',
        'type'        => 'dropdown-pages',
    ));


    /**
     * Section: Options diverses
     */
    $wp_customize->add_section('chaletmontagne_options', array(
        'title'    => __('Options diverses', 'chalet-montagne'),
        'priority' => 130,
    ));

    // Show breadcrumbs
    $wp_customize->add_setting('chaletmontagne_show_breadcrumbs', array(
        'default'           => true,
        'sanitize_callback' => 'absint',
        'transport'         => 'refresh',
    ));

    $wp_customize->add_control('chaletmontagne_show_breadcrumbs', array(
        'label'    => __('Afficher le fil d\'Ariane', 'chalet-montagne'),
        'section'  => 'chaletmontagne_options',
        'settings' => 'chaletmontagne_show_breadcrumbs',
        'type'     => 'checkbox',
    ));
}
add_action('customize_register', 'chaletmontagne_customize_register');

/**
 * Bind JS handlers to instantly live-preview changes
 */
function chaletmontagne_customize_preview_js() {
    wp_enqueue_script(
        'chaletmontagne-customizer',
        get_template_directory_uri() . '/assets/js/customizer.js',
        array('customize-preview'),
        CHALETMONTAGNE_VERSION,
        true
    );
}
add_action('customize_preview_init', 'chaletmontagne_customize_preview_js');

/**
 * Enqueue customizer controls JavaScript (panel side)
 */
function chaletmontagne_customize_controls_js() {
    wp_enqueue_script(
        'chaletmontagne-customizer-controls',
        get_template_directory_uri() . '/assets/js/customizer-controls.js',
        array('customize-controls'),
        CHALETMONTAGNE_VERSION,
        true
    );

    // Pass ajaxurl to the script
    wp_localize_script(
        'chaletmontagne-customizer-controls',
        'chaletMontagneCustomizer',
        array(
            'ajaxurl' => admin_url('admin-ajax.php'),
            'nonce' => wp_create_nonce('customize-controls')
        )
    );
}
add_action('customize_controls_enqueue_scripts', 'chaletmontagne_customize_controls_js');

/**
 * Sanitize checkbox
 */
/**
 * Sanitize hero title size (0 = automatique, sinon 12 à 150 px)
 */
function chaletmontagne_sanitize_hero_title_size($input) {
    $size = absint($input);
    if (0 === $size) {
        return 0;
    }
    return max(12, min(150, $size));
}

function chaletmontagne_sanitize_checkbox($input) {
    return (bool) $input;
}

/**
 * Sanitize luxury preset
 */
function chaletmontagne_sanitize_luxury_preset($input) {
    $valid_presets = array(
        'marron-sobre',
        'esprit-bois',
        'noir-prestige',
        'ardoise-mineral',
        'foret-sauge',
    );
    return in_array($input, $valid_presets, true) ? $input : 'marron-sobre';
}

/**
 * Sanitize typography preset
 */
function chaletmontagne_sanitize_typography_preset($input) {
    $valid_presets = array(
        // Serif + Sans-serif
        'playfair-montserrat',
        'cormorant-raleway',
        'dmserif-dmsans',
        'lora-inter',
        'crimsonpro-worksans',
        // 100% Sans-serif
        'montserrat-inter',
        'raleway-dmsans',
        'outfit-worksans',
    );
    return in_array($input, $valid_presets, true) ? $input : 'playfair-montserrat';
}

/**
 * Sanitize slider gallery (comma-separated IDs)
 */
function chaletmontagne_sanitize_gallery($input) {
    if (empty($input)) {
        return '';
    }
    $ids = explode(',', $input);
    $ids = array_map('absint', $ids);
    $ids = array_filter($ids);
    return implode(',', $ids);
}

/**
 * Sanitize slider transition type
 */
function chaletmontagne_sanitize_slider_transition($input) {
    $valid = array('fade', 'slide', 'zoom', 'blur', 'flip');
    return in_array($input, $valid, true) ? $input : 'fade';
}

/**
 * Sanitize RGBA color
 */
function chaletmontagne_sanitize_rgba_color($input) {
    // Allow hex colors
    if (preg_match('/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/', $input)) {
        return $input;
    }
    // Allow rgba colors
    if (preg_match('/^rgba?\(\s*\d+\s*,\s*\d+\s*,\s*\d+\s*(,\s*(0|1|0?\.\d+))?\s*\)$/', $input)) {
        return $input;
    }
    return 'rgba(255,255,255,0.9)';
}

/**
 * Get luxury theme colors
 * 5 Premium Themes: 3 Light, 1 Wood, 1 Dark
 */
function chaletmontagne_get_luxury_colors($preset) {
    $themes = array(

        // ═══════════════════════════════════════════════════════════
        // MARRON SOBRE - Brun raffiné, fond clair chaud
        // Inspiration: Cuir, pierre naturelle, sobriété élégante
        // ═══════════════════════════════════════════════════════════

        /**
         * MARRON SOBRE - Brun raffiné et sobre
         */
        'marron-sobre' => array(
            'primary'       => '#7B5B3A',    // Brun cuir chaud
            'secondary'     => '#A38B6D',    // Sable / tan
            'accent'        => '#9C7A52',    // Caramel discret
            'dark'          => '#3A2C1E',    // Brun très foncé (titres)
            'charcoal'      => '#4D3D2E',    // Brun sombre
            'bg'            => '#FAF8F5',    // Blanc chaud cassé
            'text'          => '#4A3D30',    // Brun-gris texte
            'text_light'    => '#7A6D5E',    // Texte secondaire
            'content_bg'    => '#FFFFFF',    // Blanc pur
            'card_bg'       => '#FDFCFA',    // Blanc légèrement chaud
            'card_border'   => '#E8E2DA',    // Bordure subtile chaude
            'input_bg'      => '#FFFFFF',    // Fond inputs
            'input_border'  => '#D8D0C5',    // Bordure inputs
            'input_focus'   => '#7B5B3A',    // Focus inputs
            'input_text'    => '#3A2C1E',    // Texte inputs
            'btn_text'      => '#FFFFFF',    // Texte boutons
            'link_hover'    => '#5E4328',    // Liens hover
            'divider'       => '#E5DED5',    // Séparateurs
            'shadow'        => 'rgba(123, 91, 58, 0.08)', // Ombres
            'is_dark'       => false,
        ),

        // ═══════════════════════════════════════════════════════════
        // ESPRIT BOIS - Authenticité chalet
        // Inspiration: Intérieur de chalet en pin, miel, lumière chaude
        // ═══════════════════════════════════════════════════════════

        'esprit-bois' => array(
            'primary'       => '#B07D3A',    // Ambre riche / miel
            'secondary'     => '#D4A95C',    // Bois doré
            'accent'        => '#C4853F',    // Cuivre boisé
            'dark'          => '#4A3520',    // Noyer foncé (titres)
            'charcoal'      => '#5E4530',    // Bois moyen foncé
            'bg'            => '#F5EDE0',    // Parchemin chaud
            'text'          => '#5A4430',    // Brun bois texte
            'text_light'    => '#8A7560',    // Texte secondaire
            'content_bg'    => '#FBF6EE',    // Crème
            'card_bg'       => '#F8F0E4',    // Fond cartes chaud
            'card_border'   => '#E0D0B8',    // Bordure boisée
            'input_bg'      => '#FBF6EE',    // Fond inputs
            'input_border'  => '#D0C0A5',    // Bordure inputs
            'input_focus'   => '#B07D3A',    // Focus inputs
            'input_text'    => '#4A3520',    // Texte inputs
            'btn_text'      => '#FFFFFF',    // Texte boutons
            'link_hover'    => '#8E6230',    // Liens hover
            'divider'       => '#DDD0BA',    // Séparateurs
            'shadow'        => 'rgba(176, 125, 58, 0.1)', // Ombres dorées
            'is_dark'       => false,
        ),

        // ═══════════════════════════════════════════════════════════
        // NOIR PRESTIGE - Luxe ultime
        // Inspiration: Palace, haute couture, noir & or
        // ═══════════════════════════════════════════════════════════

        'noir-prestige' => array(
            'primary'       => '#C9A84C',    // Or riche
            'secondary'     => '#E8D5A0',    // Or clair / champagne
            'accent'        => '#B89530',    // Or antique
            'dark'          => '#050505',    // Noir quasi absolu (titres)
            'charcoal'      => '#0A0A0A',    // Noir profond
            'bg'            => '#0A0A0A',    // Fond noir
            'text'          => '#E8E0D0',    // Ivoire chaud
            'text_light'    => '#A89878',    // Or atténué texte
            'content_bg'    => '#111110',    // Fond contenu très sombre
            'card_bg'       => '#161614',    // Fond cartes sombre
            'card_border'   => '#2A2520',    // Bordure subtile or
            'input_bg'      => '#0E0E0D',    // Fond inputs
            'input_border'  => '#3A3228',    // Bordure inputs
            'input_focus'   => '#C9A84C',    // Focus inputs or
            'input_text'    => '#E8E0D0',    // Texte inputs
            'btn_text'      => '#0A0A0A',    // Texte boutons (sombre sur or)
            'link_hover'    => '#E0C060',    // Liens hover or brillant
            'divider'       => '#1E1A15',    // Séparateurs
            'shadow'        => 'rgba(201, 168, 76, 0.1)', // Ombres dorées
            'is_dark'       => true,
            'effect'        => 'gold-shimmer',
        ),

        // ═══════════════════════════════════════════════════════════
        // ARDOISE MINÉRAL - Sobre et contemporain
        // Inspiration: Pierre d'ardoise, ciel d'hiver, minéral
        // ═══════════════════════════════════════════════════════════

        'ardoise-mineral' => array(
            'primary'       => '#5A7080',    // Bleu ardoise
            'secondary'     => '#8AA0B0',    // Ardoise claire
            'accent'        => '#8C7B5E',    // Pierre chaude (contrebalance le froid)
            'dark'          => '#1E2D38',    // Bleu-gris foncé (titres)
            'charcoal'      => '#2D3E4A',    // Bleu-charbon
            'bg'            => '#F5F7F9',    // Gris très clair froid
            'text'          => '#3A4A55',    // Bleu-gris texte
            'text_light'    => '#6A7A85',    // Texte secondaire
            'content_bg'    => '#FFFFFF',    // Blanc pur
            'card_bg'       => '#FFFFFF',    // Fond cartes
            'card_border'   => '#E0E6EB',    // Bordure froide
            'input_bg'      => '#FFFFFF',    // Fond inputs
            'input_border'  => '#CDD5DC',    // Bordure inputs
            'input_focus'   => '#5A7080',    // Focus inputs
            'input_text'    => '#1E2D38',    // Texte inputs
            'btn_text'      => '#FFFFFF',    // Texte boutons
            'link_hover'    => '#3E5565',    // Liens hover
            'divider'       => '#DDE3E8',    // Séparateurs
            'shadow'        => 'rgba(90, 112, 128, 0.08)', // Ombres
            'is_dark'       => false,
        ),

        // ═══════════════════════════════════════════════════════════
        // FORÊT SAUGE - Nature et sérénité
        // Inspiration: Forêt alpine, sauge, verdure profonde
        // ═══════════════════════════════════════════════════════════

        'foret-sauge' => array(
            'primary'       => '#5A7A5E',    // Vert forêt
            'secondary'     => '#8AA88C',    // Sauge
            'accent'        => '#A08B60',    // Bois chaud accent
            'dark'          => '#1E3022',    // Vert très foncé (titres)
            'charcoal'      => '#2D4030',    // Forêt sombre
            'bg'            => '#F6F8F5',    // Blanc teinté sauge
            'text'          => '#354538',    // Vert-gris foncé texte
            'text_light'    => '#607565',    // Texte secondaire
            'content_bg'    => '#FFFFFF',    // Blanc pur
            'card_bg'       => '#FAFCFA',    // Fond cartes légèrement vert
            'card_border'   => '#DCE5DD',    // Bordure teintée verte
            'input_bg'      => '#FFFFFF',    // Fond inputs
            'input_border'  => '#C8D5CA',    // Bordure inputs
            'input_focus'   => '#5A7A5E',    // Focus inputs
            'input_text'    => '#1E3022',    // Texte inputs
            'btn_text'      => '#FFFFFF',    // Texte boutons
            'link_hover'    => '#3E5A42',    // Liens hover
            'divider'       => '#D8E2DA',    // Séparateurs
            'shadow'        => 'rgba(90, 122, 94, 0.08)', // Ombres
            'is_dark'       => false,
        ),
    );

    return isset($themes[$preset]) ? $themes[$preset] : $themes['marron-sobre'];
}

/**
 * Get typography fonts
 */
function chaletmontagne_get_typography_fonts($preset) {
    $fonts = array(
        // Serif + Sans-serif
        'playfair-montserrat' => array(
            'heading' => "'Playfair Display', Georgia, serif",
            'body'    => "'Montserrat', -apple-system, sans-serif",
        ),
        'cormorant-raleway' => array(
            'heading' => "'Cormorant Garamond', Georgia, serif",
            'body'    => "'Raleway', -apple-system, sans-serif",
        ),
        'dmserif-dmsans' => array(
            'heading' => "'DM Serif Display', Georgia, serif",
            'body'    => "'DM Sans', -apple-system, sans-serif",
        ),
        'lora-inter' => array(
            'heading' => "'Lora', Georgia, serif",
            'body'    => "'Inter', -apple-system, sans-serif",
        ),
        'crimsonpro-worksans' => array(
            'heading' => "'Crimson Pro', Georgia, serif",
            'body'    => "'Work Sans', -apple-system, sans-serif",
        ),
        // 100% Sans-serif
        'montserrat-inter' => array(
            'heading' => "'Montserrat', -apple-system, sans-serif",
            'body'    => "'Inter', -apple-system, sans-serif",
        ),
        'raleway-dmsans' => array(
            'heading' => "'Raleway', -apple-system, sans-serif",
            'body'    => "'DM Sans', -apple-system, sans-serif",
        ),
        'outfit-worksans' => array(
            'heading' => "'Outfit', -apple-system, sans-serif",
            'body'    => "'Work Sans', -apple-system, sans-serif",
        ),
    );

    return isset($fonts[$preset]) ? $fonts[$preset] : $fonts['playfair-montserrat'];
}

/**
 * AJAX handler to reset theme colors
 */
function chaletmontagne_ajax_reset_theme_colors() {
    // Security check
    check_ajax_referer('customize-controls', 'nonce');

    if (!current_user_can('edit_theme_options')) {
        wp_send_json_error('Unauthorized');
        return;
    }

    $preset = isset($_POST['preset']) ? sanitize_text_field(wp_unslash($_POST['preset'])) : '';
    $colors = chaletmontagne_get_luxury_colors($preset);

    if (!$colors) {
        wp_send_json_error('Invalid preset');
        return;
    }

    // Update all color theme mods
    $is_dark = isset($colors['is_dark']) && $colors['is_dark'];
    set_theme_mod('chaletmontagne_primary_color', $colors['primary']);
    set_theme_mod('chaletmontagne_secondary_color', $colors['secondary']);
    set_theme_mod('chaletmontagne_accent_color', $colors['accent']);
    set_theme_mod('chaletmontagne_text_color', $colors['text']);
    set_theme_mod('chaletmontagne_headings_color', $is_dark ? $colors['text'] : $colors['dark']);
    set_theme_mod('chaletmontagne_background_color', $colors['bg']);
    set_theme_mod('chaletmontagne_content_bg_color', $colors['content_bg']);

    wp_send_json_success(array(
        'colors' => $colors,
        'message' => 'Colors reset successfully'
    ));
}
add_action('wp_ajax_chaletmontagne_reset_colors', 'chaletmontagne_ajax_reset_theme_colors');

/**
 * Convert hex color to RGB values
 *
 * @param string $hex Hex color code
 * @return string RGB values as comma-separated string
 */
function chaletmontagne_hex_to_rgb($hex) {
    $hex = ltrim($hex, '#');

    if (strlen($hex) === 3) {
        $hex = $hex[0] . $hex[0] . $hex[1] . $hex[1] . $hex[2] . $hex[2];
    }

    $r = hexdec(substr($hex, 0, 2));
    $g = hexdec(substr($hex, 2, 2));
    $b = hexdec(substr($hex, 4, 2));

    return "{$r}, {$g}, {$b}";
}

/**
 * Output custom CSS for customizer settings
 * Complete rewrite with all color variables
 */
function chaletmontagne_customizer_css() {
    $luxury_preset = get_theme_mod('chaletmontagne_luxury_preset', 'marron-sobre');
    $typography_preset = get_theme_mod('chaletmontagne_typography_preset', 'playfair-montserrat');

    // Get all colors from preset
    $c = chaletmontagne_get_luxury_colors($luxury_preset);

    // Override with user-customized colors (if set)
    $custom_overrides = array(
        'primary'    => get_theme_mod('chaletmontagne_primary_color'),
        'secondary'  => get_theme_mod('chaletmontagne_secondary_color'),
        'accent'     => get_theme_mod('chaletmontagne_accent_color'),
        'text'       => get_theme_mod('chaletmontagne_text_color'),
        'bg'         => get_theme_mod('chaletmontagne_background_color'),
        'content_bg' => get_theme_mod('chaletmontagne_content_bg_color'),
    );
    foreach ($custom_overrides as $key => $value) {
        if ($value) {
            $c[$key] = $value;
        }
    }

    // Get typography
    $fonts = chaletmontagne_get_typography_fonts($typography_preset);

    // Check if dark theme
    $is_dark = isset($c['is_dark']) && $c['is_dark'];

    // Headings color: separate from $c['dark'] to avoid breaking --color-dark
    $headings_color_override = get_theme_mod('chaletmontagne_headings_color');
    $headings_color = $headings_color_override ? $headings_color_override : ($is_dark ? $c['text'] : $c['dark']);

    // Default values for backwards compatibility
    $text_light = isset($c['text_light']) ? $c['text_light'] : $c['text'];
    $card_bg = isset($c['card_bg']) ? $c['card_bg'] : $c['content_bg'];
    $card_border = isset($c['card_border']) ? $c['card_border'] : 'rgba(0,0,0,0.1)';
    $input_bg = isset($c['input_bg']) ? $c['input_bg'] : $c['content_bg'];
    $input_border = isset($c['input_border']) ? $c['input_border'] : $card_border;
    $input_focus = isset($c['input_focus']) ? $c['input_focus'] : $c['primary'];
    $input_text = isset($c['input_text']) ? $c['input_text'] : $c['text'];
    $btn_text = isset($c['btn_text']) ? $c['btn_text'] : '#FFFFFF';
    $link_hover = isset($c['link_hover']) ? $c['link_hover'] : $c['accent'];
    $divider = isset($c['divider']) ? $c['divider'] : $card_border;
    $shadow = isset($c['shadow']) ? $c['shadow'] : 'rgba(0,0,0,0.1)';

    ?>
    <style type="text/css">
        /* ═══════════════════════════════════════════════════════════
           CSS VARIABLES
        ═══════════════════════════════════════════════════════════ */
        :root {
            --color-primary: <?php echo esc_attr($c['primary']); ?>;
            --color-primary-rgb: <?php echo esc_attr(chaletmontagne_hex_to_rgb($c['primary'])); ?>;
            --color-secondary: <?php echo esc_attr($c['secondary']); ?>;
            --color-accent: <?php echo esc_attr($c['accent']); ?>;
            --color-dark: <?php echo esc_attr($c['dark']); ?>;
            --color-charcoal: <?php echo esc_attr($c['charcoal']); ?>;
            --color-bg: <?php echo esc_attr($c['bg']); ?>;
            --color-text: <?php echo esc_attr($c['text']); ?>;
            --color-text-light: <?php echo esc_attr($text_light); ?>;
            --color-content-bg: <?php echo esc_attr($c['content_bg']); ?>;
            --color-card-bg: <?php echo esc_attr($card_bg); ?>;
            --color-card-border: <?php echo esc_attr($card_border); ?>;
            --color-input-bg: <?php echo esc_attr($input_bg); ?>;
            --color-input-border: <?php echo esc_attr($input_border); ?>;
            --color-input-focus: <?php echo esc_attr($input_focus); ?>;
            --color-input-text: <?php echo esc_attr($input_text); ?>;
            --color-btn-text: <?php echo esc_attr($btn_text); ?>;
            --color-link-hover: <?php echo esc_attr($link_hover); ?>;
            --color-divider: <?php echo esc_attr($divider); ?>;
            --shadow-color: <?php echo esc_attr($shadow); ?>;
            --font-heading: <?php echo wp_strip_all_tags($fonts['heading']); ?>;
            --font-body: <?php echo wp_strip_all_tags($fonts['body']); ?>;
<?php $hero_title_size = absint(get_theme_mod('chaletmontagne_hero_title_size', 0)); if ($hero_title_size > 0) : ?>
            --hero-title-size: min(<?php echo esc_attr($hero_title_size); ?>px, 9vw);
<?php endif; ?>
        }

        /* ═══════════════════════════════════════════════════════════
           BASE STYLES
        ═══════════════════════════════════════════════════════════ */
        body {
            font-family: var(--font-body);
            background-color: var(--color-bg);
            color: var(--color-text);
            font-weight: 300;
            line-height: 1.7;
        }

        /* ═══════════════════════════════════════════════════════════
           TYPOGRAPHY
        ═══════════════════════════════════════════════════════════ */
        h1, h2, h3, h4, h5, h6 {
            font-family: var(--font-heading);
            font-weight: 400;
            letter-spacing: -0.02em;
            color: <?php echo esc_attr($headings_color); ?>;
            line-height: 1.3;
        }

        h1 { font-size: 2.5rem; }
        h2 { font-size: 2rem; }
        h3 { font-size: 1.5rem; }
        h4 { font-size: 1.25rem; }
        h5 { font-size: 1.1rem; }
        h6 { font-size: 1rem; }

        .entry-title,
        .page-title,
        .entry-header h1,
        .page-header h1 {
            color: <?php echo esc_attr($headings_color); ?>;
            padding-left: 1rem;
        }

        .widget-title {
            color: <?php echo esc_attr($headings_color); ?>;
            font-size: 1.1rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.05em;
        }

        p, li, td, th {
            color: var(--color-text);
        }

        .text-muted,
        .entry-meta,
        .post-date,
        figcaption {
            color: var(--color-text-light);
        }

        /* ═══════════════════════════════════════════════════════════
           LINKS
        ═══════════════════════════════════════════════════════════ */
        a {
            color: var(--color-primary);
            text-decoration: none;
            transition: color 0.3s ease;
        }

        a:hover,
        a:focus {
            color: var(--color-link-hover);
        }

        /* ═══════════════════════════════════════════════════════════
           HEADER & NAVIGATION
        ═══════════════════════════════════════════════════════════ */
        .site-header {
            background-color: var(--color-content-bg);
            border-bottom: 1px solid var(--color-divider);
        }

        .site-title a,
        .site-title a:hover {
            color: <?php echo esc_attr($headings_color); ?>;
        }

        .main-navigation a {
            color: <?php echo esc_attr($headings_color); ?>;
            font-weight: 400;
        }

        .main-navigation a:hover,
        .main-navigation a:focus,
        .main-navigation .current-menu-item > a {
            color: var(--color-primary);
        }

        .main-navigation ul ul {
            background-color: var(--color-card-bg);
            border: 1px solid var(--color-card-border);
            box-shadow: 0 10px 30px var(--shadow-color);
        }

        .main-navigation ul ul a {
            color: <?php echo esc_attr($headings_color); ?>;
        }

        /* ═══════════════════════════════════════════════════════════
           BUTTONS
        ═══════════════════════════════════════════════════════════ */
        .button,
        button,
        input[type="submit"],
        input[type="button"],
        .btn-primary,
        .luxury-btn {
            background-color: var(--color-primary);
            color: var(--color-btn-text);
            border: 2px solid var(--color-primary);
            padding: 0.875rem 2rem;
            font-family: var(--font-body);
            font-weight: 500;
            font-size: 0.9rem;
            letter-spacing: 0.03em;
            text-transform: uppercase;
            border-radius: 4px;
            cursor: pointer;
            /*transition: all 0.3s ease;*/
        }

        .fc .fc-button {
            transition: none;
            transform: none;
        }

        .button:hover,
        button:hover,
        input[type="submit"]:hover,
        input[type="button"]:hover,
        .btn-primary:hover,
        .luxury-btn:hover {
            /*background-color: var(--color-accent);*/
            border-color: var(--color-accent);
            color: var(--color-btn-text);
            transform: translateY(-2px);
            box-shadow: 0 8px 25px var(--shadow-color);
        }

        .fc .fc-button:hover {
            transform: none;
            box-shadow: none;
        }

        .btn-secondary,
        .button-secondary {
            background-color: transparent;
            color: var(--color-primary);
            border: 2px solid var(--color-primary);
        }

        .btn-secondary:hover,
        .button-secondary:hover {
            background-color: var(--color-primary);
            color: var(--color-btn-text);
        }

        /* ═══════════════════════════════════════════════════════════
           FORMS & INPUTS
        ═══════════════════════════════════════════════════════════ */
        input[type="text"],
        input[type="email"],
        input[type="url"],
        input[type="password"],
        input[type="search"],
        input[type="number"],
        input[type="tel"],
        input[type="date"],
        textarea,
        select {
            background-color: var(--color-input-bg);
            color: var(--color-input-text);
            border: 1px solid var(--color-input-border);
            padding: 0.875rem 1rem;
            font-family: var(--font-body);
            font-size: 1rem;
            border-radius: 4px;
            transition: border-color 0.3s ease, box-shadow 0.3s ease;
            width: 100%;
        }

        input[type="text"]:focus,
        input[type="email"]:focus,
        input[type="url"]:focus,
        input[type="password"]:focus,
        input[type="search"]:focus,
        input[type="number"]:focus,
        input[type="tel"]:focus,
        input[type="date"]:focus,
        textarea:focus,
        select:focus {
            outline: none;
            border-color: var(--color-input-focus);
            box-shadow: 0 0 0 3px <?php echo esc_attr($c['primary']); ?>20;
        }

        input::placeholder,
        textarea::placeholder {
            color: var(--color-text-light);
            opacity: 0.7;
        }

        label {
            color: <?php echo esc_attr($headings_color); ?>;
            font-weight: 500;
            font-size: 0.9rem;
            margin-bottom: 0.5rem;
            display: block;
        }

        /* ═══════════════════════════════════════════════════════════
           CARDS & CONTENT BOXES
        ═══════════════════════════════════════════════════════════ */
        .site-content,
        .entry-content,
        article {
            background-color: var(--color-content-bg);
        }

        .site-content {
            padding: 20px 0 40px;
        }

        .luxury-card,
        .card,
        .post-card {
            background-color: var(--color-card-bg);
            border: 1px solid var(--color-card-border);
            border-radius: 8px;
            box-shadow: 0 4px 20px var(--shadow-color);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
            overflow: hidden;
        }

        .luxury-card:hover,
        .card:hover,
        .post-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 12px 40px var(--shadow-color);
        }

        .luxury-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
        }

        .luxury-card-title,
        .card-title {
            color: <?php echo esc_attr($headings_color); ?>;
            font-family: var(--font-heading);
        }

        .luxury-card-link {
            color: var(--color-primary);
        }

        .luxury-card-link:hover {
            color: var(--color-link-hover);
        }

        /* ═══════════════════════════════════════════════════════════
           HERO SECTION
        ═══════════════════════════════════════════════════════════ */
        .hero-section {
            background: linear-gradient(135deg, var(--color-dark) 0%, var(--color-charcoal) 100%);
        }

        .hero-title {
            color: #FFFFFF;
            font-family: var(--font-heading);
        }

        .hero-subtitle {
            color: rgba(255, 255, 255, 0.85);
        }

        /* ═══════════════════════════════════════════════════════════
           BREADCRUMBS
        ═══════════════════════════════════════════════════════════ */
        .breadcrumbs {
            color: var(--color-text-light);
            font-size: 0.9rem;
        }

        .breadcrumbs a {
            color: var(--color-text-light);
        }

        .breadcrumbs a:hover {
            color: var(--color-primary);
        }

        .breadcrumb-separator {
            color: var(--color-text-light);
            opacity: 0.5;
        }

        .breadcrumb-current {
            color: var(--color-text);
        }

        /* ═══════════════════════════════════════════════════════════
           FOOTER
        ═══════════════════════════════════════════════════════════ */
        .site-footer {
            background-color: <?php echo $is_dark ? esc_attr($c['charcoal']) : esc_attr($c['dark']); ?>;
            color: rgba(255, 255, 255, 0.85);
        }

        .site-footer a {
            color: <?php echo $is_dark ? esc_attr($c['primary']) : esc_attr($c['secondary']); ?>;
        }

        .site-footer a:hover {
            color: #FFFFFF;
        }

        .footer-top-bar {
            background: linear-gradient(90deg, var(--color-primary) 0%, var(--color-accent) 100%);
        }

        .footer-widget .widget-title {
            color: #FFFFFF;
            border-bottom: 1px solid rgba(255, 255, 255, 0.15);
            padding-bottom: 0.75rem;
            margin-bottom: 1rem;
        }

        .site-footer .site-info,
        .site-footer .site-info p,
        .site-footer .footer-text,
        .site-footer .footer-text p {
            color: rgba(255, 255, 255, 0.6);
        }

        .site-footer .footer-legal {
            margin-top: 0.5rem;
        }

        .site-footer .footer-legal a {
            color: rgba(255, 255, 255, 0.6);
        }

        .site-footer .footer-legal a:hover {
            color: #FFFFFF;
        }

        .site-footer .legal-separator {
            margin: 0 0.5rem;
            opacity: 0.4;
        }

        .site-footer .theme-credit,
        .site-footer .theme-credit a {
            color: rgba(255, 255, 255, 0.45);
        }

        .site-footer .theme-credit a:hover {
            color: rgba(255, 255, 255, 0.8);
        }

        /* ═══════════════════════════════════════════════════════════
           WIDGETS
        ═══════════════════════════════════════════════════════════ */
        .widget {
            background-color: transparent;
        }

        .widget ul li {
            border-bottom: 1px solid var(--color-divider);
        }

        .widget ul li:last-child {
            border-bottom: none;
        }

        /* ═══════════════════════════════════════════════════════════
           LUXURY ELEMENTS
        ═══════════════════════════════════════════════════════════ */
        .luxury-badge {
            border: 1px solid var(--color-primary);
            color: var(--color-primary);
            background-color: transparent;
            padding: 0.25rem 0.75rem;
            font-size: 0.75rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.1em;
        }

        .luxury-section-subtitle {
            color: var(--color-primary);
            font-family: var(--font-body);
            font-size: 0.85rem;
            font-weight: 500;
            text-transform: uppercase;
            letter-spacing: 0.15em;
        }

        .luxury-form {
            background-color: var(--color-card-bg);
            border: 1px solid var(--color-card-border);
            padding: 2rem;
            border-radius: 8px;
        }

        .luxury-info-item {
            background-color: var(--color-card-bg);
            border: 1px solid var(--color-card-border);
            padding: 1.5rem;
            border-radius: 8px;
        }

        /* ═══════════════════════════════════════════════════════════
           TABLES
        ═══════════════════════════════════════════════════════════ */
        table {
            border-collapse: collapse;
            width: 100%;
        }

        th, td {
            padding: 0.75rem 1rem;
            border: 1px solid var(--color-divider);
            text-align: left;
        }

        th {
            background-color: rgba(var(--color-primary-rgb), 0.08) !important;
            font-weight: 500;
            color: <?php echo esc_attr($headings_color); ?>;
        }

        tr:nth-child(even) {
            background-color: <?php echo $is_dark ? 'rgba(255,255,255,0.02)' : 'rgba(0,0,0,0.02)'; ?>;
        }

        /* ═══════════════════════════════════════════════════════════
           BLOCKQUOTES & CODE
        ═══════════════════════════════════════════════════════════ */
        blockquote {
            border-left: 4px solid var(--color-primary);
            padding-left: 1.5rem;
            margin: 1.5rem 0;
            color: var(--color-text-light);
            font-style: italic;
        }

        code, pre {
            background-color: <?php echo $is_dark ? esc_attr($c['charcoal']) : esc_attr($c['bg']); ?>;
            border: 1px solid var(--color-divider);
            border-radius: 4px;
            font-family: 'Fira Code', 'Consolas', monospace;
            font-size: 0.9rem;
        }

        code {
            padding: 0.125rem 0.375rem;
        }

        pre {
            padding: 1rem;
            overflow-x: auto;
        }

        /* ═══════════════════════════════════════════════════════════
           SCROLLBAR (for dark themes)
        ═══════════════════════════════════════════════════════════ */
        <?php if ($is_dark) : ?>
        ::-webkit-scrollbar {
            width: 10px;
        }

        ::-webkit-scrollbar-track {
            background: var(--color-bg);
        }

        ::-webkit-scrollbar-thumb {
            background: var(--color-charcoal);
            border-radius: 5px;
        }

        ::-webkit-scrollbar-thumb:hover {
            background: var(--color-primary);
        }
        <?php endif; ?>

        /* ═══════════════════════════════════════════════════════════
           SELECTION
        ═══════════════════════════════════════════════════════════ */
        ::selection {
            background-color: var(--color-primary);
            color: var(--color-btn-text);
        }

        <?php
        // ═══════════════════════════════════════════════════════════
        // THEME-SPECIFIC EFFECTS
        // ═══════════════════════════════════════════════════════════
        $effect = isset($c['effect']) ? $c['effect'] : '';

        if ($effect === 'wood-light') :
        ?>
        /* Chalet Miel - Subtle wood texture */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-image:
                repeating-linear-gradient(
                    90deg,
                    rgba(184, 134, 11, 0.015) 0px,
                    transparent 1px,
                    transparent 60px,
                    rgba(184, 134, 11, 0.015) 61px
                );
            pointer-events: none;
            z-index: -1;
        }
        <?php elseif ($effect === 'wood-dark') : ?>
        /* Chalet Noyer - Rich wood grain */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background-image:
                repeating-linear-gradient(
                    90deg,
                    rgba(196, 152, 90, 0.03) 0px,
                    transparent 1px,
                    transparent 40px,
                    rgba(196, 152, 90, 0.03) 41px
                ),
                repeating-linear-gradient(
                    0deg,
                    rgba(196, 152, 90, 0.02) 0px,
                    transparent 2px,
                    transparent 80px,
                    rgba(196, 152, 90, 0.02) 82px
                );
            pointer-events: none;
            z-index: -1;
        }

        /* Golden accents for headings */
        h1, h2, h3 {
            color: <?php echo esc_attr($c['accent']); ?>;
        }
        <?php elseif ($effect === 'subtle-glow') : ?>
        /* Nuit Anthracite - Subtle glow effect */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background:
                radial-gradient(ellipse at 10% 10%, rgba(143, 164, 176, 0.08) 0%, transparent 50%),
                radial-gradient(ellipse at 90% 90%, rgba(201, 184, 150, 0.05) 0%, transparent 50%);
            pointer-events: none;
            z-index: -1;
        }
        <?php elseif ($effect === 'gold-shimmer') : ?>
        /* Luxe Absolu - Gold shimmer pattern */
        body::before {
            content: '';
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            background:
                repeating-linear-gradient(
                    45deg,
                    transparent,
                    transparent 100px,
                    rgba(212, 175, 55, 0.02) 100px,
                    rgba(212, 175, 55, 0.02) 200px
                ),
                radial-gradient(ellipse at 50% 0%, rgba(212, 175, 55, 0.08) 0%, transparent 50%);
            pointer-events: none;
            z-index: -1;
        }

        /* Gold gradient headings */
        h1, h2, h3 {
            background: linear-gradient(135deg, <?php echo esc_attr($c['secondary']); ?> 0%, <?php echo esc_attr($c['primary']); ?> 50%, <?php echo esc_attr($c['accent']); ?> 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }

        .luxury-card {
            border: 1px solid rgba(212, 175, 55, 0.15);
        }

        .luxury-card:hover {
            border-color: rgba(212, 175, 55, 0.3);
        }
        <?php endif; ?>
    </style>
    <?php
}
add_action('wp_head', 'chaletmontagne_customizer_css');
