<?php defined('ABSPATH') || exit;
// Dashboard data with 5-minute cache for speed
$_dash_cache = get_transient('dzqcod_dash_cache');
if (!$_dash_cache || !empty($_GET['refresh'])) {
$S=\DZQCOD\Core::ST;$C=[];foreach($S as $k=>$v)$C[$k]=(int)wc_orders_count('wc-'.$k);
$total=array_sum($C);$confirm_rate=$total>0?round(($C['confirmed']+$C['delivered']+$C['shipped']+$C['in-transit']+$C['out-for-delivery'])/$total*100,1):0;
$rto_rate=($C['delivered']+$C['rto'])>0?round($C['rto']/($C['delivered']+$C['rto'])*100,1):0;
$delivery_rate=$total>0?round($C['delivered']/$total*100,1):0;
$plan=\DZQCOD\Core::opt('license_plan','free');$sym=\DZQCOD\Core::opt('currency_symbol','دج');
$buy_url='https://productes.nibra.cloud/product/dzqcod';
global $wpdb;$p=$wpdb->prefix;

// Today stats
$today=gmdate('Y-m-d');$td_next=gmdate('Y-m-d',strtotime('+1 day'));
$td_orders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$today.'...'.$td_next]);
$td_count=count($td_orders);$td_rev=0;
foreach($td_orders as $id){$o=wc_get_order($id);if($o)$td_rev+=(float)$o->get_total();}

// This week
$week_start=gmdate('Y-m-d',strtotime('monday this week'));
$wk_orders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$week_start.'...'.$td_next]);
$wk_count=count($wk_orders);$wk_rev=0;
foreach($wk_orders as $id){$o=wc_get_order($id);if($o)$wk_rev+=(float)$o->get_total();}

// This month
$month_start=gmdate('Y-m-01');
$mo_orders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$month_start.'...'.$td_next]);
$mo_count=count($mo_orders);$mo_rev=0;
foreach($mo_orders as $id){$o=wc_get_order($id);if($o)$mo_rev+=(float)$o->get_total();}

// Pending actions
$pending_call=$C['pending-call']??0;$callback=$C['callback']??0;$no_answer=$C['no-answer']??0;
$ready_ship=$C['ready-to-ship']??0;$confirmed_noship=$C['confirmed']??0;

// Recent orders
$recent=wc_get_orders(['limit'=>10,'orderby'=>'date','order'=>'DESC']);

// Top wilayas (30 days)
$top_wilayas=$wpdb->get_results("SELECT pm.meta_value as w,COUNT(*) as c FROM {$p}postmeta pm JOIN {$p}posts p ON p.ID=pm.post_id WHERE pm.meta_key='_shipping_state' AND p.post_type='shop_order' AND p.post_date>=DATE_SUB(NOW(),INTERVAL 30 DAY) GROUP BY w ORDER BY c DESC LIMIT 5",ARRAY_A);

// Setup completion
$wizard_done=get_option('dzqcod_wizard_completed');
$has_shipping=\DZQCOD\Core::opt('shipping_provider','');
$has_wa=\DZQCOD\Core::opt('wa_phone','');
$setup_score=0;if($wizard_done)$setup_score+=20;if($has_shipping)$setup_score+=20;if($has_wa)$setup_score+=20;if($total>0)$setup_score+=20;if($plan!=='free')$setup_score+=20;
// Cache dashboard data for 5 minutes
set_transient('dzqcod_dash_cache', compact('S','C','total','confirm_rate','rto_rate','delivery_rate','td_count','td_rev','wk_count','wk_rev','mo_count','mo_rev','pending_call','callback','no_answer','ready_ship','confirmed_noship','top_wilayas','setup_score'), 300);
} else {
    extract($_dash_cache);
    $plan=\DZQCOD\Core::opt('license_plan','free');$sym=\DZQCOD\Core::opt('currency_symbol','دج');
    $buy_url='https://productes.nibra.cloud/product/dzqcod';
    $wizard_done=get_option('dzqcod_wizard_completed');
    $has_shipping=\DZQCOD\Core::opt('shipping_provider','');$has_wa=\DZQCOD\Core::opt('wa_phone','');
    $recent=wc_get_orders(['limit'=>10,'orderby'=>'date','order'=>'DESC']);
}
?>
<?php include __DIR__.'/_layout_start.php'; ?>
<div class="dza-header">
<h1>📊 لوحة التحكم</h1>
<div style="display:flex;gap:8px;align-items:center">
<span style="font-size:11px;color:#94a3b8">📅 <?php echo gmdate('d/m/Y'); ?></span>
<?php if($plan==='free'):?><a href="<?php echo esc_url($buy_url);?>" target="_blank" class="dza-btn primary" style="font-size:11px;padding:6px 14px">⚡ ترقية لـ PRO</a><?php endif;?>
</div>
</div>
<div class="dza-content">

