<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= isset($page_title) ? $page_title . ' - ' : '' ?>Super Admin Portal</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.0/font/bootstrap-icons.css" rel="stylesheet">
    <!-- DataTables -->
    <link href="https://cdn.datatables.net/1.13.6/css/dataTables.bootstrap5.min.css" rel="stylesheet">
    <!-- Chart.js -->
    <script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
    
    <style>
        :root {
            --sa-primary: #1a1a2e;
            --sa-secondary: #16213e;
            --sa-accent: #e94560;
            --sa-light: #0f3460;
            --sa-success: #00bf63;
            --sa-warning: #ffc107;
            --sa-danger: #dc3545;
        }
        
        body {
            background-color: #f4f6f9;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        
        /* Sidebar */
        .sidebar {
            position: fixed;
            top: 0;
            left: 0;
            height: 100vh;
            width: 260px;
            background: linear-gradient(180deg, var(--sa-primary) 0%, var(--sa-secondary) 100%);
            padding-top: 0;
            z-index: 1000;
            transition: all 0.3s;
            overflow-y: auto;
        }
        
        .sidebar-brand {
            padding: 20px;
            text-align: center;
            border-bottom: 1px solid rgba(255,255,255,0.1);
            background: rgba(0,0,0,0.2);
        }
        
        .sidebar-brand h4 {
            color: #fff;
            margin: 0;
            font-weight: 700;
        }
        
        .sidebar-brand small {
            color: var(--sa-accent);
            font-size: 0.75rem;
        }
        
        .sidebar-menu {
            padding: 20px 0;
        }
        
        .sidebar-menu .nav-link {
            color: rgba(255,255,255,0.7);
            padding: 12px 25px;
            display: flex;
            align-items: center;
            transition: all 0.3s;
            border-left: 3px solid transparent;
        }
        
        .sidebar-menu .nav-link:hover {
            color: #fff;
            background: rgba(255,255,255,0.05);
            border-left-color: var(--sa-accent);
        }
        
        .sidebar-menu .nav-link.active {
            color: #fff;
            background: rgba(233, 69, 96, 0.2);
            border-left-color: var(--sa-accent);
        }
        
        .sidebar-menu .nav-link i {
            margin-right: 10px;
            font-size: 1.1rem;
            width: 24px;
        }
        
        .sidebar-divider {
            border-top: 1px solid rgba(255,255,255,0.1);
            margin: 15px 20px;
        }
        
        .sidebar-heading {
            color: rgba(255,255,255,0.4);
            font-size: 0.7rem;
            text-transform: uppercase;
            letter-spacing: 1px;
            padding: 0 25px;
            margin-bottom: 10px;
        }
        
        /* Main Content */
        .main-content {
            margin-left: 260px;
            min-height: 100vh;
            transition: all 0.3s;
        }
        
        /* Top Navbar */
        .top-navbar {
            background: #fff;
            padding: 15px 30px;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
            display: flex;
            justify-content: space-between;
            align-items: center;
            position: sticky;
            top: 0;
            z-index: 999;
        }
        
        .top-navbar .breadcrumb {
            margin-bottom: 0;
            background: transparent;
            padding: 0;
        }
        
        .user-menu .dropdown-toggle::after {
            display: none;
        }
        
        .user-menu .dropdown-toggle {
            display: flex;
            align-items: center;
            color: var(--sa-primary);
            text-decoration: none;
        }
        
        .user-avatar {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            background: var(--sa-accent);
            display: flex;
            align-items: center;
            justify-content: center;
            color: #fff;
            font-weight: 600;
            margin-right: 10px;
        }
        
        /* Content Area */
        .content-area {
            padding: 30px;
        }
        
        /* Cards */
        .stat-card {
            background: #fff;
            border-radius: 15px;
            padding: 25px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.05);
            transition: transform 0.3s;
            border: none;
        }
        
        .stat-card:hover {
            transform: translateY(-5px);
        }
        
        .stat-card .stat-icon {
            width: 60px;
            height: 60px;
            border-radius: 12px;
            display: flex;
            align-items: center;
            justify-content: center;
            font-size: 1.5rem;
            color: #fff;
        }
        
        .stat-card .stat-value {
            font-size: 2rem;
            font-weight: 700;
            color: var(--sa-primary);
        }
        
        .stat-card .stat-label {
            color: #6c757d;
            font-size: 0.9rem;
        }
        
        .bg-gradient-primary {
            background: linear-gradient(45deg, var(--sa-primary), var(--sa-light));
        }
        
        .bg-gradient-success {
            background: linear-gradient(45deg, #00bf63, #00a855);
        }
        
        .bg-gradient-warning {
            background: linear-gradient(45deg, #ffc107, #ffab00);
        }
        
        .bg-gradient-danger {
            background: linear-gradient(45deg, #e94560, #d63050);
        }
        
        .bg-gradient-info {
            background: linear-gradient(45deg, #17a2b8, #138496);
        }
        
        /* Tables */
        .table-card {
            background: #fff;
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0,0,0,0.05);
            overflow: hidden;
        }
        
        .table-card .card-header {
            background: #fff;
            border-bottom: 1px solid #eee;
            padding: 20px 25px;
        }
        
        .table-card .card-header h5 {
            margin: 0;
            font-weight: 600;
            color: var(--sa-primary);
        }
        
        /* Portal Status Badges */
        .portal-status {
            padding: 5px 12px;
            border-radius: 20px;
            font-size: 0.75rem;
            font-weight: 600;
        }
        
        .portal-status.active {
            background: rgba(0, 191, 99, 0.1);
            color: #00bf63;
        }
        
        .portal-status.inactive {
            background: rgba(108, 117, 125, 0.1);
            color: #6c757d;
        }
        
        .portal-status.maintenance {
            background: rgba(255, 193, 7, 0.1);
            color: #d39e00;
        }
        
        /* Buttons */
        .btn-sa-primary {
            background: var(--sa-accent);
            border-color: var(--sa-accent);
            color: #fff;
        }
        
        .btn-sa-primary:hover {
            background: #d63050;
            border-color: #d63050;
            color: #fff;
        }
        
        /* Responsive */
        @media (max-width: 768px) {
            .sidebar {
                transform: translateX(-100%);
            }
            
            .sidebar.show {
                transform: translateX(0);
            }
            
            .main-content {
                margin-left: 0;
            }
        }
        
        /* Quick Actions */
        .quick-action {
            display: flex;
            align-items: center;
            padding: 15px 20px;
            background: #fff;
            border-radius: 10px;
            text-decoration: none;
            color: var(--sa-primary);
            transition: all 0.3s;
            box-shadow: 0 2px 10px rgba(0,0,0,0.05);
        }
        
        .quick-action:hover {
            transform: translateY(-3px);
            box-shadow: 0 5px 20px rgba(0,0,0,0.1);
            color: var(--sa-accent);
        }
        
        .quick-action i {
            font-size: 1.5rem;
            margin-right: 15px;
            color: var(--sa-accent);
        }
        
        /* Activity Log */
        .activity-item {
            display: flex;
            padding: 15px 0;
            border-bottom: 1px solid #eee;
        }
        
        .activity-item:last-child {
            border-bottom: none;
        }
        
        .activity-icon {
            width: 40px;
            height: 40px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 15px;
            font-size: 0.9rem;
        }
        
        .activity-content h6 {
            margin-bottom: 3px;
            font-weight: 600;
        }
        
        .activity-content small {
            color: #6c757d;
        }
    </style>
</head>
<body>
    <!-- Sidebar -->
    <nav class="sidebar" id="sidebar">
        <div class="sidebar-brand">
            <h4><i class="bi bi-shield-lock-fill me-2"></i>Super Admin</h4>
            <small>Portal Management System</small>
        </div>
        
        <div class="sidebar-menu">
            <a class="nav-link <?= $this->uri->segment(2) == '' || $this->uri->segment(2) == 'dashboard' ? 'active' : '' ?>" href="<?= base_url('superadmin/dashboard') ?>">
                <i class="bi bi-speedometer2"></i> Dashboard
            </a>
            
            <div class="sidebar-divider"></div>
            <p class="sidebar-heading">Portal Management</p>
            
            <a class="nav-link <?= $this->uri->segment(2) == 'portals' ? 'active' : '' ?>" href="<?= base_url('superadmin/portals') ?>">
                <i class="bi bi-grid-3x3-gap-fill"></i> All Portals
            </a>
            <a class="nav-link <?= $this->uri->segment(2) == 'users' ? 'active' : '' ?>" href="<?= base_url('superadmin/users') ?>">
                <i class="bi bi-people-fill"></i> Users
            </a>
            <a class="nav-link <?= $this->uri->segment(2) == 'campaigns' ? 'active' : '' ?>" href="<?= base_url('superadmin/campaigns') ?>">
                <i class="bi bi-megaphone-fill"></i> Campaigns
            </a>
            <a class="nav-link <?= $this->uri->segment(2) == 'data' && $this->uri->segment(3) != 'user_assignments' ? 'active' : '' ?>" href="<?= base_url('superadmin/data') ?>">
                <i class="bi bi-database-fill"></i> Master Data
            </a>
            <a class="nav-link <?= $this->uri->segment(3) == 'user_assignments' || $this->uri->segment(3) == 'assign_to_user' ? 'active' : '' ?>" href="<?= base_url('superadmin/data/user_assignments') ?>">
                <i class="bi bi-person-lines-fill"></i> User Assignments
            </a>
            <a class="nav-link <?= $this->uri->segment(2) == 'messages' ? 'active' : '' ?>" href="<?= base_url('superadmin/messages') ?>">
                <i class="bi bi-chat-dots-fill"></i> Messages
            </a>
            
            <div class="sidebar-divider"></div>
            <p class="sidebar-heading">Analytics</p>
            
            <a class="nav-link <?= $this->uri->segment(2) == 'reports' ? 'active' : '' ?>" href="<?= base_url('superadmin/reports') ?>">
                <i class="bi bi-graph-up"></i> Reports
            </a>
            
            <div class="sidebar-divider"></div>
            <p class="sidebar-heading">System</p>
            
            <a class="nav-link <?= $this->uri->segment(2) == 'settings' ? 'active' : '' ?>" href="<?= base_url('superadmin/settings') ?>">
                <i class="bi bi-gear-fill"></i> Settings
            </a>
            <a class="nav-link" href="<?= base_url('superadmin/auth/logout') ?>">
                <i class="bi bi-box-arrow-right"></i> Logout
            </a>
        </div>
    </nav>
    
    <!-- Main Content -->
    <div class="main-content">
        <!-- Top Navbar -->
        <nav class="top-navbar">
            <div>
                <button class="btn btn-link d-md-none" id="sidebarToggle">
                    <i class="bi bi-list fs-4"></i>
                </button>
                <nav aria-label="breadcrumb" class="d-none d-md-block">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="<?= base_url('superadmin/dashboard') ?>">Super Admin</a></li>
                        <?php if(isset($page_title)): ?>
                        <li class="breadcrumb-item active"><?= $page_title ?></li>
                        <?php endif; ?>
                    </ol>
                </nav>
            </div>
            
            <div class="user-menu dropdown">
                <a href="#" class="dropdown-toggle" data-bs-toggle="dropdown">
                    <div class="user-avatar">
                        <?= strtoupper(substr($this->session->userdata('super_admin_name') ?? 'SA', 0, 1)) ?>
                    </div>
                    <div class="d-none d-md-block">
                        <strong><?= $this->session->userdata('super_admin_name') ?? 'Super Admin' ?></strong>
                        <small class="d-block text-muted">Administrator</small>
                    </div>
                </a>
                <ul class="dropdown-menu dropdown-menu-end">
                    <li><a class="dropdown-item" href="<?= base_url('superadmin/settings') ?>"><i class="bi bi-person me-2"></i> Profile</a></li>
                    <li><a class="dropdown-item" href="<?= base_url('superadmin/settings/password') ?>"><i class="bi bi-key me-2"></i> Change Password</a></li>
                    <li><hr class="dropdown-divider"></li>
                    <li><a class="dropdown-item text-danger" href="<?= base_url('superadmin/auth/logout') ?>"><i class="bi bi-box-arrow-right me-2"></i> Logout</a></li>
                </ul>
            </div>
        </nav>
        
        <!-- Content Area -->
        <div class="content-area">
