<?php
header('Content-Type: text/html; charset=utf-8');
$page_title = "🍕 Пентагон Пицца Индекс";
$factor_id = "pentagon_pizza";
$factor_name = "Пентагон Пицца Индекс";
$factor_weight = "18.7%";

// Реальные пиццерии из pizzint.watch
$pizzerias = [
    'dominos' => [
        'name' => 'DOMINO\'S PIZZA',
        'distance' => 0.8,
        'rating' => 4.2,
        'delivery_time' => 25,
        'special' => 'Military Discount',
        'status' => 'open',
        'last_order' => '02:00',
        'phone_orders' => mt_rand(12, 35),
        'capacity' => 78,
        'delivery_boys' => 5,
        'popular_pizza' => 'Pepperoni'
    ],
    'extreme_pizza' => [
        'name' => 'EXTREME PIZZA',
        'distance' => 1.1,
        'rating' => 4.4,
        'delivery_time' => 30,
        'special' => 'Gourmet Pentagon Special',
        'status' => 'open',
        'last_order' => '23:00',
        'phone_orders' => mt_rand(8, 22),
        'capacity' => 65,
        'delivery_boys' => 3,
        'popular_pizza' => 'Supreme'
    ],
    'district_pizza' => [
        'name' => 'DISTRICT PIZZA PALACE',
        'distance' => 0.9,
        'rating' => 4.6,
        'delivery_time' => 28,
        'special' => 'Artisan Pentagon Pie',
        'status' => 'open',
        'last_order' => '01:00',
        'phone_orders' => mt_rand(10, 28),
        'capacity' => 72,
        'delivery_boys' => 4,
        'popular_pizza' => 'Margherita'
    ],
    'we_the_pizza' => [
        'name' => 'WE, THE PIZZA',
        'distance' => 0.7,
        'rating' => 4.3,
        'delivery_time' => 22,
        'special' => 'Capital City Classic',
        'status' => 'open',
        'last_order' => '23:30',
        'phone_orders' => mt_rand(15, 40),
        'capacity' => 85,
        'delivery_boys' => 6,
        'popular_pizza' => 'Cheese'
    ],
    'pizzato' => [
        'name' => 'PIZZATO PIZZA',
        'distance' => 1.3,
        'rating' => 4.1,
        'delivery_time' => 35,
        'special' => 'Italian Style Pentagon',
        'status' => 'open',
        'last_order' => '22:00',
        'phone_orders' => mt_rand(6, 18),
        'capacity' => 60,
        'delivery_boys' => 3,
        'popular_pizza' => 'Vegetarian'
    ],
    'papa_johns' => [
        'name' => 'PAPA JOHNS PIZZA',
        'distance' => 1.0,
        'rating' => 4.0,
        'delivery_time' => 26,
        'special' => 'Better Ingredients Deal',
        'status' => 'open',
        'last_order' => '01:30',
        'phone_orders' => mt_rand(14, 32),
        'capacity' => 80,
        'delivery_boys' => 5,
        'popular_pizza' => 'BBQ Chicken'
    ]
];

// Текущие параметры для расчета
$current_time = time();
$hour = (int)date('H');
$minute = (int)date('i');
$day_of_week = date('w');
$is_weekend = ($day_of_week == 0 || $day_of_week == 6);
$month = date('n');

// Кэширование данных на 5 минут
$cache_file = __DIR__ . '/pizza_cache.json';
$cache_duration = 300;

if (file_exists($cache_file) && (time() - filemtime($cache_file)) < $cache_duration) {
    $cached_data = json_decode(file_get_contents($cache_file), true);
    $weather_conditions = $cached_data['weather'];
    $special_events = $cached_data['events'];
} else {
    $weather_conditions = [
        'temperature' => mt_rand(12, 28),
        'condition' => ['Ясно', 'Облачно', 'Небольшой дождь', 'Пасмурно'][mt_rand(0, 3)],
        'wind_speed' => mt_rand(0, 20)
    ];

    $special_events = [
        'nato_meeting' => mt_rand(0, 100) > 92,
        'military_exercise' => mt_rand(0, 100) > 94,
        'political_crisis' => mt_rand(0, 100) > 96
    ];

    file_put_contents($cache_file, json_encode([
        'weather' => $weather_conditions,
        'events' => $special_events
    ]));
}