<?php // Setup completion bar (if not 100%)
if($setup_score<100): ?>
<div style="background:linear-gradient(135deg,#1e293b,#0f172a);border-radius:14px;padding:18px;margin-bottom:16px;border:1px solid #334155">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px">
<span style="font-weight:700;font-size:13px;color:#fff">🚀 إكمال إعداد المتجر</span>
<span style="font-size:12px;color:<?php echo $setup_score>=60?'#10b981':'#f59e0b';?>;font-weight:800"><?php echo $setup_score;?>%</span>
</div>
<div style="background:#334155;border-radius:6px;height:8px;overflow:hidden"><div style="background:linear-gradient(90deg,#6366f1,#8b5cf6);height:100%;width:<?php echo $setup_score;?>%;border-radius:6px;transition:.5s"></div></div>
<div style="display:flex;gap:8px;margin-top:10px;flex-wrap:wrap;font-size:11px">
<?php if(!$wizard_done):?><a href="<?php echo admin_url('admin.php?page=dzqcod-setup');?>" style="color:#f59e0b;text-decoration:none">⚠️ أكمل الإعداد</a><?php endif;?>
<?php if(!$has_shipping):?><a href="<?php echo admin_url('admin.php?page=dzqcod-shipping');?>" style="color:#f59e0b;text-decoration:none">⚠️ ربط شركة شحن</a><?php endif;?>
<?php if(!$has_wa):?><a href="<?php echo admin_url('admin.php?page=dzqcod-whatsapp');?>" style="color:#f59e0b;text-decoration:none">⚠️ إعداد واتساب</a><?php endif;?>
<?php if($plan==='free'):?><a href="<?php echo esc_url($buy_url);?>" target="_blank" style="color:#6366f1;text-decoration:none">⚡ ترقية الخطة</a><?php endif;?>
</div>
</div>
<?php endif; ?>

<!-- ═══ KPI CARDS ═══ -->
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:12px;margin-bottom:16px">
<!-- Today -->
<div class="dza-card" style="padding:16px;border-right:4px solid #6366f1">
<div style="display:flex;justify-content:space-between;align-items:center"><span style="font-size:11px;color:#94a3b8;font-weight:700">📦 طلبات اليوم</span><span style="font-size:20px">📊</span></div>
<div style="font-size:32px;font-weight:900;color:#6366f1;margin:6px 0"><?php echo $td_count;?></div>
<div style="font-size:11px;color:#94a3b8"><?php echo number_format($td_rev,0);?> <?php echo esc_html($sym);?> إيرادات</div>
</div>
<!-- Week -->
<div class="dza-card" style="padding:16px;border-right:4px solid #3b82f6">
<div style="display:flex;justify-content:space-between;align-items:center"><span style="font-size:11px;color:#94a3b8;font-weight:700">📅 هذا الأسبوع</span><span style="font-size:20px">📈</span></div>
<div style="font-size:32px;font-weight:900;color:#3b82f6;margin:6px 0"><?php echo $wk_count;?></div>
<div style="font-size:11px;color:#94a3b8"><?php echo number_format($wk_rev,0);?> <?php echo esc_html($sym);?></div>
</div>
<!-- Month -->
<div class="dza-card" style="padding:16px;border-right:4px solid #10b981">
<div style="display:flex;justify-content:space-between;align-items:center"><span style="font-size:11px;color:#94a3b8;font-weight:700">📆 هذا الشهر</span><span style="font-size:20px">💰</span></div>
<div style="font-size:32px;font-weight:900;color:#10b981;margin:6px 0"><?php echo $mo_count;?></div>
<div style="font-size:11px;color:#94a3b8"><?php echo number_format($mo_rev,0);?> <?php echo esc_html($sym);?></div>
</div>
<!-- Delivery Rate -->
<div class="dza-card" style="padding:16px;border-right:4px solid #f59e0b">
<div style="display:flex;justify-content:space-between;align-items:center"><span style="font-size:11px;color:#94a3b8;font-weight:700">🎯 معدل التسليم</span><span style="font-size:20px">📋</span></div>
<div style="font-size:32px;font-weight:900;color:<?php echo $delivery_rate>=50?'#10b981':'#ef4444';?>;margin:6px 0"><?php echo $delivery_rate;?>%</div>
<div style="font-size:11px;color:#94a3b8">تأكيد: <?php echo $confirm_rate;?>% | مرتجع: <?php echo $rto_rate;?>%</div>
</div>
</div>

