<?php
/**
 * index.php — বধুবরণ জুয়েলার্স ERP Dashboard
 * Upload: /home/jewellersbd/public_html/erp.jewellersbd.com/index.php
 */
require_once __DIR__ . '/config/session.php';
require_once __DIR__ . '/config/db.php';

if (session_status() === PHP_SESSION_NONE) session_start();
if (empty($_SESSION['user_id'])) {
    header('Location: ui/login.html');
    exit;
}

$today = date('Y-m-d');

$cash_rows = $pdo->query("SELECT account_name_bn, account_name, current_balance FROM cash_accounts WHERE is_active=1 AND deleted_at IS NULL ORDER BY sort_order,id")->fetchAll(PDO::FETCH_ASSOC);
$total_cash = array_sum(array_column($cash_rows, 'current_balance'));

$r = $pdo->prepare("SELECT SUM(CASE WHEN direction='IN' AND is_deleted=0 THEN amount ELSE 0 END) ti, SUM(CASE WHEN direction='OUT' AND is_deleted=0 THEN amount ELSE 0 END) to_ FROM cash_transactions WHERE transaction_date=?");
$r->execute([$today]);
$tc = $r->fetch(PDO::FETCH_ASSOC);
$today_in  = (float)($tc['ti']  ?? 0);
$today_out = (float)($tc['to_'] ?? 0);

$ps = $pdo->query("SELECT COUNT(*) cnt, SUM(outstanding_principal) op FROM pawn_pledges WHERE status='OPEN'")->fetch(PDO::FETCH_ASSOC);
$pledge_count       = (int)($ps['cnt'] ?? 0);
$pledge_outstanding = (float)($ps['op'] ?? 0);

$overdue = (int)$pdo->query("
    SELECT COUNT(*) FROM pawn_pledges p WHERE p.status='OPEN'
    AND NOT EXISTS (SELECT 1 FROM pawn_payments pp WHERE pp.pledge_id=p.id AND pp.payment_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY))
    AND DATEDIFF(CURDATE(), p.pledge_date) > 30
")->fetchColumn();

$ss = $pdo->prepare("SELECT COUNT(*) cnt, COALESCE(SUM(grand_total),0) total FROM sales WHERE DATE(sale_date)=?");
$ss->execute([$today]);
$sales_today = $ss->fetch(PDO::FETCH_ASSOC);

$gold = $pdo->query("SELECT rate_24k, rate_22k, rate_21k, rate_18k, rate_date FROM gold_rates ORDER BY rate_date DESC, id DESC LIMIT 1")->fetch(PDO::FETCH_ASSOC);
$stock_cnt = (int)$pdo->query("SELECT COUNT(*) FROM barcode_stock WHERE status='in_stock' AND is_deleted=0")->fetchColumn();

$int_total = 0;
foreach ($pdo->query("SELECT outstanding_principal, interest_rate, pledge_date FROM pawn_pledges WHERE status='OPEN'")->fetchAll(PDO::FETCH_ASSOC) as $pl) {
    $days = (int)(new DateTime($pl['pledge_date']))->diff(new DateTime($today))->days;
    $int_total += (float)$pl['outstanding_principal'] * ((float)$pl['interest_rate'] / 100) * ($days / 30);
}

