<?php defined('ABSPATH') || exit;
$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'])/$total*100,1):0;
$rto_rate=($C['delivered']+$C['rto'])>0?round($C['rto']/($C['delivered']+$C['rto'])*100,1):0;
$rev=0;foreach(wc_get_orders(['status'=>'wc-delivered','limit'=>-1,'return'=>'ids']) as $id){$o=wc_get_order($id);if($o)$rev+=(float)$o->get_total();}
$recent=wc_get_orders(['limit'=>15,'orderby'=>'date','order'=>'DESC']);
$plan=\DZQCOD\Core::opt('license_plan','free');
$currency=\DZQCOD\Core::opt('currency_symbol','دج');
$country=\DZQCOD\Core::opt('country','DZ');
$buy_url='https://productes.nibra.cloud/product/dzqcod';
global $wpdb;$wpdb->suppress_errors(true); $p=$wpdb->prefix.DZQCOD_DB;

// Addon status
$installed = \DZQCOD\Modules::installed_addons();
$addon_active = function($slug) use ($installed){ return !empty($installed[$slug]); };

// Today
$today=gmdate('Y-m-d'); $today_next=gmdate('Y-m-d',strtotime('+1 day'));
$today_orders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$today.'...'.$today_next]);
$today_count=count($today_orders); $today_rev=0;
foreach($today_orders as $tid){$to=wc_get_order($tid);if($to)$today_rev+=(float)$to->get_total();}

// Yesterday for comparison
$yest=gmdate('Y-m-d',strtotime('-1 day'));
$yest_orders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$yest.'...'.$today]);
$yest_count=count($yest_orders);$yest_rev=0;
foreach($yest_orders as $yid){$yo=wc_get_order($yid);if($yo)$yest_rev+=(float)$yo->get_total();}
$order_trend=$yest_count>0?round(($today_count-$yest_count)/$yest_count*100):0;
$rev_trend=$yest_rev>0?round(($today_rev-$yest_rev)/$yest_rev*100):0;

// Weekly chart data (last 7 days)
$week_data=[];
for($i=6;$i>=0;$i--){
    $d=gmdate('Y-m-d',strtotime("-{$i} days")); $dn=gmdate('Y-m-d',strtotime("-".($i-1)." days"));
    $dorders=wc_get_orders(['limit'=>-1,'return'=>'ids','date_created'=>$d.'...'.$dn]);
    $dr=0;foreach($dorders as $did){$do=wc_get_order($did);if($do)$dr+=(float)$do->get_total();}
    $week_data[]=['day'=>gmdate('D',strtotime("-{$i} days")),'orders'=>count($dorders),'rev'=>$dr];
}
$max_orders=max(1,max(array_column($week_data,'orders')));