<!-- ═══ PERFORMANCE METRICS ═══ -->
<div style="display:grid;grid-template-columns:repeat(6,1fr);gap:8px;margin-bottom:16px">
<?php
$metrics = [
    ['l'=>'⏳ بانتظار','v'=>$pending_call,'c'=>'#f59e0b','link'=>'dzqcod-call-center'],
    ['l'=>'📞 معاودة','v'=>$callback,'c'=>'#e67e22','link'=>'dzqcod-call-center'],
    ['l'=>'❌ لا يجيب','v'=>$no_answer,'c'=>'#95a5a6','link'=>'dzqcod-call-center'],
    ['l'=>'✅ مؤكد','v'=>$confirmed_noship,'c'=>'#27ae60','link'=>'dzqcod-orders'],
    ['l'=>'🚚 جاهز','v'=>$ready_ship,'c'=>'#2980b9','link'=>'dzqcod-shipping'],
    ['l'=>'🎉 مسلّم','v'=>$C['delivered']??0,'c'=>'#2ecc71','link'=>'dzqcod-orders'],
];
foreach($metrics as $m): ?>
<a href="<?php echo esc_url(admin_url('admin.php?page='.$m['link']));?>" class="dza-card" style="padding:12px;text-align:center;text-decoration:none;transition:.2s;cursor:pointer" onmouseover="this.style.transform='translateY(-3px)'" onmouseout="this.style.transform='none'">
<div style="font-size:24px;font-weight:900;color:<?php echo $m['c'];?>"><?php echo $m['v'];?></div>
<div style="font-size:10px;color:#94a3b8;margin-top:2px"><?php echo $m['l'];?></div>
</a>
<?php endforeach; ?>
</div>

<!-- ═══ MAIN GRID: Charts + Actions ═══ -->
<div style="display:grid;grid-template-columns:2fr 1fr;gap:14px;margin-bottom:16px">

<!-- Status Distribution -->
<div class="dza-card" style="padding:18px">
<h3 style="font-size:14px;font-weight:800;margin:0 0 12px;color:#1e293b">📊 توزيع حالات الطلبات</h3>
<div style="display:grid;grid-template-columns:repeat(4,1fr);gap:6px">
<?php
$show_statuses = ['pending-call','confirmed','shipped','delivered','rto','cancelled','fake','no-answer'];
foreach($show_statuses as $sk):
$sv=$S[$sk]??null;if(!$sv)continue;$cnt=$C[$sk]??0;$pct=$total>0?round($cnt/$total*100):0;
?>
<div style="background:#f8fafc;border-radius:8px;padding:8px;text-align:center">
<div style="font-size:16px;font-weight:900;color:<?php echo esc_attr($sv['c']);?>"><?php echo $cnt;?></div>
<div style="font-size:9px;color:#94a3b8"><?php echo esc_html($sv['i'].' '.$sv['l']);?></div>
<div style="background:#e2e8f0;border-radius:3px;height:4px;margin-top:4px;overflow:hidden"><div style="background:<?php echo esc_attr($sv['c']);?>;height:100%;width:<?php echo $pct;?>%"></div></div>
</div>
<?php endforeach; ?>
</div>
</div>

