<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="csrf-token" content="<?php echo e(csrf_token()); ?>">
    <title><?php echo $__env->yieldContent('title', 'Dashboard'); ?> - <?php echo e(auth('client_admin')->user()->client->name ?? 'Client Portal'); ?></title>
    <link rel="icon" type="image/png" href="<?php echo e(asset('images/icon.png')); ?>">

    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.1/font/bootstrap-icons.css" rel="stylesheet">
    <!-- Google Fonts -->
    <link rel="preconnect" href="https://fonts.googleapis.com">
    <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
    <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
    <!-- SweetAlert2 -->
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>

    <style>
        :root {
            --sidebar-width: 260px;
            --primary-gradient: linear-gradient(135deg, #11998e 0%, #38ef7d 100%);
            --owner-gradient: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            --manager-gradient: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
        }

        * {
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
        }

        body {
            background-color: #f0f2f5;
        }

        .sidebar {
            width: var(--sidebar-width);
            height: 100vh;
            position: fixed;
            left: 0;
            top: 0;
            background: linear-gradient(180deg, #0f4c3a 0%, #11998e 50%, #38ef7d 100%);
            padding-top: 0;
            z-index: 1000;
            overflow-y: auto;
        }

        .sidebar .brand {
            padding: 1.25rem 1.5rem;
            color: white;
            font-size: 1.1rem;
            font-weight: 700;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            display: flex;
            align-items: center;
            gap: 0.75rem;
            background: rgba(0, 0, 0, 0.1);
        }

        .sidebar .brand .logo-icon {
            width: 40px;
            height: 40px;
            border-radius: 10px;
            overflow: hidden;
            background: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .sidebar .brand .logo-icon i {
            font-size: 1.25rem;
            color: white;
        }

        .sidebar .org-info {
            padding: 0.75rem 1.5rem;
            background: rgba(0, 0, 0, 0.15);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar .org-info .org-name {
            color: white;
            font-size: 0.85rem;
            font-weight: 600;
            margin-bottom: 0.25rem;
        }

        .sidebar .org-info .subscription-badge {
            font-size: 0.65rem;
            padding: 0.2rem 0.5rem;
            border-radius: 4px;
            font-weight: 600;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }

        .sidebar .org-info .subscription-badge.trial {
            background: rgba(245, 158, 11, 0.2);
            color: #fbbf24;
        }

        .sidebar .org-info .subscription-badge.basic {
            background: rgba(99, 102, 241, 0.2);
            color: #a5b4fc;
        }

        .sidebar .org-info .subscription-badge.premium {
            background: rgba(236, 72, 153, 0.2);
            color: #f9a8d4;
        }

        .sidebar .org-info .subscription-badge.enterprise {
            background: rgba(139, 92, 246, 0.2);
            color: #c4b5fd;
        }

        .sidebar .role-badge {
            padding: 0.5rem 1.5rem;
            background: rgba(0, 0, 0, 0.1);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .sidebar .role-badge .badge {
            font-size: 0.7rem;
            padding: 0.35rem 0.75rem;
            font-weight: 600;
            letter-spacing: 0.5px;
        }

        .sidebar .role-badge .badge.owner {
            background: var(--owner-gradient);
        }

        .sidebar .role-badge .badge.manager {
            background: var(--manager-gradient);
        }

        .sidebar .nav-section {
            padding: 0.75rem 1.5rem 0.5rem;
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            color: rgba(255, 255, 255, 0.5);
            font-weight: 600;
            margin-top: 0.5rem;
        }

        .sidebar .nav-link {
            color: rgba(255, 255, 255, 0.75);
            padding: 0.65rem 1.5rem;
            margin: 0.15rem 0.75rem;
            border-radius: 0.5rem;
            transition: all 0.2s ease;
            font-size: 0.875rem;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 0.75rem;
        }

        .sidebar .nav-link:hover,
        .sidebar .nav-link.active {
            background: rgba(255, 255, 255, 0.15);
            color: white;
            transform: translateX(4px);
        }

        .sidebar .nav-link i {
            width: 20px;
            font-size: 1rem;
        }

        .sidebar .nav-link .count-badge {
            margin-left: auto;
            font-size: 0.65rem;
            padding: 0.15rem 0.4rem;
            background: rgba(255, 255, 255, 0.2);
            border-radius: 4px;
        }

        .main-content {
            margin-left: var(--sidebar-width);
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        .top-navbar {
            background: white;
            padding: 0.75rem 1.5rem;
            border-bottom: 1px solid #e5e7eb;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .top-navbar .page-title {
            font-size: 1.25rem;
            font-weight: 600;
            color: #1f2937;
        }

        .top-navbar .user-info {
            display: flex;
            align-items: center;
            gap: 1rem;
        }

        .top-navbar .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background: var(--primary-gradient);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-weight: 600;
        }

        .content-wrapper {
            flex: 1;
            padding: 1.5rem;
        }

        .footer {
            background: white;
            padding: 1rem 1.5rem;
            border-top: 1px solid #e5e7eb;
            text-align: center;
            font-size: 0.875rem;
            color: #6b7280;
        }

        /* Cards */
        .stat-card {
            background: white;
            border-radius: 0.75rem;
            padding: 1.25rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            transition: transform 0.2s, box-shadow 0.2s;
        }

        .stat-card:hover {
            transform: translateY(-2px);
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }

        .stat-card .stat-icon {
            width: 48px;
            height: 48px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.25rem;
        }

        .stat-card .stat-value {
            font-size: 1.75rem;
            font-weight: 700;
            color: #1f2937;
        }

        .stat-card .stat-label {
            font-size: 0.875rem;
            color: #6b7280;
        }

        /* Table styles */
        .table-card {
            background: white;
            border-radius: 0.75rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            overflow: visible;
        }

        .table-card .table-responsive {
            overflow: visible;
        }

        .dropdown-menu {
            z-index: 1050;
        }

        .table-card .card-header {
            background: transparent;
            border-bottom: 1px solid #e5e7eb;
            padding: 1rem 1.25rem;
        }

        .table-card .card-header h5 {
            margin: 0;
            font-weight: 600;
            color: #1f2937;
        }

        .table {
            margin-bottom: 0;
        }

        .table th {
            background: #f9fafb;
            font-weight: 600;
            color: #374151;
            font-size: 0.8rem;
            text-transform: uppercase;
            letter-spacing: 0.5px;
            border-bottom: 1px solid #e5e7eb;
        }

        .table td {
            vertical-align: middle;
            color: #4b5563;
            border-bottom: 1px solid #f3f4f6;
        }

        /* Buttons */
        .btn-primary {
            background: var(--primary-gradient);
            border: none;
        }

        .btn-primary:hover {
            background: linear-gradient(135deg, #0e8a7e 0%, #2fd96e 100%);
        }

        /* Alerts */
        .alert {
            border-radius: 0.5rem;
            border: none;
        }

        .alert-success {
            background: #d1fae5;
            color: #065f46;
        }

        .alert-danger {
            background: #fee2e2;
            color: #991b1b;
        }

        .alert-warning {
            background: #fef3c7;
            color: #92400e;
        }

        .alert-info {
            background: #dbeafe;
            color: #1e40af;
        }

        /* Status badges */
        .badge-pending {
            background: #fef3c7;
            color: #92400e;
        }

        .badge-approved {
            background: #d1fae5;
            color: #065f46;
        }

        .badge-rejected {
            background: #fee2e2;
            color: #991b1b;
        }

        /* Subscription warning */
        .subscription-warning {
            background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
            color: white;
            padding: 0.75rem 1.5rem;
            font-size: 0.875rem;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 0.5rem;
        }

        /* Toast styles */
        .toast-container {
            position: fixed;
            top: 1rem;
            right: 1rem;
            z-index: 9999;
        }

        .toast {
            border: none;
            border-radius: 0.75rem;
            box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
            overflow: hidden;
            min-width: 320px;
        }

        .toast .toast-body {
            padding: 0.875rem 1rem;
            font-size: 0.875rem;
            font-weight: 500;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .toast.toast-success {
            background: #d1fae5;
            color: #065f46;
        }

        .toast.toast-error {
            background: #fee2e2;
            color: #991b1b;
        }

        .toast.toast-warning {
            background: #fef3c7;
            color: #92400e;
        }

        .toast.toast-info {
            background: #dbeafe;
            color: #1e40af;
        }

        .toast .btn-close {
            filter: none;
            opacity: 0.6;
            font-size: 0.65rem;
            padding: 0.75rem;
        }

        .toast.toast-success .btn-close {
            filter: invert(25%) sepia(98%) saturate(1000%) hue-rotate(130deg);
        }

        .toast.toast-error .btn-close {
            filter: invert(15%) sepia(90%) saturate(4000%) hue-rotate(350deg);
        }

        /* Info hint icon */
        .info-hint {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 22px;
            height: 22px;
            border-radius: 50%;
            background: #dbeafe;
            color: #1e40af;
            font-size: 0.75rem;
            cursor: pointer;
            transition: all 0.2s;
            border: none;
            padding: 0;
        }

        .info-hint:hover {
            background: #1e40af;
            color: white;
            transform: scale(1.1);
        }

        /* Template card styles */
        .template-card {
            background: white;
            border-radius: 0.75rem;
            box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
            overflow: hidden;
            transition: transform 0.2s, box-shadow 0.2s;
            height: 100%;
            display: flex;
            flex-direction: column;
        }

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

        .template-card .template-type-ribbon {
            height: 4px;
        }

        .template-card .template-type-ribbon.type-sms {
            background: linear-gradient(90deg, #3b82f6, #60a5fa);
        }

        .template-card .template-type-ribbon.type-call {
            background: linear-gradient(90deg, #10b981, #34d399);
        }

        .template-card .template-type-ribbon.type-whatsapp {
            background: linear-gradient(90deg, #22c55e, #4ade80);
        }

        .template-card .template-type-ribbon.type-auto_reply {
            background: linear-gradient(90deg, #8b5cf6, #a78bfa);
        }

        .template-card .template-type-ribbon.type-promotion {
            background: linear-gradient(90deg, #f59e0b, #fbbf24);
        }

        .template-card .template-header {
            padding: 1rem 1.25rem 0.75rem;
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
        }

        .template-card .template-name {
            font-size: 0.95rem;
            font-weight: 600;
            color: #1f2937;
            margin-bottom: 0.25rem;
        }

        .template-card .template-meta {
            display: flex;
            gap: 0.5rem;
            flex-wrap: wrap;
        }

        .template-card .template-body {
            padding: 0 1.25rem 1rem;
            flex: 1;
        }

        .template-card .template-preview {
            background: #f9fafb;
            border-radius: 0.5rem;
            padding: 0.75rem;
            font-size: 0.8rem;
            color: #4b5563;
            line-height: 1.5;
            max-height: 80px;
            overflow: hidden;
            position: relative;
        }

        .template-card .template-preview::after {
            content: '';
            position: absolute;
            bottom: 0;
            left: 0;
            right: 0;
            height: 20px;
            background: linear-gradient(transparent, #f9fafb);
        }

        .template-card .template-footer {
            padding: 0.75rem 1.25rem;
            border-top: 1px solid #f3f4f6;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        /* Responsive */
        @media (max-width: 991px) {
            .sidebar {
                width: 0;
                overflow: hidden;
            }

            .main-content {
                margin-left: 0;
            }
        }
    </style>
    <?php echo $__env->yieldContent('styles'); ?>
</head>

<body>
    <?php
    $clientAdmin = auth('client_admin')->user();
    $client = $clientAdmin->client;
    ?>

    <!-- Sidebar -->
    <div class="sidebar">
        <div class="brand">
            <div class="logo-icon">
                <i class="bi bi-building"></i>
            </div>
            <span>Client Portal</span>
        </div>

        <div class="org-info">
            <div class="org-name"><?php echo e($client->name); ?></div>
            <span class="subscription-badge <?php echo e($client->subscription_type); ?>">
                <?php echo e(ucfirst($client->subscription_type)); ?>

                <?php if($client->isOnTrial()): ?>
                (<?php echo e($client->getDaysRemaining()); ?> days left)
                <?php endif; ?>
            </span>
        </div>

        <div class="role-badge">
            <span class="badge <?php echo e($clientAdmin->role); ?>">
                <i class="bi bi-<?php echo e($clientAdmin->role === 'owner' ? 'star-fill' : 'person-badge'); ?> me-1"></i>
                <?php echo e(ucfirst($clientAdmin->role)); ?>

            </span>
        </div>

        <nav class="nav flex-column">
            <div class="nav-section">Main</div>
            <a href="<?php echo e(route('client.dashboard')); ?>" class="nav-link <?php echo e(request()->routeIs('client.dashboard') ? 'active' : ''); ?>">
                <i class="bi bi-grid-1x2"></i>
                <span>Dashboard</span>
            </a>

            <?php if($clientAdmin->hasAnyPermission(['client.users.view', 'client.templates.view'])): ?>
            <div class="nav-section">Management</div>
            <?php if($clientAdmin->hasPermission('client.users.view')): ?>
            <a href="<?php echo e(route('client.users')); ?>" class="nav-link <?php echo e(request()->routeIs('client.users*') ? 'active' : ''); ?>">
                <i class="bi bi-people"></i>
                <span>Users</span>
            </a>
            <?php endif; ?>
            <?php if($clientAdmin->hasPermission('client.templates.view')): ?>
            <a href="<?php echo e(route('client.templates')); ?>" class="nav-link <?php echo e(request()->routeIs('client.templates*') ? 'active' : ''); ?>">
                <i class="bi bi-file-text"></i>
                <span>Templates</span>
            </a>
            <?php endif; ?>
            <?php endif; ?>

            <?php if($clientAdmin->hasAnyPermission(['client.reports.sms_logs', 'client.reports.call_logs'])): ?>
            <div class="nav-section">Reports</div>
            <?php if($clientAdmin->hasPermission('client.reports.sms_logs')): ?>
            <a href="<?php echo e(route('client.sms-logs')); ?>" class="nav-link <?php echo e(request()->routeIs('client.sms-logs') ? 'active' : ''); ?>">
                <i class="bi bi-chat-dots"></i>
                <span>SMS Logs</span>
            </a>
            <?php endif; ?>
            <?php if($clientAdmin->hasPermission('client.reports.call_logs')): ?>
            <a href="<?php echo e(route('client.call-logs')); ?>" class="nav-link <?php echo e(request()->routeIs('client.call-logs') ? 'active' : ''); ?>">
                <i class="bi bi-telephone"></i>
                <span>Call Logs</span>
            </a>
            <?php endif; ?>
            <?php endif; ?>

            <?php if($clientAdmin->hasPermission('client.admins.view')): ?>
            <div class="nav-section">Administration</div>
            <a href="<?php echo e(route('client.admins')); ?>" class="nav-link <?php echo e(request()->routeIs('client.admins*') ? 'active' : ''); ?>">
                <i class="bi bi-person-gear"></i>
                <span>Admin Members</span>
            </a>
            <?php endif; ?>

            <?php if($clientAdmin->hasPermission('client.profile.view')): ?>
            <div class="nav-section">Account</div>
            <a href="<?php echo e(route('client.profile')); ?>" class="nav-link <?php echo e(request()->routeIs('client.profile') ? 'active' : ''); ?>">
                <i class="bi bi-person-circle"></i>
                <span>My Profile</span>
            </a>
            <?php endif; ?>
        </nav>
    </div>

    <!-- Main Content -->
    <div class="main-content">
        <?php if($client->isOnTrial()): ?>
        <div class="subscription-warning">
            <i class="bi bi-exclamation-triangle"></i>
            <span>Trial period: <?php echo e($client->getDaysRemaining()); ?> days remaining. Contact administrator to upgrade your subscription.</span>
        </div>
        <?php elseif($client->getDaysRemaining() <= 7): ?>
            <div class="subscription-warning">
            <i class="bi bi-exclamation-triangle"></i>
            <span>Subscription expires in <?php echo e($client->getDaysRemaining()); ?> days. Contact administrator to renew.</span>
    </div>
    <?php endif; ?>

    <!-- Top Navbar -->
    <div class="top-navbar">
        <div class="page-title"><?php echo $__env->yieldContent('title', 'Dashboard'); ?></div>
        <div class="user-info">
            <span class="text-muted"><?php echo e($clientAdmin->name); ?></span>
            <div class="dropdown">
                <div class="user-avatar dropdown-toggle" data-bs-toggle="dropdown" style="cursor: pointer;">
                    <?php echo e(strtoupper(substr($clientAdmin->name, 0, 1))); ?>

                </div>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li><a class="dropdown-item" href="<?php echo e(route('client.profile')); ?>"><i class="bi bi-person me-2"></i>Profile</a></li>
                    <li>
                        <hr class="dropdown-divider">
                    </li>
                    <li>
                        <form method="POST" action="<?php echo e(route('client.logout')); ?>">
                            <?php echo csrf_field(); ?>
                            <button type="submit" class="dropdown-item text-danger"><i class="bi bi-box-arrow-right me-2"></i>Logout</button>
                        </form>
                    </li>
                </ul>
            </div>
        </div>
    </div>

    <!-- Toast Container -->
    <div class="toast-container" id="toastContainer"></div>

    <!-- Content -->
    <div class="content-wrapper">
        <?php echo $__env->yieldContent('content'); ?>
    </div>

    <!-- Footer -->
    <div class="footer">
        &copy; <?php echo e(date('Y')); ?> AutoPromix - Client Portal. All rights reserved.
    </div>
    </div>

    <!-- Bootstrap JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>

    <script>
        // SweetAlert2 Toast helper
        var SwalToast = Swal.mixin({
            toast: true,
            position: 'top-end',
            showConfirmButton: false,
            timer: 3000,
            timerProgressBar: true,
            showCloseButton: true,
            didOpen: function(toast) {
                toast.addEventListener('mouseenter', Swal.stopTimer);
                toast.addEventListener('mouseleave', Swal.resumeTimer);
            }
        });

        function showToast(message, type) {
            type = type === 'error' ? 'error' : type;
            SwalToast.fire({
                icon: type || 'success',
                title: message
            });
        }

        // Confirmation popup using SweetAlert2
        function confirmAction(formOrCallback, title, message, btnText, btnClass) {
            var isDanger = (btnClass || '').indexOf('danger') !== -1;
            var isWarning = (btnClass || '').indexOf('warning') !== -1;
            Swal.fire({
                title: title || 'Confirm Action',
                text: message || 'Are you sure you want to proceed?',
                icon: isDanger ? 'warning' : (isWarning ? 'question' : 'question'),
                showCancelButton: true,
                confirmButtonColor: isDanger ? '#dc3545' : (isWarning ? '#fd7e14' : '#198754'),
                cancelButtonColor: '#6c757d',
                confirmButtonText: btnText || 'Confirm',
                reverseButtons: true
            }).then(function(result) {
                if (result.isConfirmed) {
                    if (typeof formOrCallback === 'function') {
                        formOrCallback();
                    } else if (formOrCallback && formOrCallback.submit) {
                        formOrCallback.submit();
                    }
                }
            });
        }

        // Show session messages on page load
        document.addEventListener('DOMContentLoaded', function() {
            <?php if(session('success')): ?>
            Swal.fire({
                icon: 'success',
                title: 'Success',
                text: <?php echo json_encode(session('success'), 15, 512) ?>,
                timer: 3000,
                showConfirmButton: true,
                confirmButtonColor: '#198754'
            });
            <?php endif; ?>
            <?php if(session('error')): ?>
            Swal.fire({
                icon: 'error',
                title: 'Error',
                text: <?php echo json_encode(session('error'), 15, 512) ?>,
                confirmButtonColor: '#dc3545'
            });
            <?php endif; ?>
            <?php if($errors->any()): ?>
            Swal.fire({
                icon: 'error',
                title: 'Validation Error',
                text: <?php echo json_encode($errors->first(), 15, 512) ?>,
                confirmButtonColor: '#dc3545'
            });
            <?php endif; ?>
            <?php if(session('warning')): ?>
            showToast(<?php echo json_encode(session('warning'), 15, 512) ?>, 'warning');
            <?php endif; ?>
            <?php if(session('info')): ?>
            showToast(<?php echo json_encode(session('info'), 15, 512) ?>, 'info');
            <?php endif; ?>

            // Initialize all popovers
            document.querySelectorAll('[data-bs-toggle="popover"]').forEach(function(el) {
                new bootstrap.Popover(el, {
                    trigger: 'hover focus',
                    html: true,
                    placement: 'top'
                });
            });

            // Wire up all forms/buttons with data-confirm attribute
            document.querySelectorAll('[data-confirm]').forEach(function(el) {
                el.addEventListener('click', function(e) {
                    e.preventDefault();
                    e.stopPropagation();
                    var title = el.getAttribute('data-confirm-title') || 'Confirm Action';
                    var message = el.getAttribute('data-confirm') || 'Are you sure?';
                    var btnText = el.getAttribute('data-confirm-btn') || 'Confirm';
                    var btnClass = el.getAttribute('data-confirm-class') || 'btn-danger';
                    var form = el.closest('form');
                    if (form) {
                        confirmAction(form, title, message, btnText, btnClass);
                    }
                });
            });
        });
    </script>
    <?php echo $__env->yieldContent('scripts'); ?>
</body>

</html><?php /**PATH D:\xampp82\htdocs\AutoPromix\backend\resources\views\client\layouts\dashboard.blade.php ENDPATH**/ ?>