// Campaigns
$top_campaigns=[]; $campaign_leads=0;
if($addon_active('utm-tracking')||$addon_active('campaign-manager')){
    $top_campaigns=$wpdb->get_results("SELECT utm_campaign,SUM(leads) as leads,SUM(confirmed) as confirmed,SUM(revenue) as revenue FROM {$p}campaign_stats WHERE stat_date>=DATE_SUB(CURDATE(),INTERVAL 30 DAY) GROUP BY utm_campaign ORDER BY leads DESC LIMIT 5")?:[];
    foreach($top_campaigns as $tc)$campaign_leads+=(int)$tc->leads;
}
// Fraud
$fraud_alerts=[];$fraud_count=0;
if($addon_active('fraud-detect')){$fraud_alerts=$wpdb->get_results("SELECT f.*,CONCAT('#',f.order_id) as oid FROM {$p}fraud_scores f WHERE f.score>=50 ORDER BY f.id DESC LIMIT 5")?:[];$fraud_count=count($fraud_alerts);}
// SMS
$sms_sent=0;$sms_failed=0;
if($addon_active('sms-auto')){$sms_sent=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}sms_log WHERE status='sent' AND created_at>=DATE_SUB(NOW(),INTERVAL 7 DAY)")?:0);$sms_failed=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}sms_log WHERE status='failed' AND created_at>=DATE_SUB(NOW(),INTERVAL 7 DAY)")?:0);}
// WhatsApp
$wa_sent=0;if($addon_active('whatsapp-auto')){$wa_sent=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}whatsapp_log WHERE created_at>=DATE_SUB(NOW(),INTERVAL 7 DAY)")?:0);}
// Abandoned
$abandoned=0;if($addon_active('abandoned-cart')){$abandoned=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}abandoned_carts WHERE status='pending' AND created_at>=DATE_SUB(NOW(),INTERVAL 7 DAY)")?:0);}
// A/B
$ab_running=0;if($addon_active('ab-testing')){$ab_running=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}ab_tests WHERE status='running'")?:0);}
// Offers
$active_offers=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}offers WHERE is_active=1 AND (ends_at IS NULL OR ends_at>NOW())")?:0);
// Addons
$active_addons_count=count(array_filter($installed));
$total_addons=count(\DZQCOD\Modules::get_addons());
// Errors
$dash_errors=get_option('dzqcod_last_errors','');
$dash_err_count=$dash_errors?count(array_filter(explode("\n",$dash_errors))):0;
// Notifications
$dash_notifs=get_transient('dzqcod_server_notifs');
if($dash_notifs===false){$resp=wp_remote_get('https://dzqcd.nibra.cloud/api/v1/notifications',['timeout'=>5,'sslverify'=>false,'headers'=>['X-DZQCOD-Version'=>DZQCOD_VER,'X-DZQCOD-Plan'=>$plan]]);if(!is_wp_error($resp)&&wp_remote_retrieve_response_code($resp)===200){$body=json_decode(wp_remote_retrieve_body($resp),true);$dash_notifs=$body['notifications']??[];}else{$dash_notifs=[];}set_transient('dzqcod_server_notifs',$dash_notifs,6*HOUR_IN_SECONDS);}
// Shipping pipeline
$ship_pipeline=[
    'ready'=>(int)($C['ready-to-ship']??0),
    'shipped'=>(int)($C['shipped']??0),
    'transit'=>(int)($C['in-transit']??0),
    'delivery'=>(int)($C['out-for-delivery']??0),
    'delivered'=>(int)($C['delivered']??0),
    'rto'=>(int)($C['rto']??0),
];
$ship_total=array_sum($ship_pipeline);
// Wilayas count
$wil_count=(int)($wpdb->get_var("SELECT COUNT(*) FROM {$p}wilayas WHERE is_active=1")?:0);
?>
<div class="wrap dza-wrap" dir="rtl">
<?php include __DIR__.'/nav.php'; ?>
<div class="dza-header"><h1>📊 لوحة التحكم</h1>
<div style="display:flex;gap:8px;align-items:center">
<span style="font-size:11px;color:var(--text2)"><?php echo esc_html(DZQCOD_VER); ?> • <?php echo esc_html(strtoupper($plan)); ?></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">🛒 ترقية</a><?php endif;?>
</div></div>
<div class="dza-content">

<!-- ═══ ALERTS ═══ -->
<?php if(!empty($dash_notifs)):foreach(array_slice($dash_notifs,0,2) as $dn):
$dt=$dn['type']??'info';$dbg=$dt==='critical'?'#fef2f2':($dt==='warning'?'#fef3c7':'#eff6ff');$dico=$dt==='critical'?'🚨':($dt==='warning'?'⚠️':'💡');?>
<div style="background:<?php echo esc_html($dbg);?>;border-radius:10px;padding:10px 14px;margin-bottom:6px;display:flex;align-items:center;gap:8px;font-size:12px">
<span style="font-size:16px"><?php echo esc_html($dico);?></span>
<div style="flex:1"><strong><?php echo esc_html($dn['title']??'');?></strong> — <?php echo esc_html($dn['message']??'');?></div>
<?php if(!empty($dn['link'])):?><a href="<?php echo esc_url($dn['link']);?>" target="_blank" style="font-size:11px;color:#3b82f6">↗</a><?php endif;?></div>
<?php endforeach;endif;?>