<!-- Quick Actions -->
<div class="dza-card" style="padding:18px">
<h3 style="font-size:14px;font-weight:800;margin:0 0 12px;color:#1e293b">⚡ إجراءات سريعة</h3>
<div style="display:flex;flex-direction:column;gap:6px">
<a href="<?php echo admin_url('admin.php?page=dzqcod-call-center');?>" class="dza-btn" style="padding:10px 14px;font-size:12px;text-decoration:none;display:flex;align-items:center;gap:8px;background:#eff6ff;color:#1e40af;border-radius:8px;font-weight:700">📞 مركز الاتصال <span style="margin-right:auto;background:#3b82f6;color:#fff;padding:1px 8px;border-radius:10px;font-size:10px"><?php echo $pending_call+$callback;?></span></a>
<a href="<?php echo admin_url('admin.php?page=dzqcod-shipping');?>" class="dza-btn" style="padding:10px 14px;font-size:12px;text-decoration:none;display:flex;align-items:center;gap:8px;background:#f0fdf4;color:#166534;border-radius:8px;font-weight:700">🚚 إنشاء شحنات <span style="margin-right:auto;background:#10b981;color:#fff;padding:1px 8px;border-radius:10px;font-size:10px"><?php echo $confirmed_noship;?></span></a>
<a href="<?php echo admin_url('admin.php?page=dzqcod-printing');?>" class="dza-btn" style="padding:10px 14px;font-size:12px;text-decoration:none;display:flex;align-items:center;gap:8px;background:#fdf4ff;color:#7c3aed;border-radius:8px;font-weight:700">🖨️ طباعة الوصولات</a>
<a href="<?php echo admin_url('admin.php?page=dzqcod-orders');?>" class="dza-btn" style="padding:10px 14px;font-size:12px;text-decoration:none;display:flex;align-items:center;gap:8px;background:#fff7ed;color:#c2410c;border-radius:8px;font-weight:700">📦 كل الطلبات <span style="margin-right:auto;background:#f59e0b;color:#fff;padding:1px 8px;border-radius:10px;font-size:10px"><?php echo $total;?></span></a>
<a href="<?php echo admin_url('admin.php?page=dzqcod-page-generator');?>" class="dza-btn" style="padding:10px 14px;font-size:12px;text-decoration:none;display:flex;align-items:center;gap:8px;background:#f1f5f9;color:#475569;border-radius:8px;font-weight:700">📄 إنشاء صفحات المتجر</a>
</div>
</div>
</div>

<!-- ═══ ROW 2: Top Wilayas + Recent Orders ═══ -->
<div style="display:grid;grid-template-columns:1fr 2fr;gap:14px;margin-bottom:16px">

<!-- Top Wilayas -->
<div class="dza-card" style="padding:18px">
<h3 style="font-size:14px;font-weight:800;margin:0 0 12px;color:#1e293b">🏆 أكثر الولايات طلباً</h3>
<?php if(empty($top_wilayas)):?>
<div style="text-align:center;padding:20px;color:#94a3b8;font-size:12px">لا توجد بيانات بعد</div>
<?php else:
$max_w=max(array_column($top_wilayas,'c'));
foreach($top_wilayas as $i=>$tw):$pct=$max_w>0?round($tw['c']/$max_w*100):0;
$colors=['#6366f1','#3b82f6','#10b981','#f59e0b','#ec4899'];$clr=$colors[$i]??'#94a3b8'; ?>
<div style="margin-bottom:8px">
<div style="display:flex;justify-content:space-between;font-size:11px;margin-bottom:2px"><span style="font-weight:700"><?php echo esc_html($tw['w']?:'-');?></span><span style="color:#94a3b8"><?php echo $tw['c'];?> طلب</span></div>
<div style="background:#f1f5f9;border-radius:4px;height:6px;overflow:hidden"><div style="background:<?php echo $clr;?>;height:100%;width:<?php echo $pct;?>%;border-radius:4px;transition:.5s"></div></div>
</div>
<?php endforeach;endif;?>
</div>