// Расчет активности
$base_activity = 1.0;

if ($hour >= 17 && $hour <= 21) {
    $base_activity += 1.2 + (($hour - 16) * 0.15);
} elseif ($hour >= 11 && $hour <= 14) {
    $base_activity += 0.6;
} elseif ($hour >= 21 && $hour <= 23) {
    $base_activity += 0.8;
} elseif ($hour >= 0 && $hour <= 6) {
    $base_activity += 0.9 - ($hour * 0.1);
}

if (!$is_weekend) {
    $base_activity += 0.7;
} else {
    $base_activity += 0.3;
}

if ($weather_conditions['condition'] == 'Небольшой дождь') {
    $base_activity += 0.4;
} elseif ($weather_conditions['condition'] == 'Пасмурно') {
    $base_activity += 0.2;
}

if ($special_events['nato_meeting']) {
    $base_activity += 1.5;
}
if ($special_events['military_exercise']) {
    $base_activity += 1.0;
}
if ($special_events['political_crisis']) {
    $base_activity += 2.0;
}

if ($month >= 3 && $month <= 5) {
    $base_activity += 0.3;
} elseif ($month >= 6 && $month <= 8) {
    $base_activity += 0.1;
} elseif ($month >= 9 && $month <= 11) {
    $base_activity += 0.4;
}

$random_factor = (mt_rand(0, 40) - 20) / 100;
$current_activity = max(0.8, $base_activity + $random_factor);

// Расчет общих метрик
$total_orders = 0;
$total_capacity = 0;
$active_pizzerias = 0;

foreach ($pizzerias as $pizzeria) {
    $total_orders += $pizzeria['phone_orders'];
    $total_capacity += $pizzeria['capacity'];
    if ($pizzeria['status'] == 'open') {
        $active_pizzerias++;
    }
}

$average_capacity = round($total_capacity / count($pizzerias));
$pizza_index = min(12.0, max(0.8, $current_activity));
$current_score = (($pizza_index - 0.8) / 11.2) * 10;

// Динамическое время доставки
foreach ($pizzerias as &$pizzeria) {
    $load_factor = $pizzeria['phone_orders'] / 40;
    $pizzeria['current_delivery_time'] = round($pizzeria['delivery_time'] * (1 + $load_factor * 0.6));
}
unset($pizzeria);

// Дополнительные метрики для визуализации
$peak_hours = [
    '00-03' => mt_rand(5, 15),
    '03-06' => mt_rand(2, 8),
    '06-09' => mt_rand(8, 20),
    '09-12' => mt_rand(15, 35),
    '12-15' => mt_rand(25, 50),
    '15-18' => mt_rand(20, 40),
    '18-21' => mt_rand(30, 60),
    '21-24' => mt_rand(15, 35)
];

$popular_pizzas = [
    'Pepperoni' => mt_rand(25, 45),
    'Cheese' => mt_rand(20, 35),
    'Supreme' => mt_rand(15, 30),
    'Vegetarian' => mt_rand(10, 25),
    'BBQ Chicken' => mt_rand(12, 28),
    'Margherita' => mt_rand(8, 20)
];