<?php if($dash_err_count>0):?>
<div style="background:#fef2f2;border-radius:10px;padding:8px 14px;margin-bottom:6px;display:flex;align-items:center;gap:8px;font-size:12px">
🐛 <strong style="color:#dc2626"><?php echo esc_html($dash_err_count);?> خطأ</strong> — <a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-support'));?>" style="color:#dc2626;font-weight:700">عرض السجل</a></div>
<?php endif;?>

<?php if($plan==='free'):?>
<div style="background:linear-gradient(135deg,#4f46e5,#7c3aed);border-radius:12px;padding:14px 18px;margin-bottom:14px;display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:10px;color:#fff">
<div><div style="font-size:16px;font-weight:900">🚀 ارتقِ بمتجرك — DZQCOD PRO</div>
<div style="font-size:11px;opacity:.85;margin-top:2px">19 شركة شحن • واتساب آلي • 14 قالب • SMS • حملات • مكافحة احتيال • 11 دولة عربية</div></div>
<a href="<?php echo esc_url($buy_url);?>" target="_blank" style="background:#fff;color:#4f46e5;padding:10px 22px;border-radius:10px;font-weight:800;font-size:13px;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;?>

<!-- ═══ HERO — 6 Stats ═══ -->
<div class="dza-hero" style="display:grid;grid-template-columns:repeat(6,1fr);gap:0;padding:0;border-radius:14px;overflow:hidden;margin-bottom:16px">
<?php $hero_stats=[
    ['v'=>$today_count,'l'=>'طلبات اليوم','ico'=>'📊','trend'=>$order_trend,'color'=>'#4f46e5'],
    ['v'=>number_format($today_rev,0).' <small style="font-size:11px">'.esc_html($currency).'</small>','l'=>'إيرادات اليوم','ico'=>'💰','trend'=>$rev_trend,'color'=>'#16a34a'],
    ['v'=>$C['pending-call']??0,'l'=>'بانتظار الاتصال','ico'=>'📞','color'=>'#f59e0b'],
    ['v'=>($C['shipped']??0)+($C['in-transit']??0)+($C['out-for-delivery']??0),'l'=>'في الشحن','ico'=>'🚚','color'=>'#0ea5e9'],
    ['v'=>$C['delivered']??0,'l'=>'تم التوصيل','ico'=>'🎉','color'=>'#22c55e'],
    ['v'=>$confirm_rate.'%','l'=>'نسبة التأكيد','ico'=>'📈','color'=>$confirm_rate>=50?'#22c55e':'#ef4444'],
]; foreach($hero_stats as $hs):?>
<div style="text-align:center;padding:18px 10px;background:<?php echo esc_html($hs['color']);?>10;border-left:1px solid <?php echo esc_html($hs['color']);?>15">
<div style="font-size:14px;margin-bottom:4px"><?php echo esc_html($hs['ico']);?></div>
<div style="font-size:24px;font-weight:900;color:<?php echo esc_html($hs['color']);?>"><?php echo $hs['v'];// phpcs:ignore ?></div>
<div style="font-size:10px;color:var(--text2);margin-top:2px"><?php echo esc_html($hs['l']);?></div>
<?php if(!empty($hs['trend'])):$up=$hs['trend']>=0;?><div style="font-size:10px;color:<?php echo esc_html($up?'#16a34a':'#ef4444');?>;font-weight:700"><?php echo esc_html(($up?'▲':'▼').abs($hs['trend']).'% عن أمس');?></div><?php endif;?>
</div>
<?php endforeach;?></div>