<!-- Recent Orders -->
<div class="dza-card" style="padding:18px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:12px">
<h3 style="font-size:14px;font-weight:800;margin:0;color:#1e293b">📦 آخر الطلبات</h3>
<a href="<?php echo admin_url('admin.php?page=dzqcod-orders');?>" style="font-size:11px;color:#6366f1;text-decoration:none;font-weight:700">عرض الكل ←</a>
</div>
<?php if(empty($recent)):?>
<div style="text-align:center;padding:24px;color:#94a3b8"><div style="font-size:32px;margin-bottom:8px">📦</div><p style="font-size:13px">لا توجد طلبات بعد</p><a href="<?php echo admin_url('admin.php?page=dzqcod-form-design');?>" style="color:#6366f1;font-size:12px">🎨 صمم نموذج الطلب</a></div>
<?php else:?>
<div style="overflow-x:auto">
<table style="width:100%;border-collapse:collapse;font-size:11px">
<thead><tr style="background:#f8fafc"><th style="padding:6px 8px;text-align:right;font-weight:700;color:#64748b">#</th><th style="padding:6px 8px;text-align:right;font-weight:700;color:#64748b">العميل</th><th style="padding:6px 8px;text-align:right;font-weight:700;color:#64748b">الولاية</th><th style="padding:6px 8px;text-align:center;font-weight:700;color:#64748b">المبلغ</th><th style="padding:6px 8px;text-align:center;font-weight:700;color:#64748b">الحالة</th></tr></thead>
<tbody>
<?php foreach($recent as $o):$ost=str_replace('wc-','',$o->get_status());$ws=$S[$ost]??['l'=>$ost,'c'=>'#94a3b8','i'=>'📋']; ?>
<tr style="border-bottom:1px solid #f0f0f0;cursor:pointer" onclick="location.href='<?php echo admin_url('admin.php?page=dzqcod-orders&view='.$o->get_id());?>'" onmouseover="this.style.background='#f8fafc'" onmouseout="this.style.background='none'">
<td style="padding:6px 8px;font-weight:700"><?php echo $o->get_id();?></td>
<td style="padding:6px 8px"><?php echo esc_html($o->get_billing_first_name());?><div style="font-size:10px;color:#94a3b8"><?php echo esc_html($o->get_billing_phone());?></div></td>
<td style="padding:6px 8px"><?php echo esc_html($o->get_shipping_state()?:'-');?></td>
<td style="padding:6px 8px;text-align:center;font-weight:800;color:#10b981"><?php echo number_format((float)$o->get_total(),0);?></td>
<td style="padding:6px 8px;text-align:center"><span style="background:<?php echo esc_attr($ws['c']);?>;color:#fff;padding:2px 8px;border-radius:6px;font-size:9px;font-weight:700;white-space:nowrap"><?php echo esc_html($ws['i'].' '.$ws['l']);?></span></td>
</tr>
<?php endforeach;?>
</tbody></table>
</div>
<?php endif;?>
</div>
</div>

<!-- ═══ SMART ALERTS + INSIGHTS (v4.1) ═══ -->
<?php
$alerts = [];
// High RTO rate
if ($rto_rate > 25) $alerts[] = ['type'=>'danger','icon'=>'🔴','title'=>'نسبة المرتجعات مرتفعة: '.$rto_rate.'%','action'=>'راجع أسباب المرتجعات وفعّل مكافحة الاحتيال','link'=>admin_url('admin.php?page=dzqcod-fraud'),'btn'=>'🛡️ الحماية'];
elseif ($rto_rate > 15) $alerts[] = ['type'=>'warning','icon'=>'🟡','title'=>'نسبة المرتجعات '.$rto_rate.'% — تحتاج انتباه','action'=>'فعّل التأكيد الهاتفي وراجع الولايات ذات أعلى مرتجعات','link'=>admin_url('admin.php?page=dzqcod-fraud'),'btn'=>'📊 تحليل'];
// Pending calls
if ($pending_call > 10) $alerts[] = ['type'=>'warning','icon'=>'⏳','title'=>$pending_call.' طلب بانتظار الاتصال','action'=>'اتصل بهؤلاء الآن — كل ساعة تأخير تقلل فرصة التأكيد 12%','link'=>admin_url('admin.php?page=dzqcod-call-center'),'btn'=>'📞 اتصل الآن'];
// No answer backlog
if ($no_answer > 5) $alerts[] = ['type'=>'info','icon'=>'📞','title'=>$no_answer.' طلب "لا يجيب" — أعد المحاولة','action'=>'جرّب الاتصال في أوقات مختلفة: الصباح أو بعد المغرب','link'=>admin_url('admin.php?page=dzqcod-call-center'),'btn'=>'🔄 إعادة محاولة'];
// Confirmed not shipped
if ($confirmed_noship > 5) $alerts[] = ['type'=>'warning','icon'=>'🚚','title'=>$confirmed_noship.' طلب مؤكد بدون شحن','action'=>'أنشئ شحنات الآن — التأخير يرفع نسبة الإلغاء','link'=>admin_url('admin.php?page=dzqcod-shipping'),'btn'=>'📦 شحن'];
// No orders today
if ($td_count === 0 && $total > 0) $alerts[] = ['type'=>'info','icon'=>'📭','title'=>'لا توجد طلبات اليوم بعد','action'=>'راجع حملاتك الإعلانية أو أنشئ عرض جديد','link'=>admin_url('admin.php?page=dzqcod-offers'),'btn'=>'🎁 عرض جديد'];
// Good news
if ($delivery_rate > 70) $alerts[] = ['type'=>'success','icon'=>'🎉','title'=>'ممتاز! معدل التسليم '.$delivery_rate.'%','action'=>'استمر — أداؤك أفضل من 80% من المتاجر','link'=>'','btn'=>''];
if ($td_count > 0 && $td_count >= ($wk_count / max(1, (int)gmdate('N')))) $alerts[] = ['type'=>'success','icon'=>'📈','title'=>'طلبات اليوم ('.$td_count.') أعلى من المعدل اليومي','action'=>'يوم ممتاز! تأكد من تأكيد الطلبات بسرعة','link'=>'','btn'=>''];

