<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Multi-Cloud Orchestration Portal</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            background: #f5f5f5;
            color: #333;
        }
        
        .header {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 2rem;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        
        .header h1 {
            font-size: 2rem;
            margin-bottom: 0.5rem;
        }
        
        .header p {
            opacity: 0.9;
        }
        
        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 2rem;
        }
        
        .stats {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1rem;
            margin-bottom: 2rem;
        }
        
        .stat-card {
            background: white;
            padding: 1.5rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }
        
        .stat-card h3 {
            color: #667eea;
            font-size: 0.9rem;
            text-transform: uppercase;
            margin-bottom: 0.5rem;
        }
        
        .stat-card .value {
            font-size: 2rem;
            font-weight: bold;
            color: #333;
        }
        
        .provider-section {
            margin-bottom: 2rem;
        }
        
        .provider-header {
            background: white;
            padding: 1rem 1.5rem;
            border-radius: 8px 8px 0 0;
            border-bottom: 2px solid #667eea;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .provider-header h2 {
            color: #667eea;
            font-size: 1.5rem;
        }
        
        .environments-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
            gap: 1rem;
            padding: 1rem;
            background: white;
            border-radius: 0 0 8px 8px;
        }
        
        .env-card {
            border: 1px solid #e0e0e0;
            border-radius: 8px;
            padding: 1.5rem;
            transition: transform 0.2s, box-shadow 0.2s;
        }
        
        .env-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0,0,0,0.15);
        }
        
        .env-card.enabled {
            border-left: 4px solid #4caf50;
        }
        
        .env-card.disabled {
            border-left: 4px solid #ccc;
            opacity: 0.6;
        }
        
        .env-card h3 {
            color: #333;
            margin-bottom: 0.5rem;
        }
        
        .env-card .meta {
            font-size: 0.9rem;
            color: #666;
            margin-bottom: 1rem;
        }
        
        .env-card .status {
            display: inline-block;
            padding: 0.25rem 0.75rem;
            border-radius: 12px;
            font-size: 0.8rem;
            font-weight: 600;
            margin-top: 0.5rem;
        }
        
        .status.healthy {
            background: #e8f5e9;
            color: #2e7d32;
        }
        
        .status.deployed {
            background: #e3f2fd;
            color: #1976d2;
        }
        
        .env-actions {
            margin-top: 1rem;
            display: flex;
            gap: 0.5rem;
        }
        
        .btn {
            padding: 0.5rem 1rem;
            border: none;
            border-radius: 4px;
            cursor: pointer;
            font-size: 0.9rem;
            transition: background 0.2s;
        }
        
        .btn-primary {
            background: #667eea;
            color: white;
        }
        
        .btn-primary:hover {
            background: #5568d3;
        }
        
        .btn-secondary {
            background: #f5f5f5;
            color: #333;
        }
        
        .btn-secondary:hover {
            background: #e0e0e0;
        }
    </style>
</head>
<body>
    <div class="header">
        <h1>🌐 Multi-Cloud Orchestration Portal</h1>
        <p>Manage deployments across Azure, AWS, GCP, IBM, Oracle, and On-Prem HCI</p>
    </div>
    
    <div class="container">
        <div class="stats">
            <div class="stat-card">
                <h3>Total Environments</h3>
                <div class="value">{{ environments|length }}</div>
            </div>
            <div class="stat-card">
                <h3>Enabled</h3>
                <div class="value">{{ environments|selectattr('enabled')|list|length }}</div>
            </div>
            <div class="stat-card">
                <h3>Cloud Providers</h3>
                <div class="value">{{ by_provider|length }}</div>
            </div>
            <div class="stat-card">
                <h3>Admin Regions</h3>
                <div class="value">{{ environments|selectattr('role', 'equalto', 'admin')|list|length }}</div>
            </div>
        </div>
        
        {% for provider, envs in by_provider.items() %}
        <div class="provider-section">
            <div class="provider-header">
                <h2>{{ provider|upper }} Environments</h2>
                <span>{{ envs|length }} environment(s)</span>
            </div>
            <div class="environments-grid">
                {% for env in envs %}
                <div class="env-card {{ 'enabled' if env.enabled else 'disabled' }}">
                    <h3>{{ env.name }}</h3>
                    <div class="meta">
                        <div><strong>Role:</strong> {{ env.role }}</div>
                        <div><strong>Region:</strong> {{ env.region }}</div>
                        <div><strong>Location:</strong> {{ env.location }}</div>
                    </div>
                    {% if env.enabled and env.name in env_statuses %}
                    <div class="status {{ env_statuses[env.name].cluster_health }}">
                        {{ env_statuses[env.name].status|title }}
                    </div>
                    {% endif %}
                    <div class="env-actions">
                        <a href="/environment/{{ env.name }}" class="btn btn-primary">View Details</a>
                        {% if env.enabled %}
                        <button class="btn btn-secondary" onclick="deploy('{{ env.name }}')">Deploy</button>
                        {% endif %}
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
        {% endfor %}
    </div>
    
    <script>
        async function deploy(envName) {
            try {
                const response = await fetch(`/api/environments/${envName}/deploy`, {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }
                });
                
                const data = await response.json();
                
                if (response.ok) {
                    alert(`Deployment queued: ${data.deployment_id}`);
                } else {
                    alert(`Error: ${data.error}`);
                }
            } catch (error) {
                alert(`Error: ${error.message}`);
            }
        }
    </script>
</body>
</html>

