<?php
include 'config.php';
checkCaptainAuth();

if (!isset($_GET['id'])) {
    header('Location: orders.php');
    exit();
}

$order_id = $conn->real_escape_string($_GET['id']);
$captain_id = $_SESSION['captain_id'];

// Get order details with discount information
$order_details = $conn->query("
    SELECT o.*, c.name as customer_name, c.phone as customer_phone, 
           c.address as customer_address, d.discount_name,
           d.discount_type, d.discount_value, o.discount_amount as applied_discount_amount
    FROM orders o 
    JOIN customers c ON o.customer_id = c.id 
    LEFT JOIN direct_discounts d ON o.discount_id = d.id
    WHERE o.id = '$order_id' AND o.captain_id = '$captain_id'
")->fetch_assoc();

if (!$order_details) {
    header('Location: orders.php');
    exit();
}

$has_discount = !empty($order_details['applied_discount_amount']) && $order_details['applied_discount_amount'] > 0;

// Get order items with portions
$order_items = $conn->query("
    SELECT oi.*, m.name as meal_name, m.price as meal_price,
           mp.name as portion_name, mp.price as portion_price
    FROM order_items oi 
    JOIN meals m ON oi.meal_id = m.id 
    LEFT JOIN meal_portions mp ON oi.portion_id = mp.id
    WHERE oi.order_id = '$order_id'
");

// Calculate subtotal
$subtotal = 0;
$items_count = 0;
$order_items_data = [];
while ($item = $order_items->fetch_assoc()) {
    // Use portion price if exists, otherwise use meal price
    $item_price = !empty($item['portion_price']) ? $item['portion_price'] : $item['meal_price'];
    $item_total = $item_price * $item['quantity'];
    $subtotal += $item_total;
    $items_count++;
    
    $order_items_data[] = [
        'meal_name' => $item['meal_name'],
        'portion_name' => $item['portion_name'],
        'quantity' => $item['quantity'],
        'price' => $item_price,
        'total' => $item_total
    ];
}

// Calculate totals
$delivery_fee = isset($order_details['delivery_fee']) ? (float)$order_details['delivery_fee'] : 0;
$discount_amount = $has_discount ? (float)$order_details['applied_discount_amount'] : 0;
$total_before_discount = $subtotal + $delivery_fee;
$final_total = (float)$order_details['total'];

// Get order notes if any
$notes = !empty($order_details['notes']) ? $order_details['notes'] : 'لا توجد ملاحظات';
?>

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>تفاصيل الطلب #<?php echo $order_details['id']; ?> - Max Captain</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.rtl.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        html, body {
    max-width: 100%;
    overflow-x: hidden;
}
        body {
            font-family: 'Tajawal', sans-serif;
            background-color: #f8f9fa;
            padding-bottom: 80px;
        }
        .navbar {
            background: linear-gradient(135deg, #F57C00, #FF9800);
            color: white;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        .main-card {
            background: white;
            border-radius: 15px;
            padding: 25px;
            margin-bottom: 25px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.08);
            border: none;
            transition: transform 0.3s ease;
        }
        .main-card:hover {
            transform: translateY(-2px);
        }
        .bottom-nav {
            position: fixed;
            bottom: 0;
            right: 0;
            left: 0;
            background: white;
            box-shadow: 0 -4px 15px rgba(0,0,0,0.1);
            padding: 12px;
            z-index: 1000;
        }
        .nav-item {
            text-align: center;
        }
        .nav-link {
            color: #666;
            text-decoration: none;
            transition: all 0.3s;
            padding: 8px;
        }
        .nav-link.active {
            color: #F57C00;
            transform: translateY(-2px);
        }
        .nav-link i {
            font-size: 1.5rem;
            margin-bottom: 5px;
        }
        .discount-badge {
            background: linear-gradient(135deg, #28a745, #20c997);
            color: white;
            padding: 6px 15px;
            border-radius: 25px;
            font-size: 13px;
            font-weight: bold;
            display: inline-flex;
            align-items: center;
            gap: 8px;
            box-shadow: 0 2px 8px rgba(40, 167, 69, 0.3);
        }
        .portion-badge {
            background: linear-gradient(135deg, #6c757d, #495057);
            color: white;
            padding: 4px 10px;
            border-radius: 12px;
            font-size: 12px;
            display: inline-block;
            margin-right: 5px;
            box-shadow: 0 1px 4px rgba(0,0,0,0.1);
        }
        .customer-info-box {
            background: linear-gradient(to right, #f8f9fa, #e9ecef);
            border-radius: 12px;
            padding: 20px;
            margin: 15px 0;
            border-left: 5px solid #F57C00;
        }
        .total-summary {
            background: linear-gradient(135deg, #4CAF50, #8BC34A);
            color: white;
            border-radius: 15px;
            padding: 20px;
            margin: 20px 0;
            box-shadow: 0 4px 15px rgba(76, 175, 80, 0.2);
        }
        .action-buttons {
            display: flex;
            gap: 12px;
            flex-wrap: wrap;
            margin-top: 20px;
        }
        .btn-captain {
            border-radius: 10px;
            padding: 12px 24px;
            font-weight: 600;
            transition: all 0.3s;
            border: none;
            min-width: 160px;
        }
        .btn-captain:hover {
            transform: translateY(-3px);
            box-shadow: 0 6px 15px rgba(0,0,0,0.15);
        }
        .table-custom {
            border-radius: 10px;
            overflow: hidden;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        .table-custom thead {
            background: linear-gradient(135deg, #F57C00, #FF9800);
            color: white;
        }
        .table-custom tbody tr:hover {
            background-color: rgba(245, 124, 0, 0.05);
        }
        .mobile-view {
            display: none;
        }
        .status-indicator {
            width: 14px;
            height: 14px;
            border-radius: 50%;
            display: inline-block;
            margin-left: 8px;
            animation: pulse 2s infinite;
        }
        .status-pending { 
            background-color: #ffc107;
            box-shadow: 0 0 0 rgba(255, 193, 7, 0.4);
        }
        .status-accepted { 
            background-color: #0dcaf0;
            box-shadow: 0 0 0 rgba(13, 202, 240, 0.4);
        }
        .status-on_the_way { 
            background-color: #0d6efd;
            box-shadow: 0 0 0 rgba(13, 110, 253, 0.4);
        }
        .status-delivered { 
            background-color: #198754;
            box-shadow: 0 0 0 rgba(25, 135, 84, 0.4);
        }
        
        @keyframes pulse {
            0% {
                box-shadow: 0 0 0 0 rgba(var(--status-color), 0.4);
            }
            70% {
                box-shadow: 0 0 0 10px rgba(var(--status-color), 0);
            }
            100% {
                box-shadow: 0 0 0 0 rgba(var(--status-color), 0);
            }
        }
        
        /* تحسينات للهواتف */
        @media (max-width: 768px) {
            .main-card {
                padding: 15px;
                margin-bottom: 15px;
            }
            .btn-captain {
                min-width: 100%;
                margin-bottom: 8px;
            }
            .action-buttons {
                flex-direction: column;
            }
            .desktop-view {
                display: none;
            }
            .mobile-view {
                display: block;
            }
            .mobile-item-card {
                background: white;
                border-radius: 12px;
                padding: 15px;
                margin-bottom: 10px;
                box-shadow: 0 2px 8px rgba(0,0,0,0.08);
                border-right: 4px solid #F57C00;
            }
            .customer-info-box {
                padding: 15px;
            }
        }
        
        /* تحميل سريع */
        .fade-in {
            animation: fadeIn 0.5s ease-in;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        /* تحسينات عامة */
        .order-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 20px;
            padding-bottom: 15px;
            border-bottom: 2px solid #f0f0f0;
        }
        .order-id {
            font-size: 1.4rem;
            font-weight: 800;
            color: #333;
            background: linear-gradient(135deg, #F57C00, #FF9800);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .time-badge {
            background: #f8f9fa;
            color: #6c757d;
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 13px;
            border: 1px solid #dee2e6;
        }
        .notes-box {
            background: linear-gradient(to right, #fff3cd, #ffeaa7);
            border: 1px solid #ffc107;
            border-radius: 10px;
            padding: 15px;
            margin: 15px 0;
        }
        .discount-info-box {
            background: linear-gradient(to right, #d4edda, #c3e6cb);
            border: 1px solid #28a745;
            border-radius: 10px;
            padding: 15px;
            margin: 15px 0;
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg">
        <div class="container-fluid">
            <div class="d-flex align-items-center w-100">
                <a href="orders.php" class="text-white" style="font-size: 1.5rem;">
                    <i class="bi bi-arrow-right"></i>
                </a>
                <span class="navbar-brand text-white mx-auto fw-bold">
                    <i class="bi bi-file-text me-2"></i>
                    تفاصيل الطلب #<?php echo $order_details['id']; ?>
                </span>
            </div>
        </div>
    </nav>

    <div class="container mt-4 fade-in">
        <!-- معلومات الطلب -->
        <div class="main-card">
            <div class="order-header">
                <div>
                    <span class="order-id">طلب #<?php echo $order_details['id']; ?></span>
                    <?php if ($has_discount && !empty($order_details['discount_name'])): ?>
                        <span class="discount-badge ms-3">
                            <i class="bi bi-percent"></i>
                            <?php echo htmlspecialchars($order_details['discount_name']); ?>
                        </span>
                    <?php endif; ?>
                </div>
                <div class="d-flex align-items-center">
                    <span class="status-indicator status-<?php echo $order_details['status']; ?>"></span>
                    <span class="badge bg-<?php 
                        $status_badge = [
                            'pending' => 'warning',
                            'accepted' => 'info',
                            'on_the_way' => 'primary',
                            'delivered' => 'success'
                        ];
                        echo $status_badge[$order_details['status']];
                    ?> fs-6">
                        <?php 
                        $status_text = [
                            'pending' => 'قيد الانتظار',
                            'accepted' => 'تم القبول',
                            'on_the_way' => 'في الطريق',
                            'delivered' => 'تم التوصيل'
                        ];
                        echo $status_text[$order_details['status']];
                        ?>
                    </span>
                    <span class="time-badge ms-3">
                        <i class="bi bi-clock"></i> <?php echo date('H:i', strtotime($order_details['created_at'])); ?>
                    </span>
                </div>
            </div>
            
            <div class="row">
                <div class="col-md-6">
                    <p><strong>تاريخ الطلب:</strong> <?php echo date('Y-m-d H:i', strtotime($order_details['created_at'])); ?></p>
                    <p><strong>الوقت المنقضي:</strong> 
                        <?php 
                        $created_time = strtotime($order_details['created_at']);
                        $current_time = time();
                        $diff_minutes = round(($current_time - $created_time) / 60);
                        
                        if ($diff_minutes < 60) {
                            echo $diff_minutes . ' دقيقة';
                        } else {
                            $hours = floor($diff_minutes / 60);
                            $minutes = $diff_minutes % 60;
                            echo $hours . ' ساعة و ' . $minutes . ' دقيقة';
                        }
                        ?>
                    </p>
                </div>
                <div class="col-md-6">
                    <p><strong>عدد العناصر:</strong> <?php echo $items_count; ?> عنصر</p>
                    <?php if ($has_discount): ?>
                        <p class="text-success">
                            <strong>قيمة التخفيض:</strong> 
                            <?php echo number_format($order_details['applied_discount_amount'], 2); ?> ريال
                        </p>
                    <?php endif; ?>
                </div>
            </div>
            
            <!-- ملاحظات الطلب -->
            <div class="notes-box">
                <h6><i class="bi bi-chat-left-text me-2"></i>ملاحظات العميل:</h6>
                <p class="mb-0"><?php echo nl2br(htmlspecialchars($notes)); ?></p>
            </div>
        </div>

        <!-- معلومات العميل -->
        <div class="main-card">
            <h5 class="mb-3"><i class="bi bi-person-circle me-2"></i>معلومات العميل</h5>
            <div class="customer-info-box">
                <div class="row">
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-center">
                            <div class="bg-primary text-white rounded-circle d-flex align-items-center justify-content-center" 
                                 style="width: 50px; height: 50px;">
                                <i class="bi bi-person fs-5"></i>
                            </div>
                            <div class="ms-3">
                                <small class="text-muted d-block">اسم العميل</small>
                                <strong class="fs-5"><?php echo $order_details['customer_name']; ?></strong>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-6 mb-3">
                        <div class="d-flex align-items-center">
                            <div class="bg-success text-white rounded-circle d-flex align-items-center justify-content-center" 
                                 style="width: 50px; height: 50px;">
                                <i class="bi bi-telephone fs-5"></i>
                            </div>
                            <div class="ms-3">
                                <small class="text-muted d-block">رقم الهاتف</small>
                                <strong class="fs-5">
                                    <a href="tel:<?php echo $order_details['customer_phone']; ?>" 
                                       class="text-decoration-none text-dark">
                                        <?php echo $order_details['customer_phone']; ?>
                                    </a>
                                </strong>
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="d-flex align-items-center">
                    <div class="bg-warning text-white rounded-circle d-flex align-items-center justify-content-center" 
                         style="width: 50px; height: 50px;">
                        <i class="bi bi-geo-alt fs-5"></i>
                    </div>
                    <div class="ms-3 flex-grow-1">
                        <small class="text-muted d-block">عنوان التوصيل</small>
                        <strong class="fs-5"><?php echo $order_details['customer_address']; ?></strong>
                    </div>
                </div>
            </div>
            
            <div class="d-flex gap-2 mt-3">
                <a href="tel:<?php echo $order_details['customer_phone']; ?>" 
                   class="btn btn-outline-primary btn-captain">
                    <i class="bi bi-telephone me-2"></i>اتصال
                </a>
                <a href="https://wa.me/<?php echo $order_details['customer_phone']; ?>" 
                   target="_blank" class="btn btn-outline-success btn-captain">
                    <i class="bi bi-whatsapp me-2"></i>واتساب
                </a>
                <a href="https://maps.google.com/?q=<?php echo urlencode($order_details['customer_address']); ?>" 
                   target="_blank" class="btn btn-outline-warning btn-captain">
                    <i class="bi bi-map me-2"></i>خرائط
                </a>
            </div>
        </div>

        <!-- معلومات التخفيض -->
        <?php if ($has_discount && !empty($order_details['discount_name'])): ?>
            <div class="main-card">
                <h5 class="mb-3"><i class="bi bi-percent me-2"></i>معلومات التخفيض</h5>
                <div class="discount-info-box">
                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>اسم التخفيض:</strong> <?php echo htmlspecialchars($order_details['discount_name']); ?></p>
                            <p><strong>نوع التخفيض:</strong> 
                                <?php 
                                if ($order_details['discount_type'] == 'percentage') {
                                    echo 'نسبة (' . $order_details['discount_value'] . '%)';
                                } else {
                                    echo 'مبلغ ثابت (' . number_format($order_details['discount_value'], 2) . ' ريال)';
                                }
                                ?>
                            </p>
                        </div>
                        <div class="col-md-6">
                            <p><strong>قيمة الخصم المطبقة:</strong> 
                                <span class="text-success fw-bold">
                                    <?php echo number_format($order_details['applied_discount_amount'], 2); ?> ريال
                                </span>
                            </p>
                            <p><strong>توفير العميل:</strong> 
                                <span class="text-success fw-bold">
                                    <?php 
                                    $savings_percentage = ($discount_amount / $total_before_discount) * 100;
                                    echo number_format($savings_percentage, 1) . '%';
                                    ?>
                                </span>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        <?php endif; ?>

        <!-- العناصر المطلوبة (للشاشات الكبيرة) -->
        <div class="main-card desktop-view">
            <h5 class="mb-3"><i class="bi bi-basket me-2"></i>العناصر المطلوبة (<?php echo $items_count; ?>)</h5>
            <div class="table-responsive">
                <table class="table table-custom">
                    <thead>
                        <tr>
                            <th>#</th>
                            <th>الوجبة</th>
                            <th>القسم</th>
                            <th class="text-center">الكمية</th>
                            <th class="text-center">سعر الوحدة</th>
                            <th class="text-center">المجموع</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php foreach ($order_items_data as $index => $item): ?>
                            <tr>
                                <td><?php echo $index + 1; ?></td>
                                <td><?php echo htmlspecialchars($item['meal_name']); ?></td>
                                <td>
                                    <?php if (!empty($item['portion_name'])): ?>
                                        <span class="portion-badge"><?php echo htmlspecialchars($item['portion_name']); ?></span>
                                    <?php else: ?>
                                        <span class="text-muted">كامل</span>
                                    <?php endif; ?>
                                </td>
                                <td class="text-center"><?php echo $item['quantity']; ?></td>
                                <td class="text-center"><?php echo number_format($item['price'], 2); ?> ريال</td>
                                <td class="text-center fw-bold"><?php echo number_format($item['total'], 2); ?> ريال</td>
                            </tr>
                        <?php endforeach; ?>
                    </tbody>
                </table>
            </div>
        </div>

        <!-- العناصر المطلوبة (للهواتف) -->
        <div class="mobile-view">
            <div class="main-card">
                <h5 class="mb-3"><i class="bi bi-basket me-2"></i>العناصر المطلوبة (<?php echo $items_count; ?>)</h5>
                <?php foreach ($order_items_data as $index => $item): ?>
                    <div class="mobile-item-card">
                        <div class="d-flex justify-content-between align-items-start mb-2">
                            <div>
                                <h6 class="mb-1"><?php echo htmlspecialchars($item['meal_name']); ?></h6>
                                <?php if (!empty($item['portion_name'])): ?>
                                    <span class="portion-badge"><?php echo htmlspecialchars($item['portion_name']); ?></span>
                                <?php endif; ?>
                            </div>
                            <span class="badge bg-light text-dark"><?php echo $item['quantity']; ?>x</span>
                        </div>
                        <div class="d-flex justify-content-between align-items-center">
                            <div>
                                <small class="text-muted d-block">سعر الوحدة</small>
                                <span><?php echo number_format($item['price'], 2); ?> ريال</span>
                            </div>
                            <div class="text-end">
                                <small class="text-muted d-block">المجموع</small>
                                <span class="fw-bold text-success"><?php echo number_format($item['total'], 2); ?> ريال</span>
                            </div>
                        </div>
                    </div>
                <?php endforeach; ?>
            </div>
        </div>

        <!-- ملخص الفاتورة -->
        <div class="main-card">
            <h5 class="mb-3"><i class="bi bi-receipt me-2"></i>ملخص الفاتورة</h5>
            <div class="total-summary">
                <div class="row">
                    <div class="col-md-8">
                        <div class="d-flex justify-content-between mb-3">
                            <span>مجموع العناصر:</span>
                            <strong><?php echo number_format($subtotal, 2); ?> ريال</strong>
                        </div>
                        <div class="d-flex justify-content-between mb-3">
                            <span>رسوم التوصيل:</span>
                            <strong><?php echo number_format($delivery_fee, 2); ?> ريال</strong>
                        </div>
                        
                        <?php if ($has_discount): ?>
                            <div class="d-flex justify-content-between mb-3">
                                <span><i class="bi bi-tag me-2"></i>التخفيض:</span>
                                <strong class="text-light">-<?php echo number_format($discount_amount, 2); ?> ريال</strong>
                            </div>
                        <?php endif; ?>
                        
                        <hr class="my-3" style="border-color: rgba(255,255,255,0.3);">
                        
                        <div class="d-flex justify-content-between mb-2">
                            <span class="fs-5">المجموع الكلي:</span>
                            <strong class="fs-4"><?php echo number_format($final_total, 2); ?> ريال</strong>
                        </div>
                        
                        <?php if ($has_discount): ?>
                            <small class="opacity-75">
                                <s><?php echo number_format($total_before_discount, 2); ?> ريال</s>
                                <span class="ms-2">
                                    <i class="bi bi-piggy-bank"></i> 
                                    وفر العميل <?php echo number_format($discount_amount, 2); ?> ريال
                                </span>
                            </small>
                        <?php endif; ?>
                    </div>
                    <div class="col-md-4 text-center d-flex align-items-center justify-content-center">
                        <div class="bg-white text-success rounded-circle d-flex align-items-center justify-content-center" 
                             style="width: 100px; height: 100px;">
                            <div class="text-center">
                                <div class="fw-bold fs-4"><?php echo number_format($final_total, 2); ?></div>
                                <small class="text-muted">ريال</small>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <!-- أزرار الإجراءات -->
        <?php if ($order_details['status'] != 'delivered'): ?>
            <div class="main-card">
                <h5 class="mb-3"><i class="bi bi-gear me-2"></i>تحديث حالة الطلب</h5>
                <div class="action-buttons">
                    <?php if ($order_details['status'] == 'pending'): ?>
                        <form method="POST" action="update_order.php" class="d-inline flex-grow-1">
                            <input type="hidden" name="order_id" value="<?php echo $order_details['id']; ?>">
                            <input type="hidden" name="status" value="accepted">
                            <button type="submit" class="btn btn-success btn-captain w-100">
                                <i class="bi bi-check-circle me-2"></i> قبول الطلب
                            </button>
                        </form>
                    <?php elseif ($order_details['status'] == 'accepted'): ?>
                        <form method="POST" action="update_order.php" class="d-inline flex-grow-1">
                            <input type="hidden" name="order_id" value="<?php echo $order_details['id']; ?>">
                            <input type="hidden" name="status" value="on_the_way">
                            <button type="submit" class="btn btn-primary btn-captain w-100">
                                <i class="bi bi-truck me-2"></i> بدأ التوصيل
                            </button>
                        </form>
                    <?php elseif ($order_details['status'] == 'on_the_way'): ?>
                        <form method="POST" action="update_order.php" class="d-inline flex-grow-1">
                            <input type="hidden" name="order_id" value="<?php echo $order_details['id']; ?>">
                            <input type="hidden" name="status" value="delivered">
                            <button type="submit" class="btn btn-success btn-captain w-100">
                                <i class="bi bi-check2-circle me-2"></i> تأكيد التسليم
                            </button>
                        </form>
                    <?php endif; ?>
                    
                    <a href="orders.php" class="btn btn-outline-secondary btn-captain flex-grow-1">
                        <i class="bi bi-arrow-right me-2"></i> العودة للطلبات
                    </a>
                </div>
                
                <?php if ($order_details['status'] == 'on_the_way'): ?>
                    <div class="alert alert-info mt-3">
                        <div class="d-flex align-items-center">
                            <i class="bi bi-info-circle fs-4 me-3"></i>
                            <div>
                                <strong>ملاحظة:</strong> تأكد من استلام العميل للطلب قبل تأكيد التسليم
                            </div>
                        </div>
                    </div>
                <?php endif; ?>
            </div>
        <?php else: ?>
            <div class="main-card">
                <div class="alert alert-success">
                    <div class="d-flex align-items-center">
                        <i class="bi bi-check-circle-fill fs-4 me-3"></i>
                        <div>
                            <h5 class="mb-1">تم تسليم الطلب بنجاح!</h5>
                            <p class="mb-0">تم تسليم الطلب للعميل في <?php echo date('H:i', strtotime($order_details['updated_at'] ?? $order_details['created_at'])); ?></p>
                        </div>
                    </div>
                </div>
                <div class="text-center mt-3">
                    <a href="orders.php" class="btn btn-primary btn-captain">
                        <i class="bi bi-arrow-right me-2"></i> العودة للطلبات الحالية
                    </a>
                </div>
            </div>
        <?php endif; ?>
    </div>

    <!-- Bottom Navigation -->
   

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            // تحسين تجربة اللمس على الهواتف
            if ('ontouchstart' in window) {
                document.querySelectorAll('.btn-captain, .nav-link').forEach(btn => {
                    btn.style.padding = '14px 20px';
                    btn.style.minHeight = '54px';
                });
            }
            
            // إضافة تأثيرات للزراع
            document.querySelectorAll('.btn-captain').forEach(button => {
                button.addEventListener('mouseenter', function() {
                    this.style.transform = 'translateY(-3px)';
                });
                button.addEventListener('mouseleave', function() {
                    this.style.transform = 'translateY(0)';
                });
            });
            
            // تحديث مؤشر الحالة
            const statusIndicators = document.querySelectorAll('.status-indicator');
            statusIndicators.forEach(indicator => {
                const statusClass = indicator.className.match(/status-(\w+)/)[1];
                let color;
                switch(statusClass) {
                    case 'pending': color = '255, 193, 7'; break;
                    case 'accepted': color = '13, 202, 240'; break;
                    case 'on_the_way': color = '13, 110, 253'; break;
                    case 'delivered': color = '25, 135, 84'; break;
                }
                indicator.style.setProperty('--status-color', color);
            });
        });
    </script>
    <!-- Bottom Navigation -->
<nav class="bottom-nav">
    <div class="row text-center">
        <div class="col-3">
            <a href="dashboard.php" class="nav-link">
                <i class="bi bi-house-door fs-4"></i>
                <div>الرئيسية</div>
            </a>
        </div>
        <div class="col-3">
            <a href="orders.php" class="nav-link">
                <i class="bi bi-list-check fs-4"></i>
                <div>الطلبات</div>
            </a>
        </div>
        <div class="col-3">
            <a href="completed_orders.php" class="nav-link">
                <i class="bi bi-check-circle fs-4"></i>
                <div>المنجزة</div>
            </a>
        </div>
        <div class="col-3">
            <a href="profile.php" class="nav-link">
                <i class="bi bi-person fs-4"></i>
                <div>الحساب</div>
            </a>
        </div>
    </div>
</nav>
</body>
</html>