$overdue_list = $pdo->query("
    SELECT p.id, p.pledge_code, p.outstanding_principal, p.interest_rate, p.pledge_date,
           pa.name AS party_name, DATEDIFF(CURDATE(), p.pledge_date) AS days
    FROM pawn_pledges p LEFT JOIN parties pa ON pa.id=p.party_id
    WHERE p.status='OPEN'
    AND NOT EXISTS (SELECT 1 FROM pawn_payments pp WHERE pp.pledge_id=p.id AND pp.payment_date >= DATE_SUB(CURDATE(), INTERVAL 30 DAY))
    AND DATEDIFF(CURDATE(), p.pledge_date) > 30
    ORDER BY days DESC LIMIT 5
")->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="bn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
<title>বধুবরণ জুয়েলার্স ERP</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Serif+Bengali:wght@400;600;700&display=swap" rel="stylesheet">
<style>
:root{--bg:#0b1622;--bg2:#111d2c;--bg3:#172435;--border:#1e3048;--gold:#d4a843;--gold2:#f0c857;--gold3:#7a5c10;--green:#27ae60;--green2:#1a7a42;--red:#e74c3c;--red2:#9b2020;--blue:#3498db;--orange:#e67e22;--purple:#9b59b6;--teal:#1abc9c;--text:#e8eef5;--text2:#8fa3b8;--text3:#4a6278;}
*{box-sizing:border-box;margin:0;padding:0;}
body{font-family:'Noto Serif Bengali',serif;background:var(--bg);color:var(--text);font-size:14px;padding-bottom:90px;}
.topbar{background:var(--bg2);padding:0 16px;height:54px;display:flex;align-items:center;gap:10px;position:sticky;top:0;z-index:200;border-bottom:2px solid var(--gold);box-shadow:0 2px 16px rgba(0,0,0,.5);}
.logo{display:flex;align-items:center;gap:9px;flex:1;}
.logo-box{width:36px;height:36px;background:linear-gradient(135deg,var(--gold) 0%,#b8860b 100%);border-radius:9px;display:flex;align-items:center;justify-content:center;font-size:19px;box-shadow:0 2px 8px rgba(212,168,67,.4);}
.logo-text .shop{font-size:13px;font-weight:700;color:var(--text);}
.logo-text .sub{font-size:10px;color:var(--text3);}
.tb-right{text-align:right;}
.tb-date{font-size:13px;font-weight:700;color:var(--gold2);}
.tb-day{font-size:10px;color:var(--text3);}
.btn-out{padding:6px 11px;background:transparent;color:var(--text3);border:1px solid var(--border);border-radius:6px;font-size:11px;cursor:pointer;text-decoration:none;font-family:inherit;}
.container{max-width:720px;margin:0 auto;padding:14px 12px;}
.gold-banner{background:linear-gradient(135deg,#1a2d1a 0%,#0f1d0f 50%,#1a1d0a 100%);border:1px solid rgba(212,168,67,.25);border-left:4px solid var(--gold);border-radius:12px;padding:13px 15px;margin-bottom:12px;}
.gb-head{font-size:10px;color:var(--gold);font-weight:700;text-transform:uppercase;letter-spacing:.7px;margin-bottom:10px;}
.gb-rates{display:grid;grid-template-columns:repeat(4,1fr);gap:0;}
.gb-item{text-align:center;padding:0 6px;border-right:1px solid rgba(255,255,255,.06);}
.gb-item:last-child{border-right:none;}
.gb-karat{font-size:10px;color:var(--text3);font-weight:700;}
.gb-price{font-size:15px;font-weight:800;color:var(--gold2);margin:2px 0 1px;}
.gb-unit{font-size:9px;color:var(--text3);}
.today-strip{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:12px;}
.ts-card{background:var(--bg2);border:1px solid var(--border);border-radius:10px;padding:11px 10px;text-align:center;}
.ts-label{font-size:10px;color:var(--text3);font-weight:600;text-transform:uppercase;}
.ts-val{font-size:16px;font-weight:800;margin-top:3px;}
.ts-in{color:var(--green);}.ts-out{color:var(--red);}.ts-net{color:var(--gold2);}
.stats-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:12px;}
.st-card{background:var(--bg2);border:1px solid var(--border);border-radius:11px;padding:13px 14px;position:relative;overflow:hidden;}
.st-card::after{content:attr(data-icon);position:absolute;right:8px;bottom:4px;font-size:36px;opacity:.06;}
.st-label{font-size:10px;color:var(--text3);font-weight:700;text-transform:uppercase;letter-spacing:.4px;}
.st-val{font-size:19px;font-weight:800;margin-top:3px;line-height:1.1;}
.st-sub{font-size:11px;color:var(--text3);margin-top:3px;}
.c-blue .st-val{color:var(--blue);}.c-gold .st-val{color:var(--gold2);}.c-green .st-val{color:var(--green);}.c-red .st-val{color:var(--red);}
.dot{display:inline-block;width:7px;height:7px;background:var(--red);border-radius:50%;margin-left:3px;animation:p 1.4s infinite;}
@keyframes p{0%,100%{opacity:1}50%{opacity:.2}}
.cash-scroll{display:flex;gap:8px;overflow-x:auto;margin-bottom:12px;padding-bottom:2px;scrollbar-width:none;}
.cash-scroll::-webkit-scrollbar{display:none;}
.cc{flex:0 0 auto;background:var(--bg2);border:1px solid var(--border);border-top:2px solid var(--gold);border-radius:9px;padding:9px 13px;min-width:110px;text-decoration:none;}
.cc-name{font-size:10px;color:var(--text3);font-weight:600;white-space:nowrap;}
.cc-bal{font-size:14px;font-weight:800;color:var(--gold2);margin-top:2px;}
.sec-lbl{font-size:10px;font-weight:700;color:var(--text3);text-transform:uppercase;letter-spacing:.8px;margin-bottom:8px;display:flex;align-items:center;gap:8px;}
.sec-lbl::after{content:'';flex:1;height:1px;background:var(--border);}
.quick-grid{display:grid;grid-template-columns:1fr 1fr 1fr;gap:8px;margin-bottom:12px;}
.q-btn{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:5px;padding:13px 6px;border:none;border-radius:11px;text-decoration:none;color:#fff;font-size:11px;font-weight:700;cursor:pointer;font-family:inherit;transition:filter .15s,transform .12s;border-bottom:3px solid rgba(0,0,0,.3);}
.q-btn:active{transform:scale(.95);filter:brightness(.9);}
.q-btn .qi{font-size:22px;line-height:1;}
.qc1{background:linear-gradient(135deg,#27ae60,#1e8449);}
.qc2{background:linear-gradient(135deg,#2471a3,#1a5276);}
.qc3{background:linear-gradient(135deg,#d4a843,#9a7410);color:#1a1a1a;}
.qc4{background:linear-gradient(135deg,#e74c3c,#922b21);}
.qc5{background:linear-gradient(135deg,#e67e22,#a04000);}
.qc6{background:linear-gradient(135deg,#1abc9c,#0e6b5a);}
.mod-grid{display:grid;grid-template-columns:1fr 1fr;gap:8px;margin-bottom:12px;}
.mod{background:var(--bg2);border:1px solid var(--border);border-radius:11px;padding:14px 13px;text-decoration:none;color:var(--text);display:flex;flex-direction:column;gap:5px;position:relative;overflow:hidden;transition:border-color .15s,transform .12s;}
.mod:active{transform:scale(.97);}
.mod::before{content:'';position:absolute;top:0;left:0;right:0;height:3px;border-radius:11px 11px 0 0;}
.m-gold::before{background:var(--gold);}.m-green::before{background:var(--green);}.m-blue::before{background:var(--blue);}.m-red::before{background:var(--red);}.m-purple::before{background:var(--purple);}.m-teal::before{background:var(--teal);}.m-orange::before{background:var(--orange);}.m-navy::before{background:#3d5a80;}
.mod-icon{font-size:24px;line-height:1;}.mod-name{font-size:13px;font-weight:700;color:var(--text);}.mod-desc{font-size:11px;color:var(--text3);}
.mod-badge{position:absolute;top:10px;right:10px;background:var(--red);color:#fff;font-size:10px;font-weight:800;padding:2px 7px;border-radius:20px;}
.od-item{background:var(--bg2);border:1px solid var(--border);border-left:3px solid var(--red);border-radius:10px;padding:11px 13px;margin-bottom:6px;display:flex;justify-content:space-between;align-items:center;text-decoration:none;color:var(--text);}
.od-name{font-size:13px;font-weight:700;}.od-code{font-size:11px;color:var(--text3);}.od-amt{font-size:13px;font-weight:800;color:var(--red);}.od-days{font-size:10px;color:var(--text3);text-align:right;}
.see-all{display:block;text-align:center;padding:9px;font-size:12px;color:var(--blue);text-decoration:none;}
.bnav{position:fixed;bottom:0;left:0;right:0;background:var(--bg2);border-top:2px solid var(--gold);display:flex;z-index:300;padding-bottom:env(safe-area-inset-bottom,0);box-shadow:0 -4px 20px rgba(0,0,0,.4);}
.bn{flex:1;display:flex;flex-direction:column;align-items:center;padding:8px 4px;text-decoration:none;color:var(--text3);font-size:9px;font-weight:600;gap:2px;font-family:inherit;transition:color .15s;}
.bn.active,.bn:active{color:var(--gold2);}
.bn .bi{font-size:20px;line-height:1;}
</style>
</head>
<body>
<div class="topbar">
  <div class="logo">
    <div class="logo-box">💍</div>
    <div class="logo-text">
      <div class="shop">বধুবরণ জুয়েলার্স</div>
      <div class="sub">ERP System</div>
    </div>
  </div>
  <div class="tb-right">
    <div class="tb-date"><?= date('d M Y') ?></div>
    <div class="tb-day"><?= ['Sun'=>'রবি','Mon'=>'সোম','Tue'=>'মঙ্গল','Wed'=>'বুধ','Thu'=>'বৃহ','Fri'=>'শুক্র','Sat'=>'শনি'][date('D')] ?></div>
  </div>
  <a href="ui/notifications.html" class="btn-out" id="bellBtn" style="position:relative;font-size:18px;padding:6px 10px">🔔<span id="bellCount" style="display:none;position:absolute;top:-4px;right:-4px;background:#e05c5c;color:#fff;border-radius:50%;width:16px;height:16px;font-size:9px;align-items:center;justify-content:center;font-weight:700"></span></a>
  <a href="api/auth/logout.php" class="btn-out">লগআউট</a>
</div>

<div class="container">

  <?php if ($gold): ?>
  <div class="gold-banner">
    <div class="gb-head">💛 স্বর্ণ মূল্য — <?= $gold['rate_date'] ?> (প্রতি ভরি)</div>
    <div class="gb-rates">
      <div class="gb-item"><div class="gb-karat">24K বাজার</div><div class="gb-price">৳<?= number_format((float)$gold['rate_24k']*11.664,0) ?></div><div class="gb-unit">প্রতি ভরি</div></div>
      <div class="gb-item"><div class="gb-karat">22K বিক্রয়</div><div class="gb-price">৳<?= number_format((float)$gold['rate_22k']*11.664,0) ?></div><div class="gb-unit">প্রতি ভরি</div></div>
      <div class="gb-item"><div class="gb-karat">21K বিক্রয়</div><div class="gb-price">৳<?= number_format((float)$gold['rate_21k']*11.664,0) ?></div><div class="gb-unit">প্রতি ভরি</div></div>
      <div class="gb-item"><div class="gb-karat">18K বিক্রয়</div><div class="gb-price">৳<?= number_format((float)$gold['rate_18k']*11.664,0) ?></div><div class="gb-unit">প্রতি ভরি</div></div>
    </div>
  </div>
  <?php endif; ?>

  <div class="today-strip">
    <div class="ts-card"><div class="ts-label">▲ আজকের আয়</div><div class="ts-val ts-in">৳<?= number_format($today_in,0) ?></div></div>
    <div class="ts-card"><div class="ts-label">▼ আজকের ব্যয়</div><div class="ts-val ts-out">৳<?= number_format($today_out,0) ?></div></div>
    <div class="ts-card"><div class="ts-label">↕ নেট</div><div class="ts-val ts-net">৳<?= number_format($today_in-$today_out,0) ?></div></div>
  </div>

  <div class="stats-grid">
    <div class="st-card c-blue" data-icon="💵"><div class="st-label">মোট নগদ ব্যালেন্স</div><div class="st-val">৳<?= number_format($total_cash,0) ?></div><div class="st-sub"><?= count($cash_rows) ?> টি account</div></div>
    <div class="st-card c-gold" data-icon="📦"><div class="st-label">Barcode Stock</div><div class="st-val"><?= $stock_cnt ?> পিস</div><div class="st-sub">in_stock</div></div>
    <div class="st-card c-red" data-icon="🔒"><div class="st-label">সক্রিয় বন্ধক</div><div class="st-val"><?= $pledge_count ?> টি<?= $overdue>0?'<span class="dot"></span>':'' ?></div><div class="st-sub">বকেয়া: ৳<?= number_format($pledge_outstanding,0) ?></div></div>
    <div class="st-card c-green" data-icon="📈"><div class="st-label">সুদ আদায়যোগ্য</div><div class="st-val">৳<?= number_format($int_total,0) ?></div><div class="st-sub">সব বন্ধক মিলে</div></div>
  </div>

  <div class="cash-scroll">
    <?php foreach ($cash_rows as $ca): ?>
    <a href="cash_daily.php" class="cc">
      <div class="cc-name"><?= htmlspecialchars($ca['account_name_bn'] ?: $ca['account_name']) ?></div>
      <div class="cc-bal">৳<?= number_format($ca['current_balance'],0) ?></div>
    </a>
    <?php endforeach; ?>
  </div>

  <div class="sec-lbl">⚡ দ্রুত কাজ</div>
  <div class="quick-grid">
    <a href="ui/sales.html" class="q-btn qc1"><span class="qi">🛍️</span>নতুন বিক্রয়</a>
    <a href="pawn.php" class="q-btn qc2"><span class="qi">🔒</span>নতুন বন্ধক</a>
    <a href="cash_entry.php" class="q-btn qc3"><span class="qi">💵</span>Cash IN/OUT</a>
    <a href="ui/new_purchase.html" class="q-btn qc6"><span class="qi">🛒</span>নতুন ক্রয়</a>
    <a href="pledge_interest.php" class="q-btn qc4"><span class="qi">📈</span>সুদ হিসাব</a>
    <a href="ui/locker_summary.html" class="q-btn qc5"><span class="qi">🔐</span>লকার সামারি</a>
  </div>

  <div class="sec-lbl">📱 সব Module</div>
  <div class="mod-grid">
    <a href="ui/sales.html" class="mod m-green"><span class="mod-icon">🛍️</span><span class="mod-name">বিক্রয়</span><span class="mod-desc">Sales, Invoice, Due</span><?php if((int)$sales_today['cnt']>0):?><span class="mod-badge"><?=$sales_today['cnt']?></span><?php endif;?></a>
    <a href="ui/pledges.html" class="mod m-navy"><span class="mod-icon">🔒</span><span class="mod-name">বন্ধক ম্যানেজমেন্ট</span><span class="mod-desc">Pledge, Payment, Close</span><?php if($overdue>0):?><span class="mod-badge"><?=$overdue?>!</span><?php endif;?></a>
    <a href="cash_entry.php" class="mod m-blue"><span class="mod-icon">💵</span><span class="mod-name">Cash Module</span><span class="mod-desc">IN/OUT, Transfer, Voucher</span></a>
    <a href="cash_daily.php" class="mod m-gold"><span class="mod-icon">📊</span><span class="mod-name">Daily Closing</span><span class="mod-desc">দৈনিক হিসাব বন্ধ</span></a>
    <a href="ui/new_purchase.html" class="mod m-teal"><span class="mod-icon">🛒</span><span class="mod-name">নতুন ক্রয়</span><span class="mod-desc">Purchase, Stock Entry</span></a>
    <a href="ui/purchases.html" class="mod m-orange"><span class="mod-icon">🧾</span><span class="mod-name">ক্রয় তালিকা</span><span class="mod-desc">Purchase History, Due</span></a>
    <a href="ui/barcode_stock.html" class="mod m-orange"><span class="mod-icon">🏷️</span><span class="mod-name">Barcode Stock</span><span class="mod-desc">Stock, Barcode Print</span></a>
    <a href="ui/karigar_list.html" class="mod m-purple"><span class="mod-icon">🔨</span><span class="mod-name">কারিগর</span><span class="mod-desc">Issue, Receive, Labour</span></a>
    <a href="ui/gold_rate.html" class="mod m-gold"><span class="mod-icon">💛</span><span class="mod-name">স্বর্ণ মূল্য</span><span class="mod-desc">Gold Rate আপডেট</span></a>
    <a href="ui/parties.html" class="mod m-blue"><span class="mod-icon">👥</span><span class="mod-name">গ্রাহক/সরবরাহকারী</span><span class="mod-desc">Party Master List</span></a>
    <a href="ui/barcode_sale.html" class="mod m-green"><span class="mod-icon">📱</span><span class="mod-name">Barcode Sale</span><span class="mod-desc">Scan & Sell</span></a>
    <a href="ui/sales_list.html" class="mod m-teal"><span class="mod-icon">📋</span><span class="mod-name">বিক্রয় তালিকা</span><span class="mod-desc">History, Invoice Print</span></a>
    <a href="pledge_interest.php" class="mod m-red"><span class="mod-icon">📈</span><span class="mod-name">সুদ হিসাব</span><span class="mod-desc">Interest Due List</span><?php if($overdue>0):?><span class="mod-badge"><?=$overdue?>⚠</span><?php endif;?></a>
    <a href="ui/locker_summary.html" class="mod m-navy"><span class="mod-icon">🔐</span><span class="mod-name">লকার সামারি</span><span class="mod-desc">বিনিয়োগ ও মাসিক ভাড়া হিসাব</span></a>
    <a href="ui/locker_analysis.html" class="mod m-purple"><span class="mod-icon">📊</span><span class="mod-name">লকার ভাড়া বিশ্লেষণ</span><span class="mod-desc">প্রতি বন্ধকের বিস্তারিত হিসাব</span></a>
    <a href="ui/lockers.html" class="mod m-red"><span class="mod-icon">🗝️</span><span class="mod-name">লকার তালিকা</span><span class="mod-desc">Locker Party Master</span></a>
    <a href="ui/cash_party_report.html" class="mod m-blue"><span class="mod-icon">📒</span><span class="mod-name">পার্টি লেজার</span><span class="mod-desc">Receivable / Payable</span></a>
    <a href="ui/daily_report.html" class="mod m-gold"><span class="mod-icon">📅</span><span class="mod-name">দৈনিক রিপোর্ট</span><span class="mod-desc">Sales, Purchase, Cash Summary</span></a>
    <a href="ui/reports.html" class="mod m-gold"><span class="mod-icon">📊</span><span class="mod-name">রিপোর্ট সমূহ</span><span class="mod-desc">বিক্রি, ক্রয়, স্টক, Cash Flow</span></a>
    <a href="ui/stock_transfer.html" class="mod m-teal"><span class="mod-icon">🔄</span><span class="mod-name">স্টক ট্রান্সফার</span><span class="mod-desc">Factory ↔ Showroom ↔ Locker</span></a>
    <a href="ui/users.html" class="mod m-purple"><span class="mod-icon">👤</span><span class="mod-name">ইউজার ম্যানেজমেন্ট</span><span class="mod-desc">Role, Permission</span></a>

    <!-- Madhab 2.0 Private Focus Module -->
    <a href="ui/madhab.html" class="mod m-purple">
      <span class="mod-icon">🧘</span>
      <span class="mod-name">Madhab 2.0</span>
      <span class="mod-desc">Focus, Meditation, Mental Reset</span>
    </a>
  </div>

  <?php if(!empty($overdue_list)):?>
  <div class="sec-lbl">⚠️ Overdue বন্ধক (<?=count($overdue_list)?> টি)</div>
  <?php foreach($overdue_list as $pl):
    $int=round((float)$pl['outstanding_principal']*((float)$pl['interest_rate']/100)*($pl['days']/30),0);?>
  <a href="pledge_payment.php?pledge_id=<?=$pl['id']?>" class="od-item">
    <div><div class="od-name"><?=htmlspecialchars($pl['party_name'])?></div><div class="od-code"><?=$pl['pledge_code']?></div></div>
    <div><div class="od-amt">৳<?=number_format($int,0)?> সুদ</div><div class="od-days"><?=$pl['days']?> দিন</div></div>
  </a>
  <?php endforeach;?>
  <a href="pledge_interest.php" class="see-all">সব Overdue দেখুন →</a>
  <?php endif;?>

</div>

<div class="bnav">
  <a href="index.php" class="bn active"><span class="bi">🏠</span>হোম</a>
  <a href="ui/pledges.html" class="bn"><span class="bi">🔒</span>বন্ধক</a>
  <a href="ui/sales.html" class="bn"><span class="bi">🛍️</span>বিক্রয়</a>
  <a href="pledge_interest.php" class="bn"><span class="bi">📈</span>সুদ</a>
  <a href="ui/reports.html" class="bn"><span class="bi">📊</span>রিপোর্ট</a>
  <a href="cash_entry.php" class="bn"><span class="bi">💵</span>Cash</a>
</div>

<script>
(async function() {
  try {
    const res  = await fetch('api/notifications/get_notifications.php');
    const data = await res.json();
    if (data.success && data.count > 0) {
      const el = document.getElementById('bellCount');
      if (el) {
        el.textContent = data.high > 0 ? data.high : data.count;
        el.style.display = 'flex';
      }
    }
  } catch(e) {}
})();
</script>
</body>
</html>