<!-- ═══ WEEKLY MINI CHART ═══ -->
<div class="dza-card" style="margin-bottom:14px;padding:14px 16px">
<div style="display:flex;justify-content:space-between;align-items:center;margin-bottom:10px">
<h3 style="border:none;margin:0;font-size:14px;font-weight:800">📉 آخر 7 أيام</h3>
<div style="font-size:11px;color:var(--text2)"><?php echo number_format($rev,0);?> <?php echo esc_html($currency);?> إجمالي التوصيل</div>
</div>
<div style="display:flex;align-items:end;gap:6px;height:60px">
<?php foreach($week_data as $wd):$h=max(8,round($wd['orders']/$max_orders*60));?>
<div style="flex:1;text-align:center" title="<?php echo esc_attr($wd['orders'].' طلب — '.number_format($wd['rev'],0).' '.$currency);?>">
<div style="background:linear-gradient(180deg,#4f46e5,#818cf8);border-radius:4px 4px 0 0;height:<?php echo esc_html($h);?>px;transition:.3s;cursor:pointer" onmouseenter="this.style.opacity='0.7'" onmouseleave="this.style.opacity='1'"></div>
<div style="font-size:9px;color:var(--text2);margin-top:3px"><?php echo esc_html($wd['day']);?></div>
<div style="font-size:10px;font-weight:700;color:var(--text)"><?php echo esc_html($wd['orders']);?></div>
</div>
<?php endforeach;?></div></div>

<!-- ═══ KPIs — 10 metrics ═══ -->
<div class="dza-kpi-grid" style="grid-template-columns:repeat(5,1fr);margin-bottom:14px">
<div class="dza-kpi"><div class="v"><?php echo esc_html($C['pending-call']??0);?></div><div class="l">📞 بانتظار</div></div>
<div class="dza-kpi"><div class="v"><?php echo esc_html($C['confirmed']??0);?></div><div class="l">✅ مؤكد</div></div>
<div class="dza-kpi"><div class="v"><?php echo esc_html(($C['shipped']??0)+($C['in-transit']??0));?></div><div class="l">🚚 شحن</div></div>
<div class="dza-kpi"><div class="v"><?php echo esc_html($C['delivered']??0);?></div><div class="l">🎉 توصيل</div></div>
<div class="dza-kpi"><div class="v" style="color:var(--red)"><?php echo esc_html($C['rto']??0);?></div><div class="l">↩️ مرتجع</div></div>
<div class="dza-kpi"><div class="v" style="color:var(--green)"><?php echo esc_html($confirm_rate);?>%</div><div class="l">📊 تأكيد</div></div>
<div class="dza-kpi"><div class="v" style="color:var(--red)"><?php echo esc_html($rto_rate);?>%</div><div class="l">↩️ RTO</div></div>
<div class="dza-kpi"><div class="v" style="color:var(--green)"><?php echo number_format($rev,0);?></div><div class="l">💰 إيرادات (<?php echo esc_html($currency);?>)</div></div>
<div class="dza-kpi"><div class="v"><?php echo esc_html($total);?></div><div class="l">📦 إجمالي</div></div>
<div class="dza-kpi"><div class="v"><?php echo esc_html($active_offers);?></div><div class="l">🎁 عروض نشطة</div></div>
</div>

