<?php require_once __DIR__.'/../config/config.php'; require_user();
$U=current_user();
$self=basename($_SERVER['PHP_SELF']);
function nav($h,$l,$i,$active,$hi=false){$a=$active===$h?'active':''; $s=$hi?' style="background:linear-gradient(90deg,#10b981,#059669);color:#fff;font-weight:700;border-radius:8px;margin:4px 0"':''; return '<a class="'.$a.'" href="'.$h.'"'.$s.'>'.$i.' '.$l.'</a>';}
$TG_LINK=trim(setting($pdo,'telegram_link',''));
$WA_LINK=trim(setting($pdo,'whatsapp_link',''));

// Sidebar mini-stats data (balance / recharge / total orders / today orders)
$__uid = (int)$U['id'];
$__side_orders = (int)$pdo->query("SELECT COUNT(*) c FROM orders WHERE user_id=$__uid")->fetch()['c'];
$__side_today  = (int)$pdo->query("SELECT COUNT(*) c FROM orders WHERE user_id=$__uid AND DATE(created_at)=CURDATE()")->fetch()['c'];

// Popup notice (fullscreen modal) — only if popup=1 & user hasn't dismissed for 10h
$__popup = null;
try {
  $__popup = $pdo->query("SELECT * FROM notices WHERE active=1 AND popup=1 ORDER BY id DESC LIMIT 1")->fetch();
} catch (Throwable $e) { $__popup = null; }
$__cookieKey = $__popup ? ('notice_hide_'.$__popup['id']) : '';
$__hidePopup = $__popup ? !empty($_COOKIE[$__cookieKey]) : true;
?><!doctype html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<title><?=e($PAGE_TITLE??'Dashboard')?></title>
<link href="https://fonts.googleapis.com/css2?family=Hind+Siliguri:wght@400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../assets/css/style.css?v=<?=@filemtime(__DIR__."/../assets/css/style.css")?:time()?>">
<style>
.social-fab{position:fixed;right:18px;bottom:18px;display:flex;flex-direction:column;gap:12px;z-index:9999}
.social-fab a{width:54px;height:54px;border-radius:50%;display:flex;align-items:center;justify-content:center;box-shadow:0 6px 18px rgba(0,0,0,.18);transition:transform .15s ease, box-shadow .15s ease;text-decoration:none}
.social-fab a:hover{transform:translateY(-2px);box-shadow:0 10px 22px rgba(0,0,0,.24)}
.social-fab .fab-tg{background:#229ED9}
.social-fab .fab-wa{background:#25D366}
.social-fab svg{width:30px;height:30px;display:block}
.social-side{display:flex;gap:8px;padding:10px 6px 4px;margin-top:8px;border-top:1px solid rgba(255,255,255,.12)}
.social-side a{flex:1;display:flex;align-items:center;justify-content:center;gap:6px;padding:8px 6px;border-radius:8px;color:#fff;font-weight:600;font-size:13px;text-decoration:none}
.social-side .s-tg{background:#229ED9}
.social-side .s-wa{background:#25D366}
.social-side svg{width:18px;height:18px}
@media (max-width:640px){.social-fab a{width:48px;height:48px}.social-fab svg{width:26px;height:26px}}

/* Sidebar close button (hamburger back) */
.sb-close{display:none;position:absolute;top:10px;right:10px;width:34px;height:34px;border-radius:50%;background:rgba(255,255,255,.12);color:#fff;border:none;font-size:20px;line-height:1;cursor:pointer;z-index:5}
.sb-close:hover{background:rgba(255,255,255,.22)}
@media(max-width:768px){.sidebar.open .sb-close{display:flex;align-items:center;justify-content:center}}

/* Sidebar mini-stats block */
.sb-stats{padding:10px 12px 4px;margin-top:6px;border-top:1px solid rgba(255,255,255,.12);display:grid;grid-template-columns:1fr 1fr;gap:6px}
.sb-stat{background:rgba(255,255,255,.08);color:#fff;padding:8px 10px;border-radius:8px;text-decoration:none;font-size:12px;line-height:1.2}
.sb-stat:hover{background:rgba(255,255,255,.16)}
.sb-stat .sbs-l{font-size:10px;opacity:.75;font-weight:600;text-transform:uppercase;letter-spacing:.3px}
.sb-stat .sbs-v{font-size:14px;font-weight:800;margin-top:2px;color:#fff}

/* Full-screen popup notice */
.notice-modal{position:fixed;inset:0;background:rgba(15,23,42,.55);display:flex;align-items:center;justify-content:center;z-index:100000;padding:20px;backdrop-filter:blur(4px)}
.notice-modal .box{background:#fff;border-radius:16px;max-width:520px;width:100%;max-height:90vh;overflow:auto;box-shadow:0 30px 60px rgba(0,0,0,.35);animation:zoomIn .2s ease}
.notice-modal .hd{padding:18px 22px 8px;color:#0f172a;font-size:20px;font-weight:800;line-height:1.3}
.notice-modal .bd{padding:0 22px 18px;color:#334155;font-size:15px;line-height:1.6;white-space:pre-wrap;word-wrap:break-word}
.notice-modal .ft{display:flex;justify-content:space-between;gap:10px;padding:14px 22px 18px;border-top:1px solid #f1f5f9}
.notice-modal .ft button{flex:1;padding:11px 14px;border:none;border-radius:10px;cursor:pointer;font-family:inherit;font-weight:700;font-size:14px}
.notice-modal .btn-hide{background:#f1f5f9;color:#475569}
.notice-modal .btn-hide:hover{background:#e2e8f0}
.notice-modal .btn-ok{background:linear-gradient(135deg,#6366f1,#8b5cf6);color:#fff}
.notice-modal .btn-ok:hover{opacity:.9}
@keyframes zoomIn{from{transform:scale(.92);opacity:0}to{transform:scale(1);opacity:1}}
</style>
</head><body>
<div class="app">
<aside class="sidebar" id="sb">
<button class="sb-close" onclick="document.getElementById('sb').classList.remove('open')" aria-label="Close menu">✕</button>
<h2>👤 <?=e($U['name'])?></h2>
<?=nav('search.php','সার্ভার কপি','🔍',$self,true)?>
<?=nav('auto_nid.php','অটো NID মেক','🪪',$self)?>
<?=nav('dashboard.php','ড্যাশবোর্ড','📊',$self)?>
<?=nav('history.php','হিস্টোরি','📜',$self)?>
<?=nav('services.php','সার্ভিস','🎯',$self)?>
<?=nav('recharge.php','রিচার্জ','💰',$self)?>
<?=nav('transactions.php','ট্রানজেকশন','💳',$self)?>
<?=nav('profile.php','প্রোফাইল','⚙️',$self)?>
<a href="../public/logout.php">🚪 লগআউট</a>
<?php if($TG_LINK||$WA_LINK):?>
<div class="social-side">
<?php if($TG_LINK):?>
<a class="s-tg" href="<?=e($TG_LINK)?>" target="_blank" rel="noopener" title="Telegram">
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M21.9 4.3 18.8 19.9c-.2 1-.9 1.3-1.7.8l-4.7-3.5-2.3 2.2c-.3.3-.5.5-1 .5l.3-4.8 8.7-7.9c.4-.3-.1-.5-.6-.2L6.7 13.2 2.1 11.7c-1-.3-1-1 .2-1.5L20.6 3.1c.8-.3 1.5.2 1.3 1.2Z" fill="#fff"/></svg>
Telegram</a>
<?php endif;?>
<?php if($WA_LINK):?>
<a class="s-wa" href="<?=e($WA_LINK)?>" target="_blank" rel="noopener" title="WhatsApp">
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path d="M19.11 17.205c-.372 0-1.088 1.39-1.518 1.39a.63.63 0 0 1-.315-.1c-.802-.402-1.504-.817-2.163-1.406-.545-.489-1.087-1.052-1.51-1.64-.588-.83-.288-1.02.1-1.35.169-.144.319-.31.457-.487.14-.181.146-.353.226-.596.081-.242.041-.464-.059-.633-.101-.169-.868-1.976-1.216-2.679-.288-.61-.577-.514-.797-.514-.204 0-.436-.02-.668-.02-.204 0-.545.062-.83.302-.29.242-1.09 1.052-1.09 2.573s1.11 2.983 1.263 3.186c.152.202 2.163 3.6 5.402 4.888.541.209 1.023.334 1.365.415.573.128 1.096.11 1.51.066.463-.058 1.42-.577 1.62-1.13.196-.554.196-1.026.14-1.13-.06-.104-.213-.166-.44-.278Zm-4.936 8.06h-.024c-1.66 0-3.288-.446-4.705-1.288l-.337-.2-3.5.918.936-3.418-.219-.351a10.28 10.28 0 0 1-1.573-5.462c.002-5.686 4.63-10.313 10.323-10.313 2.755 0 5.345 1.076 7.293 3.03 1.948 1.95 3.02 4.544 3.02 7.29a10.31 10.31 0 0 1-10.213 10.394Zm8.786-19.098A12.365 12.365 0 0 0 14.18 2.53C7.415 2.53 1.907 8.032 1.905 14.795a12.24 12.24 0 0 0 1.633 6.14L1.71 27.472l6.677-1.75a12.331 12.331 0 0 0 5.878 1.492h.006c6.762 0 12.271-5.502 12.274-12.264a12.19 12.19 0 0 0-3.586-8.673Z" fill="#fff"/></svg>
WhatsApp</a>
<?php endif;?>
</div>
<?php endif;?>
<div class="sb-stats">
  <a class="sb-stat" href="transactions.php"><div class="sbs-l">💵 ব্যালেন্স</div><div class="sbs-v"><?=money($U['balance'])?></div></a>
  <a class="sb-stat" href="recharge.php"><div class="sbs-l">💰 রিচার্জ</div><div class="sbs-v"><?=money($U['total_recharge'])?></div></a>
  <a class="sb-stat" href="history.php"><div class="sbs-l">📦 মোট অর্ডার</div><div class="sbs-v"><?=$__side_orders?></div></a>
  <a class="sb-stat" href="history.php"><div class="sbs-l">📅 আজকের</div><div class="sbs-v"><?=$__side_today?></div></a>
</div>
</aside>
<div class="main">
<div class="topbar">
<button class="hamburger" onclick="document.getElementById('sb').classList.toggle('open')">☰</button>
<div><b><?=e(setting($pdo,'site_name',SITE_NAME))?></b></div>
<?php if(($U['role']??'')==='admin'):?><a href="../admin/dashboard.php" style="background:linear-gradient(90deg,#7c3aed,#4c1d95);color:#fff;padding:6px 12px;border-radius:8px;text-decoration:none;font-size:13px;font-weight:600;margin-right:8px">👑 Admin Panel →</a><?php endif;?>
<div>💰 <b><?=money($U['balance'])?></b></div>
</div>
<?php if($TG_LINK||$WA_LINK):?>
<div class="social-fab">
<?php if($TG_LINK):?>
<a class="fab-tg" href="<?=e($TG_LINK)?>" target="_blank" rel="noopener" aria-label="Telegram">
<svg viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M21.9 4.3 18.8 19.9c-.2 1-.9 1.3-1.7.8l-4.7-3.5-2.3 2.2c-.3.3-.5.5-1 .5l.3-4.8 8.7-7.9c.4-.3-.1-.5-.6-.2L6.7 13.2 2.1 11.7c-1-.3-1-1 .2-1.5L20.6 3.1c.8-.3 1.5.2 1.3 1.2Z" fill="#fff"/></svg>
</a>
<?php endif;?>
<?php if($WA_LINK):?>
<a class="fab-wa" href="<?=e($WA_LINK)?>" target="_blank" rel="noopener" aria-label="WhatsApp">
<svg viewBox="0 0 32 32" xmlns="http://www.w3.org/2000/svg"><path d="M19.11 17.205c-.372 0-1.088 1.39-1.518 1.39a.63.63 0 0 1-.315-.1c-.802-.402-1.504-.817-2.163-1.406-.545-.489-1.087-1.052-1.51-1.64-.588-.83-.288-1.02.1-1.35.169-.144.319-.31.457-.487.14-.181.146-.353.226-.596.081-.242.041-.464-.059-.633-.101-.169-.868-1.976-1.216-2.679-.288-.61-.577-.514-.797-.514-.204 0-.436-.02-.668-.02-.204 0-.545.062-.83.302-.29.242-1.09 1.052-1.09 2.573s1.11 2.983 1.263 3.186c.152.202 2.163 3.6 5.402 4.888.541.209 1.023.334 1.365.415.573.128 1.096.11 1.51.066.463-.058 1.42-.577 1.62-1.13.196-.554.196-1.026.14-1.13-.06-.104-.213-.166-.44-.278Zm-4.936 8.06h-.024c-1.66 0-3.288-.446-4.705-1.288l-.337-.2-3.5.918.936-3.418-.219-.351a10.28 10.28 0 0 1-1.573-5.462c.002-5.686 4.63-10.313 10.323-10.313 2.755 0 5.345 1.076 7.293 3.03 1.948 1.95 3.02 4.544 3.02 7.29a10.31 10.31 0 0 1-10.213 10.394Zm8.786-19.098A12.365 12.365 0 0 0 14.18 2.53C7.415 2.53 1.907 8.032 1.905 14.795a12.24 12.24 0 0 0 1.633 6.14L1.71 27.472l6.677-1.75a12.331 12.331 0 0 0 5.878 1.492h.006c6.762 0 12.271-5.502 12.274-12.264a12.19 12.19 0 0 0-3.586-8.673Z" fill="#fff"/></svg>
</a>
<?php endif;?>
</div>
<?php endif;?>

<?php if($__popup && !$__hidePopup && $self==='dashboard.php'): ?>
<div id="noticeModal" class="notice-modal" onclick="if(event.target===this)closeNoticeModal(false)">
  <div class="box" role="dialog" aria-modal="true">
    <div class="hd">📢 <?=e($__popup['title'])?></div>
    <div class="bd"><?=nl2br(e($__popup['body']))?></div>
    <div class="ft">
      <button type="button" class="btn-hide" onclick="closeNoticeModal(true)">🚫 আর দেখবো না</button>
      <button type="button" class="btn-ok" onclick="closeNoticeModal(false)">✅ ওকে</button>
    </div>
  </div>
</div>
<script>
function closeNoticeModal(hide10h){
  var m=document.getElementById('noticeModal'); if(m){m.style.display='none';}
  if(hide10h){
    var d=new Date(); d.setTime(d.getTime()+10*60*60*1000);
    document.cookie='<?=e($__cookieKey)?>=1; expires='+d.toUTCString()+'; path=/; SameSite=Lax';
  }
}
</script>
<?php endif; ?>
