<?php
$page_title = 'Logistics Intelligence';
require_once __DIR__ . '/../config.php';
if (session_status() === PHP_SESSION_NONE) { session_start(); }
if (!isset($_SESSION['admin_id'])) { redirect(SITE_URL . '/admin/login.php'); }
require_once __DIR__ . '/header.php';
?>

<div style="display:flex; justify-content:space-between; align-items:center; margin-bottom:24px;">
    <div>
        <h2 style="font-family:'Outfit', sans-serif; font-size:1.8rem; color:#0f172a; margin:0;"><i class="fas fa-shipping-fast" style="color:#0ea5e9; margin-right:10px;"></i>Logistics Intelligence</h2>
        <p style="color:#64748b; font-size:0.95rem; margin-top:5px;">Route optimization, fleet analytics, fuel tracking, and delivery performance.</p>
    </div>
</div>

<div class="grid-4" style="margin-bottom:24px;">
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #0ea5e9;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">FLEET SIZE</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">84 <span style="font-size:0.9rem; color:#64748b;">Vehicles</span></div>
        <div style="color:#0ea5e9; font-size:0.8rem; margin-top:5px;"><i class="fas fa-truck"></i> 72 Active Now</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #10b981;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">ON-TIME DELIVERY</div>
        <div style="font-size:1.6rem; font-weight:700; color:#10b981;">94.2%</div>
        <div style="color:#10b981; font-size:0.8rem; margin-top:5px;"><i class="fas fa-check-circle"></i> +2.1% vs Last Month</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #f59e0b;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">FUEL COST/KM</div>
        <div style="font-size:1.6rem; font-weight:700; color:#0f172a;">₹8.4</div>
        <div style="color:#f59e0b; font-size:0.8rem; margin-top:5px;"><i class="fas fa-gas-pump"></i> -5% Optimized</div>
    </div>
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0; border-top:4px solid #ef4444;">
        <div style="color:#64748b; font-size:0.8rem; font-weight:600; margin-bottom:8px;">DELAYED TODAY</div>
        <div style="font-size:1.6rem; font-weight:700; color:#ef4444;">5</div>
        <div style="color:#ef4444; font-size:0.8rem; margin-top:5px;"><i class="fas fa-exclamation-circle"></i> Traffic + Weather</div>
    </div>
</div>

<div class="grid-2" style="margin-bottom:24px;">
    <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
        <h3 style="margin:0 0 15px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-route" style="color:#0ea5e9; margin-right:8px;"></i>Route Optimization</h3>
        <div style="background:#f0f9ff; border:1px solid #bae6fd; padding:15px; border-radius:8px; margin-bottom:15px;">
            <div style="display:flex; justify-content:space-between; margin-bottom:10px;">
                <span style="font-weight:600; color:#0369a1;">Today's Optimized Routes</span>
                <span style="font-weight:bold; color:#0ea5e9;">42 routes</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; color:#64748b; margin-bottom:5px;">
                <span>Km Saved Today</span><span style="font-weight:bold; color:#10b981;">340 km</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; color:#64748b;">
                <span>Fuel Saved</span><span style="font-weight:bold; color:#10b981;">₹28,560</span>
            </div>
        </div>
        <h4 style="margin:0 0 10px; font-size:0.95rem;">Active Deliveries</h4>
        <?php
        $deliveries = [
            ['Mumbai → Pune', 'TK-4521', '78%', '2:30 PM ETA', '#10b981'],
            ['Delhi → Jaipur', 'TK-4522', '45%', '4:00 PM ETA', '#3b82f6'],
            ['Chennai → Bangalore', 'TK-4523', '92%', '1:00 PM ETA', '#10b981'],
            ['Kolkata → Patna', 'TK-4524', '12%', '8:00 PM ETA', '#f59e0b'],
        ];
        foreach ($deliveries as $d): ?>
        <div style="border:1px solid #e2e8f0; border-radius:8px; padding:10px 15px; margin-bottom:8px;">
            <div style="display:flex; justify-content:space-between; margin-bottom:6px;">
                <span style="font-weight:600; font-size:0.85rem;"><?= $d[0] ?></span>
                <span style="font-size:0.75rem; color:#94a3b8;"><?= $d[1] ?></span>
            </div>
            <div style="background:#e2e8f0; height:6px; border-radius:3px; overflow:hidden; margin-bottom:4px;">
                <div style="width:<?= $d[2] ?>; height:100%; background:<?= $d[4] ?>; border-radius:3px;"></div>
            </div>
            <div style="font-size:0.75rem; color:#64748b;"><?= $d[3] ?></div>
        </div>
        <?php endforeach; ?>
    </div>

    <div style="display:flex; flex-direction:column; gap:24px;">
        <div style="background:#fff; padding:20px; border-radius:12px; border:1px solid #e2e8f0;">
            <h3 style="margin:0 0 15px; font-size:1.15rem; color:#0f172a;"><i class="fas fa-chart-bar" style="color:#8b5cf6; margin-right:8px;"></i>Fleet Analytics</h3>
            <div style="display:grid; grid-template-columns:1fr 1fr; gap:15px;">
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.5rem; font-weight:700; color:#0ea5e9;">84</div>
                    <div style="font-size:0.75rem; color:#94a3b8;">Total Vehicles</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.5rem; font-weight:700; color:#10b981;">86%</div>
                    <div style="font-size:0.75rem; color:#94a3b8;">Utilization</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.5rem; font-weight:700; color:#f59e0b;">12</div>
                    <div style="font-size:0.75rem; color:#94a3b8;">In Maintenance</div>
                </div>
                <div style="background:#f8fafc; padding:15px; border-radius:8px; text-align:center;">
                    <div style="font-size:1.5rem; font-weight:700; color:#8b5cf6;">4.2L km</div>
                    <div style="font-size:0.75rem; color:#94a3b8;">Monthly Km</div>
                </div>
            </div>
        </div>

        <div style="background:linear-gradient(135deg,#0ea5e9,#0284c7); color:#fff; padding:20px; border-radius:12px;">
            <h3 style="margin:0 0 8px; font-size:1.1rem;"><i class="fas fa-map-marked-alt"></i> Last-Mile Optimization</h3>
            <p style="margin:0 0 15px; font-size:0.85rem; opacity:0.85;">AI-powered last-mile delivery routing for urban zones.</p>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Avg Last-Mile Time</span><span style="font-weight:bold;">45 min</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem; margin-bottom:8px;">
                <span>Delivery Score</span><span style="font-weight:bold;">4.7/5.0</span>
            </div>
            <div style="display:flex; justify-content:space-between; font-size:0.85rem;">
                <span>Network Simulations</span><span style="font-weight:bold;">12 Scenarios</span>
            </div>
        </div>
    </div>
</div>

<?php require_once __DIR__ . '/footer.php'; ?>
