```php
<?php
$host = 'localhost';
$dbname = 'med';
$username = 'root';
$password = '';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Connection failed: " . $e->getMessage());
}

$order_id = $_GET['order_id'] ?? null;

if (!$order_id) {
    die("معرف الطلب غير محدد");
}

try {
    $stmt = $pdo->prepare("
        SELECT o.*, w.name AS wilaya_name, dc.name AS delivery_company_name
        FROM orders o
        JOIN wilayas w ON o.wilaya_id = w.id
        JOIN delivery_companies dc ON o.delivery_company_id = dc.id
        WHERE o.id = ?
    ");
    $stmt->execute([$order_id]);
    $order = $stmt->fetch(PDO::FETCH_ASSOC);

    if (!$order) {
        die("الطلب غير موجود");
    }

    $stmt = $pdo->prepare("
        SELECT oi.*, pv.sku, p.name AS product_name
        FROM order_items oi
        JOIN product_variants pv ON oi.product_variant_id = pv.id
        JOIN products p ON pv.product_id = p.id
        WHERE oi.order_id = ?
    ");
    $stmt->execute([$order_id]);
    $order_items = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
    die("Error fetching order details: " . $e->getMessage());
}
?>

<!DOCTYPE html>
<html lang="ar" dir="rtl">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>تأكيد الطلب - متجرنا</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Tajawal:wght@300;400;500;700&display=swap" rel="stylesheet">
    <style>
        body {
            font-family: 'Tajawal', sans-serif;
            background-color: #f5f5f5;
            color: #333;
            margin: 0;
            padding: 0;
        }
        .container {
            max-width: 800px;
            margin: 30px auto;
            padding: 20px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.1);
        }
        h1 {
            text-align: center;
            color: #2196F3;
            margin-bottom: 20px;
        }
        .order-details {
            margin-bottom: 20px;
        }
        .order-details p {
            margin: 10px 0;
        }
        .order-items {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }
        .order-items th, .order-items td {
            border: 1px solid #ddd;
            padding: 10px;
            text-align: right;
        }
        .order-items th {
            background-color: #f5f5f5;
        }
        .btn-primary {
            display: block;
            width: 200px;
            margin: 20px auto;
            padding: 12px;
            background-color: #2196F3;
            color: white;
            text-align: center;
            text-decoration: none;
            border-radius: 4px;
            font-size: 16px;
        }
        .btn-primary:hover {
            background-color: #0b7dda;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>تم تسجيل طلبك بنجاح!</h1>
        <div class="order-details">
            <p><strong>رقم الطلب:</strong> <?php echo htmlspecialchars($order['id']); ?></p>
            <p><strong>الاسم:</strong> <?php echo htmlspecialchars($order['customer_name']); ?></p>
            <p><strong>رقم الهاتف:</strong> <?php echo htmlspecialchars($order['phone']); ?></p>
            <p><strong>العنوان:</strong> <?php echo htmlspecialchars($order['address']); ?></p>
            <p><strong>الولاية:</strong> <?php echo htmlspecialchars($order['wilaya_name']); ?></p>
            <p><strong>نوع التوصيل:</strong> <?php echo $order['delivery_type'] === 'home' ? 'توصيل إلى المنزل' : 'توصيل إلى المكتب'; ?></p>
            <p><strong>شركة التوصيل:</strong> <?php echo htmlspecialchars($order['delivery_company_name']); ?></p>
        </div>
        
        <table class="order-items">
            <thead>
                <tr>
                    <th>المنتج</th>
                    <th>الخصائص</th>
                    <th>الكمية</th>
                    <th>السعر الوحدة</th>
                    <th>الإجمالي</th>
                </tr>
            </thead>
            <tbody>
                <?php foreach ($order_items as $item): ?>
                    <tr>
                        <td><?php echo htmlspecialchars($item['product_name']); ?></td>
                        <td><?php echo htmlspecialchars($item['selected_attribute_value']); ?></td>
                        <td><?php echo $item['quantity']; ?></td>
                        <td><?php echo number_format($item['unit_price'], 2); ?> دج</td>
                        <td><?php echo number_format($item['unit_price'] * $item['quantity'], 2); ?> دج</td>
                    </tr>
                <?php endforeach; ?>
            </tbody>
        </table>
        
        <a href="index.php" class="btn-primary">العودة إ