{% extends "base.html" %}

{% block title %}Mercedes-Benz TBA Marienfelde - Steckdosen-Steuerung für 3D-Drucker{% endblock %}

{% block extra_css %}
<style>
    /* Mercedes-Benz Corporate Design */
    .text-mercedes-black { color: #000000; }
    .text-mercedes-gray { color: #6b7280; }
    .text-mercedes-silver { color: #9ca3af; }
    .text-mercedes-blue { color: #0073ce; }
    .text-mercedes-green { color: #008c32; }
    .text-mercedes-red { color: #dc2626; }
    
    .bg-mercedes-black { background-color: #000000; }
    .bg-mercedes-silver { background-color: #e5e7eb; }
    .bg-mercedes-blue { background-color: #0073ce; }
    .bg-mercedes-green { background-color: #008c32; }
    
    /* Enhanced Hero Section */
    .hero-section {
        background: linear-gradient(135deg, #0f172a 0%, #1e3a8a 50%, #1e40af 100%);
        position: relative;
        overflow: hidden;
        min-height: 80vh;
    }
    
    .hero-section::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: radial-gradient(circle at 30% 30%, rgba(59, 130, 246, 0.3) 0%, transparent 50%),
                    radial-gradient(circle at 70% 70%, rgba(168, 85, 247, 0.2) 0%, transparent 50%);
        animation: heroFloat 20s ease-in-out infinite;
    }
    
    @keyframes heroFloat {
        0%, 100% { transform: scale(1) rotate(0deg); }
        50% { transform: scale(1.1) rotate(5deg); }
    }
    
    .hero-section::after {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'%3E%3Cg fill-opacity='0.05'%3E%3Cpath d='M11 18c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm48 25c3.866 0 7-3.134 7-7s-3.134-7-7-7-7 3.134-7 7 3.134 7 7 7zm-43-7c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm63 31c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM34 90c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zm56-76c1.657 0 3-1.343 3-3s-1.343-3-3-3-3 1.343-3 3 1.343 3 3 3zM12 86c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm28-65c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm23-11c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-6 60c2.21 0 4-1.79 4-4s-1.79-4-4-4-4 1.79-4 4 1.79 4 4 4zm29 22c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zM32 63c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm57-13c2.76 0 5-2.24 5-5s-2.24-5-5-5-5 2.24-5 5 2.24 5 5 5zm-9-21c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM60 91c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM35 41c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2zM12 60c1.105 0 2-.895 2-2s-.895-2-2-2-2 .895-2 2 .895 2 2 2z' fill='%23ffffff'/%3E%3C/g%3E%3C/svg%3E");
        animation: patternMove 60s linear infinite;
    }
    
    @keyframes patternMove {
        0% { transform: translateX(-100px) translateY(-100px); }
        100% { transform: translateX(100px) translateY(100px); }
    }
    
    /* Mercedes Logo Animation */
    .mercedes-logo {
        animation: logoSpin 20s linear infinite;
        filter: drop-shadow(0 8px 16px rgba(255, 255, 255, 0.1));
    }
    
    @keyframes logoSpin {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Enhanced Cards */
    .mercedes-feature-card {
        background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
        border: 1px solid #e5e7eb;
        box-shadow: 
            0 10px 25px -5px rgba(0, 0, 0, 0.1),
            0 4px 6px -2px rgba(0, 0, 0, 0.05);
        transition: all 0.3s ease;
        backdrop-filter: blur(10px);
        border-radius: 16px;
        position: relative;
        overflow: hidden;
    }
    
    .dark .mercedes-feature-card {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        border-color: #334155;
        box-shadow: 
            0 10px 25px -5px rgba(0, 0, 0, 0.3),
            0 4px 6px -2px rgba(0, 0, 0, 0.2);
    }
    
    .mercedes-feature-card::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(0, 115, 206, 0.1), transparent);
        transition: left 0.5s;
    }
    
    .mercedes-feature-card:hover::before {
        left: 100%;
    }
    
    .mercedes-feature-card:hover {
        transform: translateY(-8px) scale(1.02);
        box-shadow: 
            0 25px 50px -12px rgba(0, 0, 0, 0.25),
            0 8px 16px -4px rgba(0, 0, 0, 0.1);
    }
    
    .dark .mercedes-feature-card:hover {
        box-shadow: 
            0 25px 50px -12px rgba(0, 0, 0, 0.5),
            0 8px 16px -4px rgba(0, 0, 0, 0.3);
    }
    
    /* Icon Animations */
    .feature-icon {
        transition: all 0.3s ease;
        position: relative;
    }
    
    .mercedes-feature-card:hover .feature-icon {
        transform: scale(1.15) rotate(5deg);
    }
    
    /* Enhanced Statistics Section */
    .stats-section {
        background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
        position: relative;
        overflow: hidden;
    }
    
    .dark .stats-section {
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
    }
    
    .stats-section::before {
        content: '';
        position: absolute;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background: radial-gradient(circle at 20% 80%, rgba(0, 115, 206, 0.1) 0%, transparent 50%),
                    radial-gradient(circle at 80% 20%, rgba(16, 185, 129, 0.1) 0%, transparent 50%);
    }
    
    .stat-card {
        background: rgba(255, 255, 255, 0.8);
        backdrop-filter: blur(10px);
        border: 1px solid rgba(255, 255, 255, 0.2);
        border-radius: 16px;
        padding: 2rem;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
    }
    
    .dark .stat-card {
        background: rgba(30, 41, 59, 0.8);
        border-color: rgba(71, 85, 105, 0.3);
    }
    
    .stat-card:hover {
        transform: translateY(-4px);
        box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.2);
    }
    
    .stat-number {
        font-size: 3rem;
        font-weight: 700;
        background: linear-gradient(45deg, #0073ce, #16a34a);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
        background-clip: text;
        animation: numberPulse 2s ease-in-out infinite;
    }
    
    @keyframes numberPulse {
        0%, 100% { transform: scale(1); }
        50% { transform: scale(1.05); }
    }
    
    /* Process Steps Enhancement */
    .process-step {
        position: relative;
        z-index: 1;
    }
    
    .process-step-number {
        background: linear-gradient(135deg, #0073ce 0%, #1e40af 100%);
        box-shadow: 0 8px 16px rgba(0, 115, 206, 0.3);
        transition: all 0.3s ease;
    }
    
    .process-step:hover .process-step-number {
        transform: scale(1.1);
        box-shadow: 0 12px 24px rgba(0, 115, 206, 0.4);
    }
    
    /* CTA Section Enhancement */
    .cta-section {
        background: linear-gradient(135deg, #ffffff 0%, #f1f5f9 100%);
        border: 1px solid #e2e8f0;
        box-shadow: 
            0 20px 40px -12px rgba(0, 0, 0, 0.1),
            0 8px 16px -4px rgba(0, 0, 0, 0.05);
        position: relative;
        overflow: hidden;
    }
    
    .dark .cta-section {
        background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
        border-color: #334155;
    }
    
    .cta-section::before {
        content: '';
        position: absolute;
        top: -50%;
        left: -50%;
        width: 200%;
        height: 200%;
        background: conic-gradient(from 0deg, transparent, rgba(0, 115, 206, 0.1), transparent);
        animation: ctaRotate 20s linear infinite;
    }
    
    @keyframes ctaRotate {
        0% { transform: rotate(0deg); }
        100% { transform: rotate(360deg); }
    }
    
    /* Enhanced Buttons */
    .btn-primary {
        background: linear-gradient(135deg, #0073ce 0%, #1e40af 100%);
        border: none;
        color: white;
        padding: 0.75rem 2rem;
        border-radius: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        transition: all 0.3s ease;
        position: relative;
        overflow: hidden;
        display: inline-flex;
        align-items: center;
        text-decoration: none;
        box-shadow: 0 4px 14px 0 rgba(0, 115, 206, 0.39);
    }
    
    .btn-primary::before {
        content: '';
        position: absolute;
        top: 0;
        left: -100%;
        width: 100%;
        height: 100%;
        background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent);
        transition: left 0.5s;
    }
    
    .btn-primary:hover::before {
        left: 100%;
    }
    
    .btn-primary:hover {
        transform: translateY(-2px);
        box-shadow: 0 8px 25px 0 rgba(0, 115, 206, 0.5);
    }
    
    .btn-secondary {
        background: transparent;
        border: 2px solid #0073ce;
        color: #0073ce;
        padding: 0.75rem 2rem;
        border-radius: 12px;
        font-weight: 600;
        text-transform: uppercase;
        letter-spacing: 0.5px;
        transition: all 0.3s ease;
        display: inline-flex;
        align-items: center;
        text-decoration: none;
    }
    
    .btn-secondary:hover {
        background: #0073ce;
        color: white;
        transform: translateY(-2px);
    }
    
    .dark .btn-secondary {
        border-color: #60a5fa;
        color: #60a5fa;
    }
    
    .dark .btn-secondary:hover {
        background: #60a5fa;
        color: #1e293b;
    }
    
    /* Loading States */
    .loading-skeleton {
        background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
        background-size: 200% 100%;
        animation: loading 2s infinite;
    }
    
    .dark .loading-skeleton {
        background: linear-gradient(90deg, #374151 25%, #4b5563 50%, #374151 75%);
        background-size: 200% 100%;
    }
    
    @keyframes loading {
        0% { background-position: 200% 0; }
        100% { background-position: -200% 0; }
    }
    
    /* Responsive Design */
    @media (max-width: 768px) {
        .hero-section {
            min-height: 60vh;
            padding: 2rem 1rem;
        }
        
        .mercedes-feature-card {
            margin: 0 1rem;
        }
        
        .stat-number {
            font-size: 2rem;
        }
        
        .process-step-number {
            width: 48px;
            height: 48px;
            font-size: 1rem;
        }
    }
    
    /* Accessibility Enhancements */
    @media (prefers-reduced-motion: reduce) {
        *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
    
    /* Focus States */
    .btn-primary:focus,
    .btn-secondary:focus {
        outline: 2px solid #0073ce;
        outline-offset: 2px;
    }
</style>
{% endblock %}

{% block content %}
<div class="space-y-16">
    <!-- Enhanced Hero Section -->
    <div class="hero-section relative overflow-hidden text-white rounded-3xl">
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-20 z-10">
            <div class="text-center">
                <!-- Mercedes-Benz Logo -->
                <div class="mercedes-logo inline-flex items-center justify-center w-28 h-28 bg-white/10 backdrop-blur-sm rounded-full mb-8 border border-white/20">
                    <svg class="w-14 h-14 text-white" viewBox="0 0 80 80" fill="currentColor">
                        <path d="M58.6,4.5C53,1.6,46.7,0,40,0c-6.7,0-13,1.6-18.6,4.5v0C8.7,11.2,0,24.6,0,40c0,15.4,8.7,28.8,21.5,35.5
                        C27,78.3,33.3,80,40,80c6.7,0,12.9-1.7,18.5-4.6C71.3,68.8,80,55.4,80,40C80,24.6,71.3,11.2,58.6,4.5z M4,40
                        c0-13.1,7-24.5,17.5-30.9v0C26.6,6,32.5,4.2,39,4l-4.5,32.7L21.5,46.8v0L8.3,57.1C5.6,52,4,46.2,4,40z M58.6,70.8
                        C53.1,74.1,46.8,76,40,76c-6.8,0-13.2-1.9-18.6-5.2c-4.9-2.9-8.9-6.9-11.9-11.7l11.9-4.9v0L40,46.6l18.6,7.5v0l12,4.9
                        C67.6,63.9,63.4,67.9,58.6,70.8z M58.6,46.8L58.6,46.8l-12.9-10L41.1,4c6.3,0.2,12.3,2,17.4,5.1v0C69,15.4,76,26.9,76,40
                        c0,6.2-1.5,12-4.3,17.1L58.6,46.8z"/>
                    </svg>
                </div>
                
                <h1 class="text-6xl md:text-8xl font-bold mb-6 tracking-tight">
                    <span class="bg-gradient-to-r from-white via-blue-200 to-white bg-clip-text text-transparent">
                        TBA Platform
                    </span>
                </h1>
                <p class="text-xl md:text-2xl text-blue-100 max-w-4xl mx-auto leading-relaxed mb-4">
                    <strong>Das Beste oder nichts</strong> - Intelligente Steckdosen-Steuerung für 3D-Drucker in der Mercedes-Benz Technischen Berufsausbildung Werk Marienfelde
                </p>
                <p class="text-lg md:text-xl text-blue-200 max-w-3xl mx-auto leading-relaxed mb-12">
                    Sichere Ein-/Ausschaltung und Reservierungsmanagement. Ausbilder-geprüfte Anträge für höchste Sicherheit und Qualität.
                </p>
                
                <!-- Enhanced CTA Buttons -->
                <div class="flex flex-col sm:flex-row justify-center gap-6 mb-8">
                    {% if current_user.is_authenticated %}
                    <a href="{{ url_for('dashboard') if url_for else '/dashboard' }}" 
                       class="btn-primary group">
                        <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2H5a2 2 0 00-2-2z"/>
                        </svg>
                        Zum Dashboard
                    </a>
                    {% else %}
                    <a href="{{ url_for('login') if url_for else '/login' }}" 
                       class="btn-primary group">
                        <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>
                        </svg>
                        Jetzt Anmelden
                    </a>
                    {% endif %}
                    <a href="{{ url_for('guest.guest_request_form') if url_for else '/guest-request' }}" 
                       class="btn-secondary group text-white">
                        <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                        </svg>
                        Antrag für Nutzung stellen
                    </a>
                </div>
                
            </div>
        </div>
    </div>

    <!-- Enhanced Features Section -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="text-center mb-16">
            <h2 class="text-5xl font-bold text-mercedes-black dark:text-white mb-6">
                Mercedes-Benz TBA: Sichere Drucker-Steckdosen-Verwaltung
            </h2>
            <p class="text-xl text-mercedes-gray dark:text-slate-400 max-w-4xl mx-auto leading-relaxed">
                Unser Steckdosen-Management-System ermöglicht die sichere Steuerung von 3D-Drucker-Steckdosen in der Technischen Berufsausbildung. 
                Ausbilder-überwachte Genehmigungsprozesse für <strong>höchste Sicherheitsstandards</strong> im Werk Marienfelde.
            </p>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
            <!-- Enhanced Feature 1 -->
            <div class="mercedes-feature-card p-8 text-center group">
                <div class="feature-icon w-20 h-20 bg-gradient-to-br from-blue-100 to-blue-200 dark:from-blue-900/30 dark:to-blue-800/30 rounded-xl flex items-center justify-center mx-auto mb-6">
                    <svg class="w-10 h-10 text-mercedes-blue" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
                    </svg>
                </div>
                <h3 class="text-2xl font-bold text-mercedes-black dark:text-white mb-4">Sichere Steckdosen-Steuerung</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed">
                    Kontrollierte Ein- und Ausschaltung von 3D-Drucker-Steckdosen mit Echtzeit-Status 
                    und Sicherheitsprotokollen für die Ausbildungswerkstatt.
                </p>
                <div class="mt-6 flex justify-center">
                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800 dark:bg-blue-900/30 dark:text-blue-300">
                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
                        </svg>
                        Sicher
                    </span>
                </div>
            </div>
            
            <!-- Enhanced Feature 2 -->
            <div class="mercedes-feature-card p-8 text-center group">
                <div class="feature-icon w-20 h-20 bg-gradient-to-br from-green-100 to-green-200 dark:from-green-900/30 dark:to-green-800/30 rounded-xl flex items-center justify-center mx-auto mb-6">
                    <svg class="w-10 h-10 text-mercedes-green" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"/>
                    </svg>
                </div>
                <h3 class="text-2xl font-bold text-mercedes-black dark:text-white mb-4">Ausbilder-geprüfte Reservierungen</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed">
                    Strukturiertes Reservierungssystem mit Ausbilder-Genehmigung für optimale Ressourcenverteilung 
                    und sichere Nutzung in der TBA.
                </p>
                <div class="mt-6 flex justify-center">
                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800 dark:bg-green-900/30 dark:text-green-300">
                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                        </svg>
                        Ausbilder-geprüft
                    </span>
                </div>
            </div>
            
            <!-- Enhanced Feature 3 -->
            <div class="mercedes-feature-card p-8 text-center group">
                <div class="feature-icon w-20 h-20 bg-gradient-to-br from-purple-100 to-purple-200 dark:from-purple-900/30 dark:to-purple-800/30 rounded-xl flex items-center justify-center mx-auto mb-6">
                    <svg class="w-10 h-10 text-purple-600 dark:text-purple-400" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
                    </svg>
                </div>
                <h3 class="text-2xl font-bold text-mercedes-black dark:text-white mb-4">TBA-Nutzungsstatistiken</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed">
                    Detaillierte Auswertungen der Steckdosen-Nutzung und Reservierungsstatistiken zur 
                    Optimierung der Ausbildungsabläufe im Werk Marienfelde.
                </p>
                <div class="mt-6 flex justify-center">
                    <span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-purple-100 text-purple-800 dark:bg-purple-900/30 dark:text-purple-300">
                        <svg class="w-4 h-4 mr-1" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"/>
                        </svg>
                        TBA-optimiert
                    </span>
                </div>
            </div>
        </div>
    </div>

    <!-- Enhanced Statistics Section -->
    <div class="stats-section rounded-3xl mx-4 relative">
        <div class="relative max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-16 z-10">
            <div class="text-center mb-12">
                <h2 class="text-4xl font-bold text-mercedes-black dark:text-white mb-4">
                    Leistung in Zahlen
                </h2>
                <p class="text-lg text-mercedes-gray dark:text-slate-400">
                    Unsere Plattform im Überblick - Live-Daten aus der Produktion
                </p>
            </div>
            
            <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
                <div class="stat-card text-center">
                    <div class="stat-number text-mercedes-blue" id="total-jobs">0</div>
                    <div class="text-lg font-semibold text-mercedes-black dark:text-white mb-2">Druckaufträge</div>
                    <div class="text-sm text-mercedes-gray dark:text-slate-400">Gesamt verarbeitet</div>
                    <div class="mt-3">
                        <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
                            <div class="bg-blue-600 h-2 rounded-full" style="width: 85%" id="jobs-progress"></div>
                        </div>
                    </div>
                </div>
                <div class="stat-card text-center">
                    <div class="stat-number text-mercedes-green" id="active-printers">0</div>
                    <div class="text-lg font-semibold text-mercedes-black dark:text-white mb-2">Aktive Drucker</div>
                    <div class="text-sm text-mercedes-gray dark:text-slate-400">Online verfügbar</div>
                    <div class="mt-3">
                        <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
                            <div class="bg-green-600 h-2 rounded-full" style="width: 92%" id="printers-progress"></div>
                        </div>
                    </div>
                </div>
                <div class="stat-card text-center">
                    <div class="stat-number text-purple-600 dark:text-purple-400" id="success-rate">98.5%</div>
                    <div class="text-lg font-semibold text-mercedes-black dark:text-white mb-2">Erfolgsrate</div>
                    <div class="text-sm text-mercedes-gray dark:text-slate-400">Qualitätssicherung</div>
                    <div class="mt-3">
                        <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
                            <div class="bg-purple-600 h-2 rounded-full" style="width: 98.5%" id="success-progress"></div>
                        </div>
                    </div>
                </div>
                <div class="stat-card text-center">
                    <div class="stat-number text-orange-600 dark:text-orange-400" id="uptime">99.9%</div>
                    <div class="text-lg font-semibold text-mercedes-black dark:text-white mb-2">Verfügbarkeit</div>
                    <div class="text-sm text-mercedes-gray dark:text-slate-400">System-Uptime</div>
                    <div class="mt-3">
                        <div class="w-full bg-gray-200 dark:bg-gray-700 rounded-full h-2">
                            <div class="bg-orange-600 h-2 rounded-full" style="width: 99.9%" id="uptime-progress"></div>
                        </div>
                    </div>
                </div>
            </div>
            
            <!-- Live Status Indicator -->
            <div class="mt-8 text-center">
                <div class="inline-flex items-center px-4 py-2 bg-green-100 dark:bg-green-900/30 text-green-800 dark:text-green-300 rounded-full text-sm font-medium">
                    <span class="w-2 h-2 bg-green-500 rounded-full animate-pulse mr-2"></span>
                    Live-Daten - Aktualisiert alle 30 Sekunden
                </div>
            </div>
        </div>
    </div>

    <!-- Enhanced Process Section -->
    <div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
        <div class="text-center mb-16">
            <h2 class="text-5xl font-bold text-mercedes-black dark:text-white mb-6">
                Ihr Weg zur sicheren Steckdosen-Nutzung
            </h2>
            <p class="text-xl text-mercedes-gray dark:text-slate-400 max-w-4xl mx-auto leading-relaxed">
                Von der Anfrage bis zur genehmigten Nutzung - Mercedes-Benz Qualität in jedem Schritt. 
            </p>
        </div>

        <div class="grid grid-cols-1 md:grid-cols-4 gap-8">
            <!-- Enhanced Step 1 -->
            <div class="process-step text-center">
                <div class="process-step-number w-20 h-20 text-white rounded-full flex items-center justify-center mx-auto mb-6 text-xl font-bold">1</div>
                <h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-4">TBA-Antrag stellen</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed mb-4">
                    Stellen Sie Ihren Antrag für die Nutzung einer Drucker-Steckdose in der TBA. 
                    Beschreiben Sie Ihr Ausbildungsprojekt und laden Sie optional Ihre 3D-Datei hoch.
                </p>
                <div class="flex justify-center space-x-2">
                    <span class="w-2 h-2 bg-blue-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                </div>
            </div>
            
            <!-- Enhanced Step 2 -->
            <div class="process-step text-center">
                <div class="process-step-number w-20 h-20 bg-green-500 text-white rounded-full flex items-center justify-center mx-auto mb-6 text-xl font-bold">2</div>
                <h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-4">Ausbilder-Prüfung</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed mb-4">
                    Ihr TBA-Ausbilder prüft Ihren Antrag auf Sicherheit, pädagogischen Wert und 
                    Machbarkeit. Nur genehmigte Projekte erhalten Zugang zu den Steckdosen.
                </p>
                <div class="flex justify-center space-x-2">
                    <span class="w-2 h-2 bg-blue-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-green-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                </div>
            </div>
            
            <!-- Enhanced Step 3 -->
            <div class="process-step text-center">
                <div class="process-step-number w-20 h-20 bg-purple-500 text-white rounded-full flex items-center justify-center mx-auto mb-6 text-xl font-bold">3</div>
                <h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-4">Steckdosen-Freischaltung</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed mb-4">
                    Nach der Genehmigung wird Ihre Drucker-Steckdose für den reservierten Zeitraum freigeschaltet. 
                    Sie können Ihren 3D-Drucker sicher ein- und ausschalten.
                </p>
                <div class="flex justify-center space-x-2">
                    <span class="w-2 h-2 bg-blue-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-green-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-purple-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-gray-300 rounded-full"></span>
                </div>
            </div>
            
            <!-- Enhanced Step 4 -->
            <div class="process-step text-center">
                <div class="process-step-number w-20 h-20 bg-orange-500 text-white rounded-full flex items-center justify-center mx-auto mb-6 text-xl font-bold">4</div>
                <h3 class="text-xl font-bold text-mercedes-black dark:text-white mb-4">Betreute Nutzung</h3>
                <p class="text-mercedes-gray dark:text-slate-400 leading-relaxed mb-4">
                    Arbeiten Sie unter Ausbilder-Aufsicht an Ihrem Projekt. Das System protokolliert 
                    die Nutzung und stellt sicher, dass alle Sicherheitsrichtlinien eingehalten werden.
                </p>
                <div class="flex justify-center space-x-2">
                    <span class="w-2 h-2 bg-blue-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-green-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-purple-500 rounded-full"></span>
                    <span class="w-2 h-2 bg-orange-500 rounded-full"></span>
                </div>
            </div>
        </div>

        <!-- Process Timeline -->
        <div class="mt-16 relative">
            <div class="absolute top-8 left-0 right-0 h-1 bg-gradient-to-r from-blue-500 via-green-500 via-purple-500 to-orange-500 opacity-30"></div>
            <div class="text-center">
            </div>
        </div>
    </div>

    <!-- Enhanced CTA Section -->
    <div class="cta-section p-12 text-center mx-4 rounded-3xl relative">
        <div class="relative z-10">
            <div class="mb-8">
                <div class="inline-flex items-center justify-center w-16 h-16 bg-mercedes-blue text-white rounded-full mb-6">
                    <svg class="w-8 h-8" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 10V3L4 14h7v7l9-11h-7z"/>
                    </svg>
                </div>
                <h2 class="text-4xl font-bold text-mercedes-black dark:text-white mb-4">
                    Bereit für den Druck?
                </h2>
                <p class="text-xl text-mercedes-gray dark:text-slate-400 mb-6 max-w-3xl mx-auto leading-relaxed">
                    Nutzen Sie 3D-Druck-Technologie in der Mercedes-Benz Berufsausbildung 
                    und lernen Sie unter professioneller Anleitung
                </p>
                <div class="grid grid-cols-1 md:grid-cols-3 gap-6 max-w-4xl mx-auto mb-8">
                    <div class="flex items-center justify-center">
                        <svg class="w-6 h-6 text-green-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                        </svg>
                        <span class="text-mercedes-gray dark:text-slate-300">Ausbilder-Betreuung</span>
                    </div>
                    <div class="flex items-center justify-center">
                        <svg class="w-6 h-6 text-green-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                        </svg>
                        <span class="text-mercedes-gray dark:text-slate-300">Sichere Steckdosen-Kontrolle</span>
                    </div>
                    <div class="flex items-center justify-center">
                        <svg class="w-6 h-6 text-green-500 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                            <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"/>
                        </svg>
                        <span class="text-mercedes-gray dark:text-slate-300">TBA-Qualitätsstandards</span>
                    </div>
                </div>
            </div>
            
            <div class="flex flex-col sm:flex-row justify-center gap-6">
                {% if current_user.is_authenticated %}
                <a href="{{ url_for('guest.guest_request_form') if url_for else '/guest-request' }}" 
                   class="btn-primary group">
                    <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                    TBA-Nutzungsantrag stellen
                </a>
                <a href="{{ url_for('dashboard') if url_for else '/dashboard' }}" 
                   class="btn-secondary group">
                    <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2H5a2 2 0 00-2-2z"/>
                    </svg>
                    Zum Dashboard
                </a>
                {% else %}
                <a href="{{ url_for('login') if url_for else '/login' }}" 
                   class="btn-primary group">
                    <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 16l-4-4m0 0l4-4m-4 4h14m-5 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1"/>
                    </svg>
                    Jetzt anmelden
                </a>
                <a href="{{ url_for('guest.guest_request_form') if url_for else '/guest-request' }}" 
                   class="btn-secondary group">
                    <svg class="w-6 h-6 mr-3 group-hover:scale-110 transition-transform" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"/>
                    </svg>
                    Nutzung beantragen
                </a>
                {% endif %}
            </div>
            
            <!-- Trust Badges -->
            <div class="mt-12 flex flex-wrap justify-center items-center gap-8 opacity-70">
                <div class="flex items-center">
                    <svg class="w-8 h-8 mr-2 text-mercedes-gray" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/>
                    </svg>
                    <span class="text-sm text-mercedes-gray dark:text-slate-400">Mercedes-Benz Qualität</span>
                </div>
                <div class="flex items-center">
                    <svg class="w-8 h-8 mr-2 text-mercedes-gray" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"/>
                    </svg>
                    <span class="text-sm text-mercedes-gray dark:text-slate-400">DSGVO Konform</span>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
let statisticsData = {
    total_jobs: 0,
    active_printers: 0,
    success_rate: 98.5,
    uptime: 99.9
};
let animationInProgress = false;
let lastUpdateTime = 0;
let retryCount = 0;
const MAX_RETRIES = 3;
const RETRY_DELAY = 5000;
const UPDATE_INTERVAL = 30000;

document.addEventListener('DOMContentLoaded', function() {
    initializeIndexPage();
});

function initializeIndexPage() {
    // Initialize components
    loadStatistics();
    setupIntersectionObservers();
    setupProcessStepAnimations();
    setupErrorHandling();
    setupPerformanceOptimizations();
    setupAccessibilityFeatures();
    
    // Set up update interval
    setInterval(loadStatisticsWithRetry, UPDATE_INTERVAL);
    
    // Handle visibility change for performance
    document.addEventListener('visibilitychange', handleVisibilityChange);
    
    // Setup smooth scrolling for anchor links
    setupSmoothScrolling();
}

async function loadStatisticsWithRetry() {
    try {
        await loadStatistics();
        retryCount = 0; // Reset retry count on success
    } catch (error) {
        console.warn('Statistics load failed, attempt', retryCount + 1);
        if (retryCount < MAX_RETRIES) {
            retryCount++;
            setTimeout(loadStatisticsWithRetry, RETRY_DELAY);
        } else {
            console.error('Max retries reached for statistics loading');
            showStatisticsError();
        }
    }
}

async function loadStatistics() {
    const now = Date.now();
    
    // Prevent too frequent updates
    if (now - lastUpdateTime < 5000) {
        return;
    }
    
    lastUpdateTime = now;
    
    try {
        // Show loading state for first load
        if (statisticsData.total_jobs === 0) {
            showLoadingSkeletons();
        }
        
        // Try multiple endpoints for reliability
        let response;
        try {
            response = await fetchWithTimeout('/api/statistics/public', 5000);
        } catch (primaryError) {
            console.log('Primary statistics API failed, trying fallback');
            response = await fetchWithTimeout('/api/stats/public', 5000);
        }
        
        if (response.ok) {
            const stats = await response.json();
            
            // Validate data
            const newData = {
                total_jobs: Math.max(0, parseInt(stats.total_jobs) || 0),
                active_printers: Math.max(0, parseInt(stats.active_printers) || 0),
                success_rate: Math.min(100, Math.max(0, parseFloat(stats.success_rate) || 98.5)),
                uptime: Math.min(100, Math.max(0, parseFloat(stats.uptime) || 99.9))
            };
            
            // Update statistics with animation
            await updateStatisticsAnimated(newData);
            
            // Update progress bars
            updateProgressBars(newData);
            
            // Hide loading skeletons
            hideLoadingSkeletons();
            
            // Update last successful fetch time
            updateLiveIndicator(true);
            
        } else {
            throw new Error(`HTTP ${response.status}: ${response.statusText}`);
        }
        
    } catch (error) {
        console.error('Error loading statistics:', error);
        updateLiveIndicator(false);
        
        // Use fallback values for first load
        if (statisticsData.total_jobs === 0) {
            const fallbackData = {
                total_jobs: 1250,
                active_printers: 12,
                success_rate: 98.5,
                uptime: 99.9
            };
            await updateStatisticsAnimated(fallbackData);
            updateProgressBars(fallbackData);
            hideLoadingSkeletons();
            
            showStatisticsMessage('Demo-Daten werden angezeigt', 'warning');
        }
        
        throw error; // Re-throw for retry logic
    }
}

async function updateStatisticsAnimated(newData) {
    if (animationInProgress) return;
    
    animationInProgress = true;
    
    try {
        // Animate counters
        await Promise.all([
            animateCounter('total-jobs', statisticsData.total_jobs, newData.total_jobs, 2000),
            animateCounter('active-printers', statisticsData.active_printers, newData.active_printers, 1500),
            animatePercentage('success-rate', statisticsData.success_rate, newData.success_rate, 1800),
            animatePercentage('uptime', statisticsData.uptime, newData.uptime, 1600)
        ]);
        
        // Update stored data
        statisticsData = { ...newData };
        
    } finally {
        animationInProgress = false;
    }
}

function animateCounter(elementId, fromValue, toValue, duration = 2000) {
    return new Promise((resolve) => {
        const element = document.getElementById(elementId);
        if (!element) {
            resolve();
            return;
        }
        
        const startTime = performance.now();
        const difference = toValue - fromValue;
        
        function updateCounter(currentTime) {
            const elapsed = currentTime - startTime;
            const progress = Math.min(elapsed / duration, 1);
            
            // Use easing function for smooth animation
            const easedProgress = easeOutQuart(progress);
            const currentValue = Math.round(fromValue + (difference * easedProgress));
            
            element.textContent = formatNumber(currentValue);
            
            if (progress < 1) {
                requestAnimationFrame(updateCounter);
            } else {
                resolve();
            }
        }
        
        requestAnimationFrame(updateCounter);
    });
}

function animatePercentage(elementId, fromValue, toValue, duration = 1500) {
    return new Promise((resolve) => {
        const element = document.getElementById(elementId);
        if (!element) {
            resolve();
            return;
        }
        
        const startTime = performance.now();
        const difference = toValue - fromValue;
        
        function updatePercentage(currentTime) {
            const elapsed = currentTime - startTime;
            const progress = Math.min(elapsed / duration, 1);
            
            const easedProgress = easeOutQuart(progress);
            const currentValue = fromValue + (difference * easedProgress);
            
            element.textContent = currentValue.toFixed(1) + '%';
            
            if (progress < 1) {
                requestAnimationFrame(updatePercentage);
            } else {
                resolve();
            }
        }
        
        requestAnimationFrame(updatePercentage);
    });
}

function updateProgressBars(data) {
    const progressBars = {
        'jobs-progress': Math.min(100, (data.total_jobs / 1500) * 100),
        'printers-progress': Math.min(100, (data.active_printers / 15) * 100),
        'success-progress': data.success_rate,
        'uptime-progress': data.uptime
    };
    
    Object.entries(progressBars).forEach(([id, width]) => {
        const element = document.getElementById(id);
        if (element) {
            element.style.width = `${width}%`;
            element.style.transition = 'width 1s ease-out';
        }
    });
}

function setupIntersectionObservers() {
    const observerOptions = {
        threshold: 0.1,
        rootMargin: '0px 0px -50px 0px'
    };
    
    const observer = new IntersectionObserver((entries) => {
        entries.forEach(entry => {
            if (entry.isIntersecting) {
                entry.target.classList.add('animate-in');
                
                // Trigger specific animations based on element
                if (entry.target.classList.contains('mercedes-feature-card')) {
                    animateFeatureCard(entry.target);
                } else if (entry.target.classList.contains('stat-card')) {
                    animateStatCard(entry.target);
                } else if (entry.target.classList.contains('process-step')) {
                    animateProcessStep(entry.target);
                }
            }
        });
    }, observerOptions);
    
    // Observe elements
    document.querySelectorAll('.mercedes-feature-card, .stat-card, .process-step').forEach(el => {
        observer.observe(el);
    });
}

function animateFeatureCard(element) {
    element.style.transform = 'translateY(20px)';
    element.style.opacity = '0';
    element.style.transition = 'all 0.6s ease-out';
    
    setTimeout(() => {
        element.style.transform = 'translateY(0)';
        element.style.opacity = '1';
    }, 100);
}

function animateStatCard(element) {
    const delay = Array.from(element.parentNode.children).indexOf(element) * 150;
    
    element.style.transform = 'scale(0.8) translateY(30px)';
    element.style.opacity = '0';
    element.style.transition = 'all 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275)';
    
    setTimeout(() => {
        element.style.transform = 'scale(1) translateY(0)';
        element.style.opacity = '1';
    }, delay);
}

function animateProcessStep(element) {
    const delay = Array.from(element.parentNode.children).indexOf(element) * 200;
    
    element.style.transform = 'translateY(40px)';
    element.style.opacity = '0';
    element.style.transition = 'all 0.7s ease-out';
    
    setTimeout(() => {
        element.style.transform = 'translateY(0)';
        element.style.opacity = '1';
        
        // Animate step number
        const stepNumber = element.querySelector('.process-step-number');
        if (stepNumber) {
            stepNumber.style.animation = 'bounce 0.6s ease-out';
        }
    }, delay);
}

function setupProcessStepAnimations() {
    const processSteps = document.querySelectorAll('.process-step');
    
    processSteps.forEach((step, index) => {
        step.addEventListener('mouseenter', () => {
            const stepNumber = step.querySelector('.process-step-number');
            if (stepNumber) {
                stepNumber.style.transform = 'scale(1.1) rotate(5deg)';
            }
        });
        
        step.addEventListener('mouseleave', () => {
            const stepNumber = step.querySelector('.process-step-number');
            if (stepNumber) {
                stepNumber.style.transform = 'scale(1) rotate(0deg)';
            }
        });
    });
}

function setupSmoothScrolling() {
    document.querySelectorAll('a[href^="#"]').forEach(anchor => {
        anchor.addEventListener('click', function (e) {
            e.preventDefault();
            const target = document.querySelector(this.getAttribute('href'));
            if (target) {
                target.scrollIntoView({
                    behavior: 'smooth',
                    block: 'start'
                });
            }
        });
    });
}

function handleVisibilityChange() {
    if (document.hidden) {
        // Pause animations and updates when tab is not visible
        console.log('Page hidden, pausing updates');
    } else {
        // Resume updates when tab becomes visible
        console.log('Page visible, resuming updates');
        loadStatistics();
    }
}

function setupErrorHandling() {
    window.addEventListener('error', (event) => {
        console.error('JavaScript error:', event.error);
    });
    
    window.addEventListener('unhandledrejection', (event) => {
        console.error('Unhandled promise rejection:', event.reason);
    });
}

function setupPerformanceOptimizations() {
    // Preload critical resources
    const preloadLinks = [
        '/api/statistics/public'
    ];
    
    preloadLinks.forEach(href => {
        const link = document.createElement('link');
        link.rel = 'prefetch';
        link.href = href;
        document.head.appendChild(link);
    });
}

function setupAccessibilityFeatures() {
    // Add ARIA labels for statistics
    const statElements = document.querySelectorAll('.stat-number');
    statElements.forEach(element => {
        element.setAttribute('aria-live', 'polite');
        element.setAttribute('aria-atomic', 'true');
    });
    
    // Add keyboard navigation for interactive elements
    document.querySelectorAll('.mercedes-feature-card').forEach(card => {
        card.setAttribute('tabindex', '0');
        card.addEventListener('keydown', function(e) {
            if (e.key === 'Enter' || e.key === ' ') {
                e.preventDefault();
                this.click();
            }
        });
    });
}

// Utility functions
function fetchWithTimeout(url, timeout = 5000) {
    return Promise.race([
        fetch(url),
        new Promise((_, reject) => 
            setTimeout(() => reject(new Error('Request timeout')), timeout)
        )
    ]);
}

function formatNumber(num) {
    if (num >= 1000000) {
        return (num / 1000000).toFixed(1) + 'M';
    } else if (num >= 1000) {
        return (num / 1000).toFixed(1) + 'K';
    }
    return num.toString();
}

function easeOutQuart(t) {
    return 1 - (--t) * t * t * t;
}

function showLoadingSkeletons() {
    document.querySelectorAll('.stat-number').forEach(element => {
        element.classList.add('loading-skeleton');
        element.textContent = '---';
    });
}

function hideLoadingSkeletons() {
    document.querySelectorAll('.stat-number').forEach(element => {
        element.classList.remove('loading-skeleton');
    });
}

function updateLiveIndicator(isConnected) {
    const indicator = document.querySelector('.animate-pulse');
    if (indicator) {
        if (isConnected) {
            indicator.classList.add('animate-pulse');
            indicator.classList.remove('opacity-50');
        } else {
            indicator.classList.remove('animate-pulse');
            indicator.classList.add('opacity-50');
        }
    }
}

function showStatisticsError() {
    const errorMessage = document.createElement('div');
    errorMessage.className = 'fixed top-4 right-4 bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded z-50';
    errorMessage.innerHTML = `
        <div class="flex items-center">
            <svg class="w-5 h-5 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
            </svg>
            <span>Statistiken konnten nicht geladen werden</span>
            <button onclick="this.parentElement.parentElement.remove()" class="ml-4">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                </svg>
            </button>
        </div>
    `;
    document.body.appendChild(errorMessage);
    
    setTimeout(() => {
        errorMessage.remove();
    }, 5000);
}

function showStatisticsMessage(message, type = 'info') {
    const toast = document.createElement('div');
    const bgColor = type === 'warning' ? 'bg-yellow-100 border-yellow-400 text-yellow-700' : 'bg-blue-100 border-blue-400 text-blue-700';
    
    toast.className = `fixed top-4 right-4 ${bgColor} px-4 py-3 rounded border z-50`;
    toast.innerHTML = `
        <div class="flex items-center">
            <span>${message}</span>
            <button onclick="this.parentElement.parentElement.remove()" class="ml-4">
                <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"/>
                </svg>
            </button>
        </div>
    `;
    document.body.appendChild(toast);
    
    setTimeout(() => {
        toast.remove();
    }, 3000);
}

// Add bounce animation keyframe
const style = document.createElement('style');
style.textContent = `
    @keyframes bounce {
        0%, 20%, 53%, 80%, 100% {
            transform: translate3d(0, 0, 0);
        }
        40%, 43% {
            transform: translate3d(0, -10px, 0);
        }
        70% {
            transform: translate3d(0, -5px, 0);
        }
        90% {
            transform: translate3d(0, -2px, 0);
        }
    }
    
    .animate-in {
        animation: fadeInUp 0.6s ease-out forwards;
    }
    
    @keyframes fadeInUp {
        from {
            opacity: 0;
            transform: translateY(30px);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }
`;
document.head.appendChild(style);
</script>
{% endblock %} 