// Top wilaya insight
if (!empty($top_wilayas)) {
    $tw1 = $top_wilayas[0];
    $alerts[] = ['type'=>'info','icon'=>'🗺️','title'=>'أكثر ولاية طلباً: '.($tw1['w']?:'-').' ('.$tw1['c'].' طلب)','action'=>'ركّز إعلاناتك على هذه الولاية لنتائج أفضل','link'=>'','btn'=>''];
}
?>
<?php if (!empty($alerts)): ?>
<div style="margin-bottom:16px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:8px">
<h3 style="font-size:14px;font-weight:800;color:#1e293b;margin:0">🧠 تنبيهات وتوصيات ذكية</h3>
<span style="font-size:10px;color:#94a3b8"><?php echo count($alerts); ?> تنبيه</span>
</div>
<?php foreach ($alerts as $al):
$bg = ['danger'=>'#fef2f2','warning'=>'#fffbeb','info'=>'#eff6ff','success'=>'#f0fdf4'][$al['type']] ?? '#f8fafc';
$border = ['danger'=>'#ef4444','warning'=>'#f59e0b','info'=>'#3b82f6','success'=>'#10b981'][$al['type']] ?? '#e2e8f0';
$text_c = ['danger'=>'#991b1b','warning'=>'#92400e','info'=>'#1e40af','success'=>'#166534'][$al['type']] ?? '#475569';
?>
<div style="background:<?php echo $bg;?>;border-right:4px solid <?php echo $border;?>;border-radius:10px;padding:12px 14px;margin-bottom:6px;display:flex;align-items:center;gap:12px">
<span style="font-size:20px;flex-shrink:0"><?php echo esc_html($al['icon']);?></span>
<div style="flex:1">
<div style="font-weight:700;font-size:12px;color:<?php echo $text_c;?>"><?php echo esc_html($al['title']);?></div>
<div style="font-size:11px;color:#64748b;margin-top:1px"><?php echo esc_html($al['action']);?></div>
</div>
<?php if ($al['link']): ?><a href="<?php echo esc_url($al['link']);?>" style="background:<?php echo $border;?>;color:#fff;padding:5px 12px;border-radius:6px;font-size:10px;font-weight:700;text-decoration:none;white-space:nowrap;flex-shrink:0"><?php echo esc_html($al['btn']);?></a><?php endif;?>
</div>
<?php endforeach;?>
</div>
<?php endif;?>

<!-- ═══ PRO UPSELL (only for free plan) ═══ -->
<?php if($plan==='free'): ?>
<div style="background:linear-gradient(135deg,#6366f1,#8b5cf6);border-radius:16px;padding:24px;color:#fff;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:12px">
<div>
<div style="font-size:20px;font-weight:900;margin-bottom:4px">⚡ ترقية لـ PRO — ضاعف مبيعاتك</div>
<div style="opacity:.85;font-size:13px">19 شركة شحن + مكافحة احتيال + واتساب + تتبع إعلانات + أتمتة ذكية</div>
</div>
<a href="<?php echo esc_url($buy_url);?>" target="_blank" style="background:#fff;color:#6366f1;padding:12px 28px;border-radius:10px;font-weight:800;font-size:14px;text-decoration:none;white-space:nowrap;transition:.2s" onmouseover="this.style.transform='scale(1.05)'" onmouseout="this.style.transform='none'">🛒 4,900 دج/سنة فقط</a>
</div>
<?php endif;?>

</div>
<?php include __DIR__."/_layout_end.php"; ?>
