<footer id="colophon" class="site-footer">
    <div class="container">
        <!-- 1. OBERER BEREICH: Widgets -->
        <div class="footer-widgets">
            <?php if ( is_active_sidebar( 'footer-1' ) ) : ?>
                <div class="footer-widget"><?php dynamic_sidebar( 'footer-1' ); ?></div>
            <?php endif; ?>
            <?php if ( is_active_sidebar( 'footer-2' ) ) : ?>
                <div class="footer-widget"><?php dynamic_sidebar( 'footer-2' ); ?></div>
            <?php endif; ?>
            <?php if ( is_active_sidebar( 'footer-3' ) ) : ?>
                <div class="footer-widget"><?php dynamic_sidebar( 'footer-3' ); ?></div>
            <?php endif; ?>
        </div>

        <!-- 2. UNTERER BEREICH: Menü, Copyright, Legal -->
        <div class="footer-bottom-bar">
            
            <div class="footer-left-group">
                <!-- Copyright -->
                <div class="site-info">
                    <?php
                    $copyright_text = get_theme_mod( 'footer_copyright', '&copy; ' . date('Y') . ' ' . get_bloginfo('name') );
                    
                    if ( get_theme_mod('show_footer_credit', true) ) {
                        $full_footer_text = $copyright_text . ' <span class="footer-separator">|</span> <span class="footer-credit">
                            <a href="https://m-viper.de" target="_blank" rel="noopener noreferrer">
                                Minecraft Theme by M_Viper
                            </a>
                        </span>';
                    } else {
                        $full_footer_text = $copyright_text;
                    }
                    echo '<p>' . wp_kses_post( $full_footer_text ) . '</p>';
                    ?>
                </div>

                <!-- Footer Menü ( falls vorhanden ) -->
                <?php if ( has_nav_menu( 'footer' ) ) : ?>
                    <nav class="footer-navigation">
                        <?php
                        wp_nav_menu(
                            array(
                                'theme_location' => 'footer',
                                'menu_class'     => 'footer-menu',
                                'container'      => false,
                                'depth'          => 1, // Nur eine Ebene
                            )
                        );
                        ?>
                    </nav>
                <?php endif; ?>
            </div>

            <div class="footer-right-group">
                <!-- Impressum & Datenschutz -->
                <div class="footer-legal-links">
                    <?php
                    $impressum_url = get_theme_mod('footer_impressum_url');
                    $datenschutz_url = get_theme_mod('footer_datenschutz_url');
                    $links = array();

                    if (!empty($impressum_url)) {
                        $links[] = '<a href="' . esc_url($impressum_url) . '"><i class="fas fa-info-circle"></i> Impressum</a>';
                    }

                    if (!empty($datenschutz_url)) {
                        $links[] = '<a href="' . esc_url($datenschutz_url) . '"><i class="fas fa-shield-alt"></i> Datenschutz</a>';
                    }

                    if (!empty($links)) {
                        echo implode('', $links); // Kein Trennzeichen mehr, da wir Icons haben
                    }
                    ?>
                </div>
            </div>

        </div> <!-- Ende footer-bottom-bar -->
    </div> <!-- Ende Container -->
    
    <!-- THEME TOGGLE (Fixiert unten rechts) -->
    <button class="theme-toggle" aria-label="Dark/Light Mode umschalten" title="Dark / Light Mode">
        <div class="theme-toggle-icons">
            <svg class="icon-moon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>
            </svg>
            <svg class="icon-sun" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
                <circle cx="12" cy="12" r="5"/>
                <line x1="12" y1="1" x2="12" y2="3"/>
                <line x1="12" y1="21" x2="12" y2="23"/>
                <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"/>
                <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"/>
                <line x1="1" y1="12" x2="3" y2="12"/>
                <line x1="21" y1="12" x2="23" y2="12"/>
                <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"/>
                <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"/>
            </svg>
        </div>
    </button>
</footer>
<?php wp_footer(); ?>
</body>
</html>