<!-- ═══ ADDON STATUS BAR ═══ -->
<div style="display:flex;flex-wrap:wrap;gap:6px;margin-bottom:14px;align-items:center">
<span style="font-size:12px;font-weight:800;color:var(--text2)">🧩 <?php echo esc_html($active_addons_count);?>/<?php echo esc_html($total_addons);?> إضافة:</span>
<?php
$addon_indicators=[
    'whatsapp-auto'=>['📱','واتساب',$wa_sent>0?$wa_sent.' رسالة':''],
    'sms-auto'=>['📲','SMS',$sms_sent>0?$sms_sent.' مرسلة':''],
    'chargily'=>['💳','Chargily',''],
    'baridimob'=>['📱','BaridiMob',''],
    'fraud-detect'=>['🛡️','احتيال',$fraud_count>0?$fraud_count.' تنبيه':''],
    'utm-tracking'=>['📈','UTM',$campaign_leads>0?$campaign_leads.' lead':''],
    'abandoned-cart'=>['🛒','مهجورة',$abandoned>0?$abandoned:''],
    'ab-testing'=>['🔬','A/B',$ab_running>0?$ab_running.' نشط':''],
    'yalidine'=>['🚚','Yalidine',''],
    'noest'=>['📦','NOEST',''],
    'custom-products'=>['🏗️','مخصص',''],
    'canva'=>['🎨','Canva',''],
];
foreach($addon_indicators as $aslug=>$ainfo):$aon=$addon_active($aslug);?>
<span style="display:inline-flex;align-items:center;gap:3px;padding:3px 8px;border-radius:14px;font-size:10px;font-weight:600;background:<?php echo esc_html($aon?'#dcfce7':'#f1f5f9');?>;color:<?php echo esc_html($aon?'#166534':'#94a3b8');?>" title="<?php echo esc_html($aon?'✅ مفعّل':'❌ معطّل');?>">
<?php echo esc_html($ainfo[0].' '.$ainfo[1]);?>
<?php if($aon&&$ainfo[2]):?><small style="opacity:.7">(<?php echo esc_html($ainfo[2]);?>)</small><?php endif;?>
</span>
<?php endforeach;?></div>

<!-- ═══ STATUS PILLS ═══ -->
<div class="dza-status-row"><?php foreach($S as $k=>$v):$c=$C[$k]??0;if(!$c&&!in_array($k,['pending-call','confirmed','shipped','delivered','rto']))continue;?>
<div class="dza-pill" style="background:<?php echo esc_html($v['c']);?>"><?php echo esc_html($v['i']);?> <?php echo esc_html($c);?><small><?php echo esc_html($v['l']);?></small></div>
<?php endforeach;?></div>

<!-- ═══ TWO COLUMN LAYOUT ═══ -->
<div class="dza-two-col">
<div class="dza-col">

<!-- Orders Table -->
<h2 class="dza-section-title">📦 آخر الطلبات</h2>
<table class="dza-table"><thead><tr><th>#</th><th>العميل</th><th>الهاتف</th><th><?php echo esc_html(\DZQCOD\Core::state_label());?></th><th>المبلغ</th><th>الحالة</th><th>تاريخ</th><th></th></tr></thead><tbody>
<?php foreach($recent as $o):$st=str_replace('wc-','',$o->get_status());$sc=$S[$st]??['l'=>$st,'c'=>'#999','i'=>''];?>
<tr>
<td><a href="<?php echo esc_url($o->get_edit_order_url());?>">#<?php echo(int)$o->get_id();?></a></td>
<td><?php echo esc_html($o->get_billing_first_name());?></td>
<td class="ltr"><?php echo esc_html($o->get_billing_phone());?></td>
<td><?php echo esc_html($o->get_shipping_state());?></td>
<td class="bold"><?php echo number_format((float)$o->get_total(),0);?> <?php echo esc_html($currency);?></td>
<td><span class="dza-badge" style="background:<?php echo esc_html($sc['c']);?>"><?php echo esc_html($sc['i'].' '.$sc['l']);?></span></td>
<td class="sm"><?php echo esc_html($o->get_date_created()?$o->get_date_created()->format('m/d H:i'):'-');?></td>
<td><button class="dza-btn sm print-receipt" data-id="<?php echo(int)$o->get_id();?>" title="طباعة">🖨️</button></td>
</tr>
<?php endforeach;?></tbody></table>
</div>

<!-- ═══ SIDEBAR ═══ -->
<div class="dza-sidebar">

