<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Dashboard — WhatsApp Cloud API</title>
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
    <style>
        * { margin: 0; padding: 0; box-sizing: border-box; }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
            background: #f0f2f5;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* ── HEADER ── */
        header {
            background: #000;
            color: #fff;
            height: 58px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 1.75rem;
            position: fixed;
            top: 0; left: 0; right: 0;
            z-index: 200;
            border-bottom: 1px solid #1a1a1a;
        }

        .brand {
            display: flex;
            align-items: center;
            gap: 0.65rem;
            font-size: 1rem;
            font-weight: 700;
            letter-spacing: 0.3px;
            color: #fff;
        }
        .brand svg { width: 30px; height: 30px; }
        .brand-logo { height: 36px; width: auto; max-width: 160px; object-fit: contain; }
        .user-avatar { width:32px; height:32px; border-radius:50%; object-fit:cover; border:2px solid #333; flex-shrink:0; }
        .user-avatar-initials { width:32px; height:32px; border-radius:50%; background:#25d366; display:flex; align-items:center; justify-content:center; font-weight:700; font-size:.82rem; color:#000; flex-shrink:0; }

        .header-right {
            display: flex;
            align-items: center;
            gap: 1rem;
            font-size: 0.85rem;
        }
        .header-right .username { color: #aaa; font-weight: 500; }

        .btn-logout {
            background: transparent;
            border: 1px solid #333;
            color: #ccc;
            padding: 0.38rem 1rem;
            border-radius: 7px;
            cursor: pointer;
            font-size: 0.82rem;
            font-weight: 600;
            transition: border-color 0.2s, color 0.2s;
        }
        .btn-logout:hover { border-color: #666; color: #fff; }

        /* ── LAYOUT ── */
        .layout {
            display: flex;
            flex: 1;
            margin-top: 58px;
            min-height: calc(100vh - 58px);
        }

        /* ── SIDEBAR ── */
        aside {
            width: 248px;
            background: #000;
            color: #fff;
            position: fixed;
            top: 58px;
            left: 0;
            bottom: 0;
            overflow-y: auto;
            padding: 1.25rem 0 2rem;
            border-right: 1px solid #1c1c1c;
            scrollbar-width: thin;
            scrollbar-color: #2a2a2a #000;
        }

        .nav-section-label {
            padding: 1.2rem 1.4rem 0.4rem;
            font-size: 0.63rem;
            font-weight: 700;
            letter-spacing: 1.4px;
            color: #aab;
            text-transform: uppercase;
        }

        .nav-item {
            display: flex;
            align-items: center;
            gap: 0.8rem;
            padding: 0.7rem 1.4rem;
            color: #d1d5db;
            text-decoration: none;
            font-size: 0.88rem;
            font-weight: 500;
            border-left: 3px solid transparent;
            transition: background 0.18s, color 0.18s, border-color 0.18s;
            white-space: nowrap;
            cursor: pointer;
        }

        /* Hover = green bg, black text */
        .nav-item:hover {
            background: #25d366;
            color: #000;
            border-left-color: #1db954;
        }
        .nav-item:hover svg { opacity: 1; color: #000; }

        /* Active = green bg, black text */
        .nav-item.active {
            background: #25d366;
            color: #000 !important;
            border-left-color: #1db954;
            font-weight: 700;
        }
        .nav-item.active svg { opacity: 1; color: #000; }

        .nav-item svg {
            width: 17px;
            height: 17px;
            flex-shrink: 0;
            opacity: 0.7;
            color: #d1d5db;
        }

        .nav-sep {
            height: 1px;
            background: #1a1a1a;
            margin: 0.6rem 0;
        }

        /* ── PAGE TRANSITION ── */
        @keyframes fadeSlideIn {
            from { opacity: 0; transform: translateY(8px); }
            to   { opacity: 1; transform: translateY(0); }
        }

        @keyframes fadeSlideOut {
            from { opacity: 1; transform: translateY(0); }
            to   { opacity: 0; transform: translateY(-8px); }
        }

        @keyframes fadeOut {
            from { opacity: 1; transform: translateY(0); }
            to   { opacity: 0; transform: translateY(-8px); }
        }

        .page-transition-out {
            animation: fadeSlideOut 0.18s ease forwards !important;
            pointer-events: none;
        }

        /* ── MAIN CONTENT ── */
        main {
            margin-left: 248px;
            flex: 1;
            padding: 1.75rem 2rem;
            animation: fadeSlideIn 0.18s ease both;
        }

        /* Staggered card animation */
        .stat-card {
            animation: fadeSlideIn 0.18s ease both;
        }
        .stats-grid .stat-card:nth-child(1) { animation-delay: 0.02s; }
        .stats-grid .stat-card:nth-child(2) { animation-delay: 0.04s; }
        .stats-grid .stat-card:nth-child(3) { animation-delay: 0.06s; }
        .stats-grid .stat-card:nth-child(4) { animation-delay: 0.08s; }

        .chart-card {
            animation: fadeSlideIn 0.18s ease both;
            animation-delay: 0.08s;
        }

        .activity-card {
            animation: fadeSlideIn 0.18s ease both;
            animation-delay: 0.1s;
        }

        .page-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 1.5rem;
        }

        .page-header h1 {
            font-size: 1.35rem;
            font-weight: 800;
            color: #0f0f0f;
            letter-spacing: -0.3px;
        }

        .page-header p {
            font-size: 0.85rem;
            color: #9ca3af;
            margin-top: 0.2rem;
        }

        .date-badge {
            font-size: 0.8rem;
            background: #fff;
            border: 1px solid #e5e7eb;
            border-radius: 8px;
            padding: 0.4rem 0.85rem;
            color: #6b7280;
            font-weight: 500;
        }

        /* ── SECTION TITLE ── */
        .section-title {
            font-size: 0.72rem;
            font-weight: 700;
            letter-spacing: 1.1px;
            text-transform: uppercase;
            color: #9ca3af;
            margin: 1.5rem 0 0.75rem;
        }

        /* ── STATS GRID ── */
        .stats-grid {
            display: grid;
            grid-template-columns: repeat(4, 1fr);
            gap: 1rem;
        }

        /* ── STAT CARD ── */
        .stat-card {
            background: #fff;
            border-radius: 14px;
            padding: 1.2rem 1.3rem 1.1rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
            position: relative;
            overflow: hidden;
            transition: box-shadow 0.22s, transform 0.22s;
            cursor: default;
        }

        .stat-card::before {
            content: '';
            position: absolute;
            top: 0; left: 0; right: 0;
            height: 3px;
            border-radius: 14px 14px 0 0;
        }

        .stat-card:hover {
            box-shadow: 0 8px 28px rgba(0,0,0,0.12);
            transform: translateY(-3px);
        }

        .stat-card.c-blue::before   { background: linear-gradient(90deg,#3b82f6,#60a5fa); }
        .stat-card.c-green::before  { background: linear-gradient(90deg,#22c55e,#4ade80); }
        .stat-card.c-purple::before { background: linear-gradient(90deg,#a855f7,#c084fc); }
        .stat-card.c-orange::before { background: linear-gradient(90deg,#f97316,#fb923c); }
        .stat-card.c-teal::before   { background: linear-gradient(90deg,#14b8a6,#2dd4bf); }
        .stat-card.c-indigo::before { background: linear-gradient(90deg,#6366f1,#818cf8); }
        .stat-card.c-yellow::before { background: linear-gradient(90deg,#eab308,#facc15); }
        .stat-card.c-red::before    { background: linear-gradient(90deg,#ef4444,#f87171); }
        .stat-card.c-emerald::before{ background: linear-gradient(90deg,#10b981,#34d399); }
        .stat-card.c-pink::before   { background: linear-gradient(90deg,#ec4899,#f472b6); }
        .stat-card.c-sky::before    { background: linear-gradient(90deg,#0ea5e9,#38bdf8); }
        .stat-card.c-lime::before   { background: linear-gradient(90deg,#84cc16,#a3e635); }

        .card-top {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 0.85rem;
        }

        .card-icon {
            width: 40px; height: 40px;
            border-radius: 10px;
            display: flex; align-items: center; justify-content: center;
        }
        .card-icon svg { width: 19px; height: 19px; }

        .c-blue    .card-icon { background:#eff6ff; color:#3b82f6; }
        .c-green   .card-icon { background:#f0fdf4; color:#16a34a; }
        .c-purple  .card-icon { background:#faf5ff; color:#9333ea; }
        .c-orange  .card-icon { background:#fff7ed; color:#ea580c; }
        .c-teal    .card-icon { background:#f0fdfa; color:#0d9488; }
        .c-indigo  .card-icon { background:#eef2ff; color:#4f46e5; }
        .c-yellow  .card-icon { background:#fefce8; color:#ca8a04; }
        .c-red     .card-icon { background:#fef2f2; color:#dc2626; }
        .c-emerald .card-icon { background:#ecfdf5; color:#059669; }
        .c-pink    .card-icon { background:#fdf2f8; color:#db2777; }
        .c-sky     .card-icon { background:#f0f9ff; color:#0284c7; }
        .c-lime    .card-icon { background:#f7fee7; color:#65a30d; }

        .card-badge {
            font-size: 0.68rem;
            font-weight: 700;
            padding: 0.22rem 0.55rem;
            border-radius: 20px;
            letter-spacing: 0.2px;
        }

        .c-blue    .card-badge { background:#eff6ff; color:#2563eb; }
        .c-green   .card-badge { background:#f0fdf4; color:#15803d; }
        .c-purple  .card-badge { background:#faf5ff; color:#7e22ce; }
        .c-orange  .card-badge { background:#fff7ed; color:#c2410c; }
        .c-teal    .card-badge { background:#f0fdfa; color:#0f766e; }
        .c-indigo  .card-badge { background:#eef2ff; color:#4338ca; }
        .c-yellow  .card-badge { background:#fefce8; color:#a16207; }
        .c-red     .card-badge { background:#fef2f2; color:#b91c1c; }
        .c-emerald .card-badge { background:#ecfdf5; color:#047857; }
        .c-pink    .card-badge { background:#fdf2f8; color:#be185d; }
        .c-sky     .card-badge { background:#f0f9ff; color:#0369a1; }
        .c-lime    .card-badge { background:#f7fee7; color:#4d7c0f; }

        .stat-value {
            font-size: 1.9rem;
            font-weight: 800;
            color: #0f0f0f;
            line-height: 1;
            letter-spacing: -0.5px;
        }

        .stat-label {
            font-size: 0.8rem;
            font-weight: 600;
            color: #374151;
            margin-top: 0.3rem;
        }

        .stat-hint {
            font-size: 0.72rem;
            color: #9ca3af;
            margin-top: 0.15rem;
        }

        .stat-trend {
            display: inline-flex;
            align-items: center;
            gap: 3px;
            font-size: 0.72rem;
            font-weight: 600;
            margin-top: 0.35rem;
            padding: 0.18rem 0.45rem;
            border-radius: 6px;
        }
        .trend-up   { background: #f0fdf4; color: #16a34a; }
        .trend-down { background: #fef2f2; color: #dc2626; }
        .trend-neu  { background: #f1f5f9; color: #64748b; }

        /* ── CHARTS SECTION ── */
        .charts-row {
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 1rem;
            margin-top: 0.75rem;
        }

        .charts-row-3 {
            display: grid;
            grid-template-columns: 1fr 1fr 1fr;
            gap: 1rem;
            margin-top: 1rem;
        }

        .chart-card {
            background: #fff;
            border-radius: 14px;
            padding: 1.3rem 1.5rem 1.2rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
        }

        .chart-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 1rem;
        }

        .chart-title {
            font-size: 0.9rem;
            font-weight: 700;
            color: #0f0f0f;
        }

        .chart-sub {
            font-size: 0.75rem;
            color: #9ca3af;
            margin-top: 1px;
        }

        .chart-badge {
            font-size: 0.7rem;
            font-weight: 600;
            background: #f0fdf4;
            color: #15803d;
            padding: 0.22rem 0.6rem;
            border-radius: 6px;
        }

        .chart-canvas-wrap {
            position: relative;
        }

        /* ── ACTIVITY TABLE ── */
        .activity-card {
            background: #fff;
            border-radius: 14px;
            padding: 1.3rem 1.5rem;
            box-shadow: 0 1px 3px rgba(0,0,0,0.06), 0 4px 12px rgba(0,0,0,0.04);
            margin-top: 1rem;
        }

        .activity-header {
            display: flex;
            align-items: center;
            justify-content: space-between;
            margin-bottom: 1rem;
        }

        .activity-title {
            font-size: 0.9rem;
            font-weight: 700;
            color: #0f0f0f;
        }

        .activity-table {
            width: 100%;
            border-collapse: collapse;
        }

        .activity-table th {
            font-size: 0.72rem;
            font-weight: 700;
            color: #9ca3af;
            text-transform: uppercase;
            letter-spacing: 0.6px;
            padding: 0 0 0.6rem;
            text-align: left;
            border-bottom: 1px solid #f1f5f9;
        }

        .activity-table td {
            padding: 0.7rem 0;
            font-size: 0.83rem;
            color: #374151;
            border-bottom: 1px solid #f8fafc;
        }

        .activity-table tr:last-child td { border-bottom: none; }

        .pill {
            display: inline-block;
            padding: 0.18rem 0.55rem;
            border-radius: 20px;
            font-size: 0.7rem;
            font-weight: 700;
        }
        .pill-green  { background:#f0fdf4; color:#16a34a; }
        .pill-orange { background:#fff7ed; color:#ea580c; }
        .pill-blue   { background:#eff6ff; color:#2563eb; }
        .pill-red    { background:#fef2f2; color:#dc2626; }
        .pill-gray   { background:#f1f5f9; color:#64748b; }
    </style>
</head>
<body>

<!-- HEADER -->
<?php
    $appLogo    = \App\Models\Setting::get('app_logo', '');
    $appName    = \App\Models\Setting::get('project_name', 'On Cloud API');
    $hasLogo    = $appLogo && file_exists(public_path('uploads/' . $appLogo));
    $userPhoto  = $user->profile_photo_path ?? '';
    $hasPhoto   = $userPhoto && file_exists(public_path('uploads/' . $userPhoto));
    $initials   = strtoupper(substr($user->name ?? 'U', 0, 1));
?>
<header>
    <div class="brand">
        <?php if($hasLogo): ?>
            <img src="<?php echo e(asset('uploads/' . $appLogo)); ?>" class="brand-logo" alt="<?php echo e($appName); ?>">
        <?php else: ?>
            <svg viewBox="0 0 48 48" fill="none">
                <circle cx="24" cy="24" r="24" fill="#25D366"/>
                <path d="M24 10C16.268 10 10 16.268 10 24c0 2.637.718 5.107 1.97 7.23L10 38l7-1.93A13.93 13.93 0 0024 38c7.732 0 14-6.268 14-14S31.732 10 24 10z" fill="white"/>
                <path d="M19.5 17.5c-.4-.9-1-1-1.4-1h-1.2c-.4 0-1 .15-1.5.7s-2 2-2 4.85 2.05 5.6 2.35 5.95 4 6.3 9.75 8.6c4.8 1.9 5.75 1.5 6.75 1.4s3.25-1.35 3.7-2.65.45-2.4.3-2.65-1.15-1.1-2.4-1.7-3.05-1.5-3.5-1.65-.8-.25-1.15.25-1.3 1.65-1.6 2c-.3.3-.6.35-1.1.1s-2.15-1.05-4.1-2.8c-1.52-1.5-2.53-3.35-2.83-3.85s-.03-.75.22-1l.55-.65c.2-.2.3-.45.45-.75s.05-.55-.05-.75l-1.74-3.6z" fill="#25D366"/>
            </svg>
        <?php endif; ?>
    </div>
    <div class="header-right">
        <?php if($hasPhoto): ?>
            <img src="<?php echo e(asset('uploads/' . $userPhoto)); ?>" class="user-avatar" alt="<?php echo e($user->name); ?>">
        <?php else: ?>
            <div class="user-avatar-initials"><?php echo e($initials); ?></div>
        <?php endif; ?>
        <span class="username"><?php echo e($user->name); ?></span>
        <form method="POST" action="<?php echo e(route('logout')); ?>">
            <?php echo csrf_field(); ?>
            <button type="submit" class="btn-logout">Logout</button>
        </form>
    </div>
</header>

<div class="layout">

    <!-- SIDEBAR -->
    <aside>
        <div class="nav-section-label">Main</div>

        <a href="<?php echo e(route('dashboard')); ?>" class="nav-item active" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M3 12l2-2m0 0l7-7 7 7M5 10v10a1 1 0 001 1h3m10-11l2 2m-2-2v10a1 1 0 01-1 1h-3m-6 0a1 1 0 001-1v-4a1 1 0 011-1h2a1 1 0 011 1v4a1 1 0 001 1m-6 0h6"/></svg>
            Dashboard
        </a>

        <div class="nav-sep"></div>
        <div class="nav-section-label">Management</div>

        <a href="#" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
            Subscriptions
        </a>

        <a href="<?php echo e(route('companies')); ?>" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"/></svg>
            Companies
        </a>

        <a href="<?php echo e(route('pricing-plans')); ?>" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2M9 12h6m-6 4h6"/></svg>
            Pricing Plans
        </a>

        <div class="nav-sep"></div>
        <div class="nav-section-label">Explore</div>

        <a href="#" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 10h.01M12 10h.01M16 10h.01M9 16H5a2 2 0 01-2-2V6a2 2 0 012-2h14a2 2 0 012 2v8a2 2 0 01-2 2h-5l-5 5v-5z"/></svg>
            Today Messages
        </a>

        <a href="#" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"/></svg>
            Today Campaigns
        </a>

        <a href="<?php echo e(route('apps')); ?>" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 6h16M4 10h16M4 14h16M4 18h16"/></svg>
            Apps
        </a>

        <div class="nav-sep"></div>
        <div class="nav-section-label">System</div>

        <a href="<?php echo e(route('settings')); ?>" class="nav-item" onclick="setActive(event,this)">
            <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"/><path stroke-linecap="round" stroke-linejoin="round" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
            Settings
        </a>
    </aside>

    <!-- MAIN -->
    <main>
        <div class="page-header">
            <div>
                <h1>Dashboard</h1>
                <p>Welcome back, <?php echo e($user->name); ?>. Here's your full overview.</p>
            </div>
            <span class="date-badge" id="todayDate"></span>
        </div>

        <!-- ROW 1: General Overview -->
        <div class="section-title">Overview</div>
        <div class="stats-grid">

            <div class="stat-card c-blue">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0z"/></svg>
                    </div>
                    <span class="card-badge">Total</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Total Users</div>
                <div class="stat-hint">Registered accounts</div>
                <div class="stat-trend trend-neu">— No change</div>
            </div>

            <div class="stat-card c-green">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8c-1.657 0-3 .895-3 2s1.343 2 3 2 3 .895 3 2-1.343 2-3 2m0-8c1.11 0 2.08.402 2.599 1M12 8V7m0 1v8m0 0v1m0-1c-1.11 0-2.08-.402-2.599-1M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                    </div>
                    <span class="card-badge">Active</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Paying Clients</div>
                <div class="stat-hint">Active subscriptions</div>
                <div class="stat-trend trend-neu">— No change</div>
            </div>

            <div class="stat-card c-purple">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"/></svg>
                    </div>
                    <span class="card-badge">Plans</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Pricing Plans</div>
                <div class="stat-hint">Available plans</div>
                <div class="stat-trend trend-neu">— No change</div>
            </div>

            <div class="stat-card c-red">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M18.364 18.364A9 9 0 005.636 5.636m12.728 12.728A9 9 0 015.636 5.636m12.728 12.728L5.636 5.636"/></svg>
                    </div>
                    <span class="card-badge">Blocked</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Blocked Accounts</div>
                <div class="stat-hint">Restricted numbers</div>
                <div class="stat-trend trend-neu">— No change</div>
            </div>

        </div>

        <!-- ROW 2: Today's Activity -->
        <div class="section-title">Today's Activity</div>
        <div class="stats-grid">

            <div class="stat-card c-emerald">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"/></svg>
                    </div>
                    <span class="card-badge">Today</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Today Campaigns</div>
                <div class="stat-hint">Campaigns launched today</div>
                <div class="stat-trend trend-neu">— No activity yet</div>
            </div>

            <div class="stat-card c-indigo">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"/></svg>
                    </div>
                    <span class="card-badge">Today</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Today Messages Sent</div>
                <div class="stat-hint">Delivered today</div>
                <div class="stat-trend trend-neu">— No messages yet</div>
            </div>

            <div class="stat-card c-pink">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/></svg>
                    </div>
                    <span class="card-badge">Today</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Today Cronjob Hits</div>
                <div class="stat-hint">Cron executions today</div>
                <div class="stat-trend trend-neu">— No hits yet</div>
            </div>

            <div class="stat-card c-teal">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                    </div>
                    <span class="card-badge">Today</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Today Renewals</div>
                <div class="stat-hint">Subscriptions renewed today</div>
                <div class="stat-trend trend-neu">— No renewals yet</div>
            </div>

        </div>

        <!-- ROW 3: Messages & Queue -->
        <div class="section-title">Messages & Queue</div>
        <div class="stats-grid">

            <div class="stat-card c-sky">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v12a2 2 0 002 2z"/></svg>
                    </div>
                    <span class="card-badge">Month</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">This Month</div>
                <div class="stat-hint">Messages this month</div>
                <div class="stat-trend trend-neu">— No data</div>
            </div>

            <div class="stat-card c-orange">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M3 8l7.89 5.26a2 2 0 002.22 0L21 8M5 19h14a2 2 0 002-2V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2z"/></svg>
                    </div>
                    <span class="card-badge">All-Time</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Total Messages Sent</div>
                <div class="stat-hint">All-time delivered</div>
                <div class="stat-trend trend-neu">— No data</div>
            </div>

            <div class="stat-card c-yellow">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                    </div>
                    <span class="card-badge">Queue</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Cronjob Pending</div>
                <div class="stat-hint">Messages waiting in queue</div>
                <div class="stat-trend trend-neu">— Queue empty</div>
            </div>

            <div class="stat-card c-lime">
                <div class="card-top">
                    <div class="card-icon">
                        <svg fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"/></svg>
                    </div>
                    <span class="card-badge">Total</span>
                </div>
                <div class="stat-value">0</div>
                <div class="stat-label">Total Cronjob Hits</div>
                <div class="stat-hint">All-time cron executions</div>
                <div class="stat-trend trend-neu">— No data</div>
            </div>

        </div>

        <!-- CHARTS ROW -->
        <div class="section-title">Analytics</div>
        <div class="charts-row">

            <!-- Messages chart (large) -->
            <div class="chart-card">
                <div class="chart-header">
                    <div>
                        <div class="chart-title">Messages Sent — Last 7 Days</div>
                        <div class="chart-sub">Daily message delivery trend</div>
                    </div>
                    <span class="chart-badge">Live</span>
                </div>
                <div class="chart-canvas-wrap">
                    <canvas id="msgChart" height="90"></canvas>
                </div>
            </div>

            <!-- Donut chart -->
            <div class="chart-card">
                <div class="chart-header">
                    <div>
                        <div class="chart-title">Subscription Breakdown</div>
                        <div class="chart-sub">Current plan status</div>
                    </div>
                </div>
                <div class="chart-canvas-wrap" style="display:flex;align-items:center;justify-content:center;padding:0.5rem 0;">
                    <canvas id="donutChart" height="160" style="max-width:200px;"></canvas>
                </div>
                <div style="display:flex;gap:1.2rem;justify-content:center;margin-top:0.75rem;flex-wrap:wrap;">
                    <div style="display:flex;align-items:center;gap:6px;font-size:0.75rem;color:#6b7280;">
                        <span style="width:10px;height:10px;border-radius:50%;background:#22c55e;display:inline-block;"></span>Active
                    </div>
                    <div style="display:flex;align-items:center;gap:6px;font-size:0.75rem;color:#6b7280;">
                        <span style="width:10px;height:10px;border-radius:50%;background:#f97316;display:inline-block;"></span>Trial
                    </div>
                    <div style="display:flex;align-items:center;gap:6px;font-size:0.75rem;color:#6b7280;">
                        <span style="width:10px;height:10px;border-radius:50%;background:#ef4444;display:inline-block;"></span>Expired
                    </div>
                </div>
            </div>
        </div>

        <!-- Bottom charts row -->
        <div class="charts-row-3">

            <!-- Campaigns bar chart -->
            <div class="chart-card">
                <div class="chart-header">
                    <div>
                        <div class="chart-title">Today Campaigns</div>
                        <div class="chart-sub">Hourly distribution</div>
                    </div>
                </div>
                <canvas id="campChart" height="120"></canvas>
            </div>

            <!-- Cronjob hits chart -->
            <div class="chart-card">
                <div class="chart-header">
                    <div>
                        <div class="chart-title">Cronjob Hits</div>
                        <div class="chart-sub">Last 7 days execution</div>
                    </div>
                </div>
                <canvas id="cronChart" height="120"></canvas>
            </div>

            <!-- Renewals chart -->
            <div class="chart-card">
                <div class="chart-header">
                    <div>
                        <div class="chart-title">Renewals</div>
                        <div class="chart-sub">Last 7 days</div>
                    </div>
                </div>
                <canvas id="renewChart" height="120"></canvas>
            </div>

        </div>

        <!-- Recent Activity Table -->
        <div class="activity-card">
            <div class="activity-header">
                <div class="activity-title">Recent System Activity</div>
                <span style="font-size:0.78rem;color:#9ca3af;">Last 5 events</span>
            </div>
            <table class="activity-table">
                <thead>
                    <tr>
                        <th>Event</th>
                        <th>Type</th>
                        <th>Status</th>
                        <th>Time</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>No recent activity</td>
                        <td>—</td>
                        <td><span class="pill pill-gray">Idle</span></td>
                        <td style="color:#9ca3af;">—</td>
                    </tr>
                </tbody>
            </table>
        </div>

    </main>
</div>

<script>
    /* ── Sidebar navigation with exit animation ── */
    function setActive(e, el) {
        const href = el.getAttribute('href');
        if (href === '#') { e.preventDefault(); return; }

        e.preventDefault();
        document.querySelectorAll('.nav-item').forEach(i => i.classList.remove('active'));
        el.classList.add('active');

        const mainEl = document.querySelector('main');
        mainEl.classList.add('page-transition-out');

        setTimeout(() => { window.location.href = href; }, 180);
    }

    /* ── Today's date badge ── */
    const d = new Date();
    document.getElementById('todayDate').textContent =
        d.toLocaleDateString('en-GB', { weekday:'short', day:'numeric', month:'short', year:'numeric' });

    /* ── Chart defaults ── */
    Chart.defaults.font.family = "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif";
    Chart.defaults.font.size   = 11;
    Chart.defaults.color       = '#9ca3af';

    const labels7 = Array.from({length:7}, (_,i) => {
        const d = new Date(); d.setDate(d.getDate() - (6 - i));
        return d.toLocaleDateString('en-GB',{day:'numeric',month:'short'});
    });

    /* Messages line chart */
    new Chart(document.getElementById('msgChart'), {
        type: 'line',
        data: {
            labels: labels7,
            datasets: [{
                label: 'Messages Sent',
                data: [0,0,0,0,0,0,0],
                borderColor: '#25d366',
                backgroundColor: 'rgba(37,211,102,0.08)',
                borderWidth: 2.5,
                pointBackgroundColor: '#25d366',
                pointRadius: 4,
                pointHoverRadius: 6,
                tension: 0.4,
                fill: true,
            }]
        },
        options: {
            responsive: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { color: '#f1f5f9' }, border: { display: false } },
                y: { grid: { color: '#f1f5f9' }, border: { display: false }, beginAtZero: true, ticks: { stepSize: 1 } }
            }
        }
    });

    /* Donut chart */
    new Chart(document.getElementById('donutChart'), {
        type: 'doughnut',
        data: {
            labels: ['Active', 'Trial', 'Expired'],
            datasets: [{
                data: [0, 0, 0],
                backgroundColor: ['#22c55e','#f97316','#ef4444'],
                borderWidth: 0,
                hoverOffset: 6,
            }]
        },
        options: {
            responsive: true,
            cutout: '70%',
            plugins: {
                legend: { display: false },
                tooltip: { callbacks: { label: ctx => ' ' + ctx.label + ': ' + ctx.parsed } }
            }
        },
        plugins: [{
            id: 'center',
            beforeDraw(chart) {
                const { ctx, width, height } = chart;
                ctx.save();
                ctx.font = 'bold 22px -apple-system, sans-serif';
                ctx.fillStyle = '#0f0f0f';
                ctx.textAlign = 'center';
                ctx.textBaseline = 'middle';
                ctx.fillText('0', width / 2, height / 2);
                ctx.restore();
            }
        }]
    });

    /* Campaigns bar */
    new Chart(document.getElementById('campChart'), {
        type: 'bar',
        data: {
            labels: ['6am','8am','10am','12pm','2pm','4pm','6pm'],
            datasets: [{
                label: 'Campaigns',
                data: [0,0,0,0,0,0,0],
                backgroundColor: 'rgba(16,185,129,0.75)',
                borderRadius: 6,
                borderSkipped: false,
            }]
        },
        options: {
            responsive: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { display: false }, border: { display: false } },
                y: { grid: { color: '#f1f5f9' }, border: { display: false }, beginAtZero: true, ticks: { stepSize: 1 } }
            }
        }
    });

    /* Cronjob hits line */
    new Chart(document.getElementById('cronChart'), {
        type: 'bar',
        data: {
            labels: labels7,
            datasets: [{
                label: 'Hits',
                data: [0,0,0,0,0,0,0],
                backgroundColor: 'rgba(236,72,153,0.7)',
                borderRadius: 6,
                borderSkipped: false,
            }]
        },
        options: {
            responsive: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { display: false }, border: { display: false } },
                y: { grid: { color: '#f1f5f9' }, border: { display: false }, beginAtZero: true, ticks: { stepSize: 1 } }
            }
        }
    });

    /* Renewals line */
    new Chart(document.getElementById('renewChart'), {
        type: 'line',
        data: {
            labels: labels7,
            datasets: [{
                label: 'Renewals',
                data: [0,0,0,0,0,0,0],
                borderColor: '#14b8a6',
                backgroundColor: 'rgba(20,184,166,0.08)',
                borderWidth: 2.5,
                pointBackgroundColor: '#14b8a6',
                pointRadius: 4,
                tension: 0.4,
                fill: true,
            }]
        },
        options: {
            responsive: true,
            plugins: { legend: { display: false } },
            scales: {
                x: { grid: { display: false }, border: { display: false } },
                y: { grid: { color: '#f1f5f9' }, border: { display: false }, beginAtZero: true, ticks: { stepSize: 1 } }
            }
        }
    });
</script>
</body>
</html>
<?php /**PATH /Applications/XAMPP/xamppfiles/htdocs/WhatsApp/whatsappcloudapi/resources/views/dashboard.blade.php ENDPATH**/ ?>