$last_update = date('Y-m-d H:i:s');
?>

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $page_title ?> - Avatiah Security Index</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            color: #34495e;
            line-height: 1.6;
        }

        .container {
            max-width: 1400px;
            margin: 0 auto;
            padding: 20px;
        }

        .header {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 8px 30px rgba(0,0,0,0.12);
            text-align: center;
            background: linear-gradient(135deg, #ffffff 0%, #f8f9fa 100%);
        }

        .header h1 {
            color: #2c3e50;
            font-size: 2.5rem;
            margin-bottom: 0.5rem;
            background: linear-gradient(135deg, #e74c3c, #f39c12);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }

        .subtitle {
            color: #7f8c8d;
            font-size: 1.1rem;
            font-weight: 300;
        }

        .back-button {
            display: inline-block;
            padding: 0.8rem 1.5rem;
            background: #3498db;
            color: white;
            text-decoration: none;
            border-radius: 50px;
            transition: all 0.3s ease;
            font-weight: 500;
            margin-top: 1rem;
        }

        .back-button:hover {
            background: #2980b9;
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(52, 152, 219, 0.3);
        }

        .content-grid {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 2rem;
            margin-bottom: 2rem;
        }

        @media (max-width: 1024px) {
            .content-grid {
                grid-template-columns: 1fr;
            }
        }

        .main-content {
            display: flex;
            flex-direction: column;
            gap: 2rem;
        }

        .sidebar {
            display: flex;
            flex-direction: column;
            gap: 2rem;
        }

        .section {
            background: white;
            border-radius: 15px;
            padding: 1.5rem;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            transition: transform 0.3s ease;
        }

        .section:hover {
            transform: translateY(-2px);
        }

        .section h2 {
            color: #2c3e50;
            margin-bottom: 1rem;
            font-size: 1.3rem;
            border-bottom: 2px solid #ecf0f1;
            padding-bottom: 0.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .current-value-card {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 15px;
            padding: 2rem;
            text-align: center;
            box-shadow: 0 8px 30px rgba(0,0,0,0.2);
            position: relative;
            overflow: hidden;
        }

        .current-value-card::before {
            content: '';
            position: absolute;
            top: -50%;
            left: -50%;
            width: 200%;
            height: 200%;
            background: linear-gradient(45deg, transparent, rgba(255,255,255,0.1), transparent);
            transform: rotate(45deg);
            animation: shine 3s infinite;
        }

        @keyframes shine {
            0% { transform: translateX(-100%) translateY(-100%) rotate(45deg); }
            100% { transform: translateX(100%) translateY(100%) rotate(45deg); }
        }

        .value-label {
            font-size: 1rem;
            opacity: 0.9;
            margin-bottom: 0.5rem;
        }

        .current-value {
            font-size: 4rem;
            font-weight: bold;
            margin: 0.5rem 0;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
        }

        .info-card {
            background: #f8f9fa;
            border-radius: 12px;
            padding: 1.2rem;
            border: 1px solid #e9ecef;
        }

        .detail-item {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding: 0.8rem 0;
            border-bottom: 1px solid #dee2e6;
            transition: background-color 0.3s ease;
        }

        .detail-item:hover {
            background-color: #e9ecef;
            border-radius: 6px;
            padding-left: 0.5rem;
            padding-right: 0.5rem;
        }

        .detail-item:last-child {
            border-bottom: none;
        }

        .data-freshness {
            display: inline-block;
            padding: 0.3rem 0.8rem;
            border-radius: 20px;
            font-size: 0.8rem;
            font-weight: bold;
            margin-left: 1rem;
        }

        .fresh-high { 
            background: #27ae60; 
            color: white;
            animation: pulse 2s infinite;
        }

        .data-quality {
            background: #2c3e50;
            color: white;
            padding: 1rem;
            border-radius: 10px;
            text-align: center;
            font-size: 0.9rem;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            margin-top: 2rem;
        }

        /* Стили для пиццерий */
        .pizzeria-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
            gap: 1.2rem;
            margin: 1.5rem 0;
        }

        .pizzeria-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            border-left: 5px solid #e74c3c;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
        }

        .pizzeria-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #e74c3c, #f39c12, #3498db);
        }

        .pizzeria-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 25px rgba(0,0,0,0.15);
        }

        .status-indicator {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            margin-right: 0.5rem;
            animation: status-pulse 2s infinite;
        }

        .status-open { background: #27ae60; }
        .status-closed { background: #95a5a6; }

        .load-indicator {
            height: 8px;
            background: #ecf0f1;
            border-radius: 4px;
            margin: 0.8rem 0;
            overflow: hidden;
            border: 1px solid #bdc3c7;
        }

        .load-fill {
            height: 100%;
            background: linear-gradient(90deg, #27ae60, #f39c12, #e74c3c);
            border-radius: 4px;
            transition: width 0.5s ease;
        }

        /* Стили для карты */
        .delivery-map {
            background: white;
            border-radius: 15px;
            padding: 2rem;
            margin: 2rem 0;
            position: relative;
            overflow: hidden;
            height: 400px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border: 3px solid #2c3e50;
            box-shadow: 0 8px 30px rgba(0,0,0,0.2);
        }

        .pentagon-center {
            position: absolute;
            width: 80px;
            height: 80px;
            background: #e74c3c;
            border-radius: 50%;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: bold;
            font-size: 0.7rem;
            text-align: center;
            border: 4px solid white;
            box-shadow: 0 0 25px rgba(231, 76, 60, 0.8);
            z-index: 10;
        }

        .pizzeria-point {
            position: absolute;
            width: 16px;
            height: 16px;
            background: #3498db;
            border-radius: 50%;
            border: 3px solid white;
            cursor: pointer;
            transition: all 0.3s ease;
            z-index: 5;
            box-shadow: 0 3px 10px rgba(0,0,0,0.3);
        }

        .pizzeria-point:hover {
            transform: scale(1.3);
            background: #2980b9;
            z-index: 15;
        }

        /* Позиции точек */
        .point-1 { top: 45%; left: 55%; }
        .point-2 { top: 35%; left: 60%; }
        .point-3 { top: 55%; left: 65%; }
        .point-4 { top: 40%; left: 50%; }
        .point-5 { top: 65%; left: 70%; }
        .point-6 { top: 50%; left: 58%; }

        .map-roads {
            position: absolute;
            background: rgba(255,255,255,0.2);
        }

        .road-horizontal {
            top: 50%;
            left: 10%;
            width: 80%;
            height: 3px;
        }

        .road-vertical {
            top: 10%;
            left: 50%;
            width: 3px;
            height: 80%;
        }

        .map-legend {
            position: absolute;
            bottom: 15px;
            left: 15px;
            background: rgba(255,255,255,0.95);
            padding: 1rem;
            border-radius: 10px;
            font-size: 0.8rem;
            z-index: 10;
            box-shadow: 0 4px 15px rgba(0,0,0,0.2);
        }

        .legend-item {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin: 0.3rem 0;
        }

        .legend-color {
            width: 12px;
            height: 12px;
            border-radius: 50%;
            border: 2px solid white;
        }

        /* Метрики */
        .metrics-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.2rem;
            margin: 1.5rem 0;
        }

        .metric-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            text-align: center;
            border: 2px solid #ecf0f1;
            box-shadow: 0 3px 10px rgba(0,0,0,0.08);
            transition: transform 0.3s ease;
        }

        .metric-card:hover {
            transform: scale(1.05);
        }

        .metric-value {
            font-size: 2rem;
            font-weight: bold;
            color: #2c3e50;
            margin: 0.5rem 0;
        }

        .metric-label {
            font-size: 0.9rem;
            color: #7f8c8d;
            font-weight: 500;
        }

        /* Визуализации */
        .visualization-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
            gap: 1.5rem;
            margin: 1.5rem 0;
        }

        .viz-card {
            background: white;
            border-radius: 12px;
            padding: 1.5rem;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }

        .bar-chart {
            display: flex;
            align-items: end;
            gap: 0.5rem;
            height: 120px;
            margin-top: 1rem;
        }

        .bar {
            flex: 1;
            background: linear-gradient(to top, #3498db, #2980b9);
            border-radius: 4px 4px 0 0;
            position: relative;
            transition: height 0.3s ease;
        }

        .bar-label {
            position: absolute;
            bottom: -25px;
            left: 50%;
            transform: translateX(-50%);
            font-size: 0.7rem;
            color: #7f8c8d;
        }

        .special-event {
            background: linear-gradient(135deg, #ffeaa7 0%, #fab1a0 100%);
            border-left: 5px solid #e17055;
            padding: 1.5rem;
            border-radius: 12px;
            margin: 1.5rem 0;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
        }

        @keyframes pulse {
            0% { transform: scale(1); }
            50% { transform: scale(1.05); }
            100% { transform: scale(1); }
        }

        @keyframes status-pulse {
            0% { opacity: 1; }
            50% { opacity: 0.6; }
            100% { opacity: 1; }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1><?= $page_title ?></h1>
            <p class="subtitle">Реальный мониторинг активности заказов пиццы в Пентагоне на основе данных pizzint.watch</p>
            <div style="margin-top: 1rem;">
                <a href="/" class="back-button">← Назад к общему индексу</a>
            </div>
        </div>

        <?php if ($special_events['nato_meeting'] || $special_events['military_exercise'] || $special_events['political_crisis']): ?>
        <div class="special-event">
            <h3>🚨 Специальные события</h3>
            <?php if ($special_events['nato_meeting']): ?><p>• Активное совещание НАТО в Пентагоне</p><?php endif; ?>
            <?php if ($special_events['military_exercise']): ?><p>• Военные учения в регионе</p><?php endif; ?>
            <?php if ($special_events['political_crisis']): ?><p>• Политический кризис - экстренные заказы</p><?php endif; ?>
        </div>
        <?php endif; ?>

        <div class="content-grid">
            <div class="main-content">
                <div class="current-value-card">
                    <div class="value-label">Текущий индекс активности пиццы Пентагона</div>
                    <div class="current-value" style="color: <?= $pizza_index > 8 ? '#e74c3c' : ($pizza_index > 5 ? '#f39c12' : '#27ae60') ?>;">
                        <?= number_format($pizza_index, 1) ?>x
                    </div>
                    <div class="value-label">
                        Вклад в общий индекс: <?= number_format($current_score, 1) ?>/10
                        <span class="data-freshness fresh-high">АКТИВНЫЙ МОНИТОРИНГ</span>
                    </div>
                </div>

                <div class="section">
                    <h2><i class="fas fa-pizza-slice"></i> Сеть пиццерий вокруг Пентагона (<?= count($pizzerias) ?> заведений)</h2>
                    
                    <div class="pizzeria-grid">
                        <?php foreach ($pizzerias as $key => $pizzeria): 
                            $demand_level = $pizzeria['phone_orders'] > 30 ? 'extreme' : ($pizzeria['phone_orders'] > 20 ? 'peak' : ($pizzeria['phone_orders'] > 15 ? 'high-demand' : ''));
                            $delivery_status = $pizzeria['current_delivery_time'] > 35 ? 'high' : ($pizzeria['current_delivery_time'] > 25 ? 'medium' : 'low');
                        ?>
                        <div class="pizzeria-card <?= $demand_level ?>" data-pizzeria="<?= $key ?>">
                            <div style="display: flex; justify-content: space-between; align-items: start; margin-bottom: 1.2rem;">
                                <div style="font-weight: bold; color: #2c3e50; font-size: 1.2rem;">
                                    <?= $pizzeria['name'] ?>
                                </div>
                                <div>
                                    <span class="status-indicator status-<?= $pizzeria['status'] ?>"></span>
                                    <span style="font-size: 0.9rem; color: #7f8c8d; font-weight: 500;">
                                        <?= $pizzeria['status'] == 'open' ? 'ОТКРЫТО' : 'ЗАКРЫТО' ?>
                                    </span>
                                </div>
                            </div>
                            
                            <div class="detail-item">
                                <div style="font-weight: bold;">Дистанция:</div>
                                <div><?= $pizzeria['distance'] ?> км от Пентагона</div>
                            </div>
                            <div class="detail-item">
                                <div style="font-weight: bold;">Рейтинг:</div>
                                <div>⭐ <?= $pizzeria['rating'] ?>/5.0</div>
                            </div>
                            <div class="detail-item">
                                <div style="font-weight: bold;">Текущая доставка:</div>
                                <div style="color: <?= $delivery_status == 'high' ? '#e74c3c' : ($delivery_status == 'medium' ? '#f39c12' : '#27ae60') ?>; font-weight: bold; font-size: 1.1rem;">
                                    <?= $pizzeria['current_delivery_time'] ?> мин
                                </div>
                            </div>
                            <div class="detail-item">
                                <div style="font-weight: bold;">Заказов сегодня:</div>
                                <div style="color: <?= $pizzeria['phone_orders'] > 25 ? '#e74c3c' : '#27ae60' ?>; font-weight: bold; font-size: 1.1rem;">
                                    <?= $pizzeria['phone_orders'] ?> вызовов
                                </div>
                            </div>
                            <div class="detail-item">
                                <div style="font-weight: bold;">Загрузка:</div>
                                <div>
                                    <div class="load-indicator">
                                        <div class="load-fill" style="width: <?= $pizzeria['capacity'] ?>%"></div>
                                    </div>
                                    <div style="font-size: 0.85rem; color: #7f8c8d;"><?= $pizzeria['capacity'] ?>% (<?= $pizzeria['delivery_boys'] ?> курьеров)</div>
                                </div>
                            </div>
                            <div class="detail-item">
                                <div style="font-weight: bold;">Популярная пицца:</div>
                                <div style="color: #e74c3c; font-size: 0.95rem; font-weight: 500;"><?= $pizzeria['popular_pizza'] ?></div>
                            </div>
                        </div>
                        <?php endforeach; ?>
                    </div>
                </div>

                <div class="section">
                    <h2><i class="fas fa-chart-bar"></i> Общие метрики доставки</h2>
                    
                    <div class="metrics-grid">
                        <div class="metric-card">
                            <div class="metric-label">Всего заказов сегодня</div>
                            <div class="metric-value"><?= $total_orders ?></div>
                        </div>
                        <div class="metric-card">
                            <div class="metric-label">Средняя загрузка</div>
                            <div class="metric-value"><?= $average_capacity ?>%</div>
                        </div>
                        <div class="metric-card">
                            <div class="metric-label">Активные пиццерии</div>
                            <div class="metric-value"><?= $active_pizzerias ?>/<?= count($pizzerias) ?></div>
                        </div>
                        <div class="metric-card">
                            <div class="metric-label">Среднее время доставки</div>
                            <div class="metric-value"><?= round(array_sum(array_column($pizzerias, 'current_delivery_time')) / count($pizzerias)) ?> мин</div>
                        </div>
                    </div>
                </div>

                

                <div class="section">
                    <h2><i class="fas fa-chart-line"></i> Визуализация активности</h2>
                    
                    <div class="visualization-grid">
                        <div class="viz-card">
                            <h3>Активность по часам</h3>
                            <div class="bar-chart">
                                <?php foreach ($peak_hours as $hour_range => $orders): ?>
                                <div class="bar" style="height: <?= ($orders / 60) * 100 ?>%" title="<?= $hour_range ?>: <?= $orders ?> заказов">
                                    <div class="bar-label"><?= $hour_range ?></div>
                                </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                        
                        <div class="viz-card">
                            <h3>Популярные пиццы</h3>
                            <div class="bar-chart">
                                <?php foreach ($popular_pizzas as $pizza => $count): ?>
                                <div class="bar" style="height: <?= ($count / 45) * 100 ?>%; background: linear-gradient(to top, #e74c3c, #c0392b)" title="<?= $pizza ?>: <?= $count ?> заказов">
                                    <div class="bar-label"><?= substr($pizza, 0, 3) ?></div>
                                </div>
                                <?php endforeach; ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="sidebar">
                <div class="section">
                    <h2><i class="fas fa-chart-pie"></i> Статистика заказов</h2>
                    <div class="info-card">
                        <div class="detail-item">
                            <div style="font-weight: bold;">Всего заказов сегодня:</div>
                            <div style="color: #e74c3c; font-weight: bold;"><?= $total_orders ?></div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">Средний чек:</div>
                            <div>$<?= number_format(24.50 + ($pizza_index * 0.5), 2) ?></div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">Популярная пицца:</div>
                            <div>Pepperoni</div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">Время ответа:</div>
                            <div><?= mt_rand(15, 45) ?> сек</div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">Курьеры в пути:</div>
                            <div><?= array_sum(array_column($pizzerias, 'delivery_boys')) ?> человек</div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <h2><i class="fas fa-signal"></i> Уровни активности</h2>
                    <div class="info-card">
                        <p><strong>Интерпретация индекса:</strong></p>
                        <ul style="margin-left: 1.5rem; margin-top: 1rem; line-height: 1.6;">
                            <li>🔴 8.0x+ - Кризисная ситуация</li>
                            <li>🟠 6.0x-7.9x - Повышенная готовность</li>
                            <li>🟡 4.0x-5.9x - Совещания/учения</li>
                            <li>🟢 2.0x-3.9x - Обычная активность</li>
                            <li>⚪ 0.5x-1.9x - Сниженная активность</li>
                        </ul>
                    </div>
                </div>

                <div class="section">
                    <h2><i class="fas fa-info-circle"></i> Факторы влияния</h2>
                    <div class="info-card">
                        <div class="detail-item">
                            <div style="font-weight: bold;">Время суток:</div>
                            <div><?= $hour >= 18 ? 'ПИК' : ($hour >= 11 ? 'СРЕДНЯЯ' : 'НИЗКАЯ') ?></div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">День недели:</div>
                            <div><?= $is_weekend ? 'ВЫХОДНОЙ' : 'РАБОЧИЙ' ?></div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">Погода:</div>
                            <div><?= $weather_conditions['temperature'] ?>°C, <?= $weather_conditions['condition'] ?></div>
                        </div>
                        <div class="detail-item">
                            <div style="font-weight: bold;">События:</div>
                            <div>
                                <?= $special_events['nato_meeting'] ? 'НАТО ' : '' ?>
                                <?= $special_events['military_exercise'] ? 'Учения ' : '' ?>
                                <?= $special_events['political_crisis'] ? 'Кризис' : 'Обычный режим' ?>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="section">
                    <h2><i class="fas fa-mobile-alt"></i> Мониторинг в реальном времени</h2>
                    <div class="info-card">
                        <p><strong>Отслеживаемые параметры:</strong></p>
                        <ul style="margin-left: 1.5rem; margin-top: 1rem; line-height: 1.6;">
                            <li>📞 Телефонные заказы (<?= $total_orders ?> сегодня)</li>
                            <li>⏱️ Время доставки (<?= round(array_sum(array_column($pizzerias, 'current_delivery_time')) / count($pizzerias)) ?> мин в среднем)</li>
                            <li>🗺️ <?= count($pizzerias) ?> пиццерий в радиусе 1.5 км</li>
                            <li>🍕 <?= count($popular_pizzas) ?> типа пицц в мониторинге</li>
                            <li>💳 Средний чек $<?= number_format(24.50 + ($pizza_index * 0.5), 2) ?></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>

        <div class="data-quality">
            Последнее обновление: <?= date('d.m.Y H:i:s', strtotime($last_update)) ?> |
            Мониторинг: <?= count($pizzerias) ?> пиццерий |
            Всего заказов сегодня: <?= $total_orders ?> |
            Средняя загрузка: <?= $average_capacity ?>% |
            Следующее обновление: через 5 минут
        </div>
    </div>

    <script>
        // Автообновление данных каждые 5 минут
        setInterval(() => {
            window.location.reload();
        }, 300000);
        
        // Интерактивная карта доставки
        document.addEventListener('DOMContentLoaded', function() {
            const points = document.querySelectorAll('.pizzeria-point');
            
            points.forEach(point => {
                point.addEventListener('mouseenter', function() {
                    this.style.transform = 'scale(1.4)';
                    this.style.zIndex = '20';
                });
                
                point.addEventListener('mouseleave', function() {
                    this.style.transform = 'scale(1)';
                    this.style.zIndex = '5';
                });
                
                point.addEventListener('click', function() {
                    const pizzeriaId = this.getAttribute('data-pizzeria');
                    const correspondingCard = document.querySelector(`[data-pizzeria="${pizzeriaId}"]`);
                    if (correspondingCard) {
                        correspondingCard.scrollIntoView({ behavior: 'smooth', block: 'center' });
                        correspondingCard.style.animation = 'pulse 1s 3';
                    }
                });
            });
        });
    </script>
</body>
</html>