<!-- Shipping Pipeline -->
<?php if($ship_total>0):?>
<div class="dza-card" style="border-right:3px solid var(--accent)">
<h3 style="border:none;margin:0 0 10px;font-size:14px">🚚 خط الشحن</h3>
<div style="display:flex;flex-direction:column;gap:6px">
<?php $stages=['ready'=>['🎯','جاهز','#6366f1'],'shipped'=>['📤','مرسل','#0ea5e9'],'transit'=>['🚛','في الطريق','#f59e0b'],'delivery'=>['🏍️','خارج للتوصيل','#f97316'],'delivered'=>['✅','مسلّم','#22c55e'],'rto'=>['↩️','مرتجع','#ef4444']];
foreach($stages as $sk=>$sv):$sv_count=$ship_pipeline[$sk]??0;$bar_w=$ship_total>0?round($sv_count/$ship_total*100):0;?>
<div style="display:flex;align-items:center;gap:6px;font-size:11px">
<span style="width:18px;text-align:center"><?php echo esc_html($sv[0]);?></span>
<div style="flex:1;background:#f1f5f9;border-radius:4px;height:16px;overflow:hidden">
<div style="background:<?php echo esc_html($sv[2]);?>;height:100%;width:<?php echo esc_html($bar_w);?>%;border-radius:4px;transition:.3s"></div></div>
<span style="min-width:30px;text-align:left;font-weight:700;color:<?php echo esc_html($sv[2]);?>"><?php echo esc_html($sv_count);?></span>
</div>
<?php endforeach;?></div></div>
<?php endif;?>

<!-- Campaigns -->
<?php if($addon_active('utm-tracking')&&!empty($top_campaigns)):?>
<div class="dza-card"><h3 style="border:none;margin:0 0 8px;font-size:14px">📈 أفضل الحملات</h3>
<?php foreach($top_campaigns as $tc):?><div class="dza-camp-row"><strong><?php echo esc_html($tc->utm_campaign?:'(مباشر)');?></strong><span><?php echo esc_html($tc->leads);?> • <?php echo esc_html($tc->confirmed);?> مؤكد</span></div><?php endforeach;?></div>
<?php endif;?>

<!-- Fraud -->
<?php if($addon_active('fraud-detect')&&!empty($fraud_alerts)):?>
<div class="dza-card" style="border-right:3px solid var(--red)"><h3 style="border:none;margin:0 0 8px;font-size:14px">🛡️ تنبيهات احتيال</h3>
<?php foreach($fraud_alerts as $fa):?><div class="dza-fraud-row"><span class="dza-badge" style="background:<?php echo esc_html($fa->score>=70?'#ef4444':'#f59e0b');?>"><?php echo esc_html($fa->score);?>%</span> <?php echo esc_html($fa->oid);?></div><?php endforeach;?></div>
<?php endif;?>

<!-- Messaging Stats -->
<?php if(($wa_sent+$sms_sent)>0):?>
<div class="dza-card"><h3 style="border:none;margin:0 0 8px;font-size:14px">💬 الرسائل (7 أيام)</h3>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:8px;font-size:12px">
<?php if($addon_active('whatsapp-auto')):?><div style="background:#dcfce7;border-radius:8px;padding:8px;text-align:center"><div style="font-size:18px;font-weight:900;color:#166534"><?php echo esc_html($wa_sent);?></div><div style="font-size:10px;color:#166534">💬 واتساب</div></div><?php endif;?>
<?php if($addon_active('sms-auto')):?><div style="background:#eff6ff;border-radius:8px;padding:8px;text-align:center"><div style="font-size:18px;font-weight:900;color:#1e40af"><?php echo esc_html($sms_sent);?></div><div style="font-size:10px;color:#1e40af">📲 SMS</div></div><?php endif;?>
</div>
<?php if($sms_failed>0):?><div style="font-size:10px;color:var(--red);margin-top:4px">❌ <?php echo esc_html($sms_failed);?> SMS فاشلة</div><?php endif;?>
</div>
<?php endif;?>

<!-- Abandoned -->
<?php if($addon_active('abandoned-cart')&&$abandoned>0):?>
<div class="dza-card" style="border-right:3px solid #f59e0b"><h3 style="border:none;margin:0 0 4px;font-size:14px">🛒 <?php echo esc_html($abandoned);?> سلة مهجورة</h3>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-smart-ops'));?>" style="font-size:12px">← معالجة الآن</a></div>
<?php endif;?>

<!-- System Info Mini -->
<div class="dza-card">
<h3 style="border:none;margin:0 0 8px;font-size:14px">ℹ️ النظام</h3>
<div style="display:grid;grid-template-columns:1fr 1fr;gap:6px;font-size:11px">
<div style="background:#f8fafc;border-radius:6px;padding:6px 8px;text-align:center"><span style="color:var(--text2)">الإصدار</span><br><strong style="color:var(--accent)"><?php echo esc_html(DZQCOD_VER);?></strong></div>
<div style="background:#f8fafc;border-radius:6px;padding:6px 8px;text-align:center"><span style="color:var(--text2)">الخطة</span><br><strong style="color:<?php echo esc_html($plan==='pro'?'var(--accent)':($plan==='enterprise'?'#f59e0b':'#94a3b8'));?>"><?php echo esc_html(strtoupper($plan));?></strong></div>
<div style="background:#f8fafc;border-radius:6px;padding:6px 8px;text-align:center"><span style="color:var(--text2)">🌍</span><br><strong><?php echo esc_html($country);?> (<?php echo esc_html($wil_count);?> <?php echo esc_html(\DZQCOD\Core::state_label());?>)</strong></div>
<div style="background:#f8fafc;border-radius:6px;padding:6px 8px;text-align:center"><span style="color:var(--text2)">🧩</span><br><strong style="color:var(--green)"><?php echo esc_html($active_addons_count);?>/<?php echo esc_html($total_addons);?></strong></div>
</div></div>

<!-- Quick Actions -->
<div class="dza-card"><h3 style="border:none;margin:0 0 8px;font-size:14px">⚡ إجراءات سريعة</h3>
<div style="display:flex;flex-direction:column;gap:6px">
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-call-center'));?>" class="dza-btn primary" style="justify-content:center;font-size:12px">📞 مركز الاتصال (<?php echo esc_html($C['pending-call']??0);?>)</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-orders'));?>" class="dza-btn" style="justify-content:center;font-size:12px">📦 كل الطلبات</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-shipping'));?>" class="dza-btn success" style="justify-content:center;font-size:12px">🚚 الشحن</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-pos'));?>" class="dza-btn" style="justify-content:center;font-size:12px">🖥️ نقطة البيع</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-printing'));?>" class="dza-btn ghost" style="justify-content:center;font-size:12px">🖨️ طباعة</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-offers'));?>" class="dza-btn ghost" style="justify-content:center;font-size:12px">🎁 العروض (<?php echo esc_html($active_offers);?>)</a>
<a href="<?php echo esc_url(admin_url('admin.php?page=dzqcod-addons'));?>" class="dza-btn ghost" style="justify-content:center;font-size:12px">🧩 الإضافات</a>
</div></div>

<!-- PRO CTA -->
<?php if($plan==='free'):?>
<div class="dza-card dza-pro-cta"><h3 style="font-size:15px">🚀 DZQCOD PRO</h3>
<p>واتساب آلي + 19 شركة شحن + 14 قالب + حملات تسويقية</p>
<a href="<?php echo esc_url($buy_url);?>" target="_blank" class="dza-btn primary" style="margin-top:6px">🛒 طلب الترخيص</a></div>
<?php endif;?>

</div><!-- sidebar -->
</div><!-- two-col -->

</div></div><!--dza-main--></div><!--dza-layout--></div><!--dza-wrap-->
