<?php
/**
 * RUHONDO BEACH RESORT HMS + POS System
 * Sidebar Navigation Partial - WITH QUOTATIONS MENU ADDED
 * Developer: JOACHIM'S INNOTECH
 */

// Get current user and permissions
$current_user = current_user();
$user_role = current_user_role();
$current_page = basename($_SERVER['PHP_SELF']);
$current_module = isset($_GET['module']) ? $_GET['module'] : '';
?>

<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
    <!-- Brand Logo -->
    <a href="<?php echo base_url('dashboard.php'); ?>" class="brand-link">
        <img src="<?php echo assets_url('img/logo.png'); ?>" alt="Ruhondo Logo" class="brand-image img-circle elevation-3" style="opacity: .8">
        <span class="brand-text font-weight-light">Ruhondo Beach</span>
    </a>

    <!-- Sidebar -->
    <div class="sidebar">
        <!-- Sidebar user panel (optional) -->
        <div class="user-panel mt-3 pb-3 mb-3 d-flex">
            <div class="image">
                <?php if ($current_user && !empty($current_user['profile_image'])): ?>
                    <img src="<?php echo uploads_url($current_user['profile_image']); ?>" class="img-circle elevation-2" alt="User Image">
                <?php else: ?>
                    <img src="https://www.gravatar.com/avatar/<?php echo md5(strtolower(trim($current_user['email'] ?? ''))); ?>?s=160&d=mp" class="img-circle elevation-2" alt="User Image">
                <?php endif; ?>
            </div>
            <div class="info">
                <a href="<?php echo base_url('profile.php'); ?>" class="d-block"><?php echo escape_html($current_user['first_name'] . ' ' . $current_user['last_name']); ?></a>
            </div>
        </div>

        <!-- Sidebar Menu -->
        <nav class="mt-2">
            <ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu" data-accordion="false">
                
                <!-- Dashboard -->
                <li class="nav-item">
                    <a href="<?php echo base_url('dashboard.php'); ?>" class="nav-link <?php echo $current_page == 'dashboard.php' ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-tachometer-alt"></i>
                        <p>Executive Dashboard</p>
                    </a>
                </li>

                <!-- Front Desk Module (WITH QUOTATIONS ADDED) -->
                <?php if (has_any_permission(['dashboard.frontdesk', 'reservations.view', 'guests.view', 'quotations.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/frontdesk/') !== false || strpos($_SERVER['REQUEST_URI'], '/quotations/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/frontdesk/') !== false || strpos($_SERVER['REQUEST_URI'], '/quotations/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-concierge-bell"></i>
                        <p>
                            Front Desk
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('frontdesk/dashboard.php'); ?>" class="nav-link <?php echo $current_page == 'dashboard.php' && strpos($_SERVER['REQUEST_URI'], '/frontdesk/') !== false ? 'active' : ''; ?>">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Front Desk Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('reservations.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reservations/reservations/index.php'); ?>" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/reservations/') !== false ? 'active' : ''; ?>">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Reservations</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        
                        <!-- QUOTATIONS MENU - NEWLY ADDED -->
                        <?php if (has_permission('quotations.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('quotations/index.php'); ?>" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/quotations/') !== false ? 'active' : ''; ?>">
                                <i class="far fa-file-invoice nav-icon"></i>
                                <p>Quotations</p>
                                <?php 
                                // Optional: Show count of pending quotations
                                if (function_exists('get_pending_quotations_count')) {
                                    $pending_count = get_pending_quotations_count();
                                    if ($pending_count > 0) {
                                        echo '<span class="badge badge-info right">' . $pending_count . '</span>';
                                    }
                                }
                                ?>
                            </a>
                        </li>
                        <?php endif; ?>
                        <!-- END QUOTATIONS MENU -->
                        
                        <?php if (has_permission('guests.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('guests/guests/index.php'); ?>" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/guests/') !== false ? 'active' : ''; ?>">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Guests</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reservations/checkin/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Check-In / Out</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reservations/folio/view.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Guest Folio</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Rooms Module -->
                <?php if (has_any_permission(['dashboard.rooms', 'rooms.view', 'rates.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/rooms/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/rooms/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-bed"></i>
                        <p>
                            Rooms & Rates
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('rooms/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Rooms Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('rooms.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('rooms/rooms/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Rooms</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('rooms/room-types/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Room Types</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('rates.manage')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('rooms/rates/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Rate Plans</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('rooms/availability/calendar.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Availability Calendar</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- POS Module -->
                <?php if (has_any_permission(['dashboard.pos', 'pos.sales.process', 'pos.products.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/pos/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/pos/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-cash-register"></i>
                        <p>
                            Point of Sale
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>POS Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('pos.sales.process')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/sales/pos.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>New Sale</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/sales/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Sales History</p>
                            </a>
                        </li>
                        <?php if (has_permission('pos.shifts.manage')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/shifts/open.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Shift Management</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('pos.products.manage')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/products/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Products</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/categories/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Categories</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/outlets/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Outlets</p>
                            </a>
                        </li>
                        <?php if (has_permission('pos.reports.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('pos/reports/daily-sales.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>POS Reports</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Inventory Module -->
                <?php if (has_any_permission(['dashboard.inventory', 'inventory.purchases.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/inventory/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/inventory/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-boxes"></i>
                        <p>
                            Inventory
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Inventory Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('inventory.suppliers.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/suppliers/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Suppliers</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('inventory.purchases.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/purchases/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Purchase Orders</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('inventory.stock.manage')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/stock/movements.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Stock Movements</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/stock/adjustments.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Stock Adjustments</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('inventory/stock/low-stock.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Low Stock Alert</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Housekeeping Module -->
                <?php if (has_any_permission(['dashboard.housekeeping', 'hk.tasks.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/housekeeping/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/housekeeping/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-broom"></i>
                        <p>
                            Housekeeping
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('housekeeping/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Housekeeping Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('hk.tasks.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('housekeeping/tasks/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Cleaning Tasks</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('housekeeping/cleaning/room-status.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Room Status</p>
                            </a>
                        </li>
                        <?php if (has_permission('hk.maintenance.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('housekeeping/maintenance/tickets.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Maintenance</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Billing Module -->
                <?php if (has_any_permission(['dashboard.billing', 'billing.invoices.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/billing/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/billing/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-file-invoice-dollar"></i>
                        <p>
                            Billing
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('billing/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Billing Dashboard</p>
                            </a>
                        </li>
                        <?php if (has_permission('billing.invoices.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('billing/invoices/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Invoices</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('billing.payments.manage')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('billing/payments/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Payments</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('billing/debtor/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Debtors</p>
                            </a>
                        </li>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Reports Module -->
                <?php if (has_any_permission(['reports.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/reports/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/reports/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-chart-bar"></i>
                        <p>
                            Reports
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('reports/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Reports Dashboard</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reports/occupancy.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Occupancy Reports</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reports/revenue.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Revenue Reports</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('reports/audit.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Audit Logs</p>
                            </a>
                        </li>
                        <!-- Quotations Report -->
                        <?php if (has_permission('quotations.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('quotations/reports.php'); ?>" class="nav-link">
                                <i class="far fa-file-invoice nav-icon"></i>
                                <p>Quotations Report</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Admin Module -->
                <?php if (has_any_permission(['users.view', 'settings.view'])): ?>
                <li class="nav-item <?php echo strpos($_SERVER['REQUEST_URI'], '/admin/') !== false ? 'menu-open' : ''; ?>">
                    <a href="#" class="nav-link <?php echo strpos($_SERVER['REQUEST_URI'], '/admin/') !== false ? 'active' : ''; ?>">
                        <i class="nav-icon fas fa-cog"></i>
                        <p>
                            Administration
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <?php if (has_permission('users.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/dashboard.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Admin Dashboard</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/users/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>User Management</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/users/roles.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Roles & Permissions</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('users.audit')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/users/audit-logs.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Audit Logs</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <?php if (has_permission('settings.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/settings/index.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>System Settings</p>
                            </a>
                        </li>
                        <?php endif; ?>
                        <!-- Quotations Settings (if needed) -->
                        <?php if (has_permission('settings.view')): ?>
                        <li class="nav-item">
                            <a href="<?php echo base_url('admin/settings/quotations.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Quotation Settings</p>
                            </a>
                        </li>
                        <?php endif; ?>
                    </ul>
                </li>
                <?php endif; ?>

                <!-- Help & Support -->
                <li class="nav-item">
                    <a href="#" class="nav-link">
                        <i class="nav-icon fas fa-question-circle"></i>
                        <p>
                            Help & Support
                            <i class="right fas fa-angle-left"></i>
                        </p>
                    </a>
                    <ul class="nav nav-treeview">
                        <li class="nav-item">
                            <a href="<?php echo base_url('help/user-guide.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>User Guide</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('help/faq.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>FAQ</p>
                            </a>
                        </li>
                        <li class="nav-item">
                            <a href="<?php echo base_url('help/contact.php'); ?>" class="nav-link">
                                <i class="far fa-circle nav-icon"></i>
                                <p>Contact Support</p>
                            </a>
                        </li>
                    </ul>
                </li>
            </ul>
        </nav>
        <!-- /.sidebar-menu -->
    </div>
    <!-- /.sidebar -->
</aside>

<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
    <div class="p-3">
        <h5>Quick Settings</h5>
        <hr class="mb-2">
        
        <div class="form-group">
            <label>Theme</label>
            <select class="form-control form-control-sm" id="themeSwitcher">
                <option value="light">Light</option>
                <option value="dark">Dark</option>
                <option value="auto">Auto</option>
            </select>
        </div>
        
        <div class="form-group">
            <label>Sidebar Size</label>
            <select class="form-control form-control-sm" id="sidebarSize">
                <option value="normal">Normal</option>
                <option value="compact">Compact</option>
                <option value="mini">Mini</option>
            </select>
        </div>
        
        <hr>
        
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="fixedLayout" checked>
            <label class="form-check-label" for="fixedLayout">Fixed Layout</label>
        </div>
        
        <div class="form-check">
            <input type="checkbox" class="form-check-input" id="boxedLayout">
            <label class="form-check-label" for="boxedLayout">Boxed Layout</label>
        </div>
        
        <hr>
        
        <button class="btn btn-primary btn-block btn-sm" onclick="resetSettings()">
            <i class="fas fa-undo"></i> Reset to Default
        </button>
    </div>
</aside>
<!-- /.control-sidebar -->

<!-- Add this helper function to get pending quotations count -->
<?php
// Add this function to your functions.php or include it here
if (!function_exists('get_pending_quotations_count')) {
    function get_pending_quotations_count() {
        try {
            return (int)db_fetch_value("
                SELECT COUNT(*) FROM quotations 
                WHERE status IN ('draft', 'sent')
                AND valid_until >= CURDATE()
            ") ?: 0;
        } catch (Exception $e) {
            return 0;
        }
    }
}
?>

<!-- Add CSS for sidebar -->
<style>
    .main-sidebar {
        background-color: #343a40;
    }
    
    .brand-link {
        border-bottom: 1px solid #4b545c;
        padding: 0.8125rem 0.5rem;
    }
    
    .brand-image {
        width: 33px;
        height: 33px;
        object-fit: cover;
    }
    
    .user-panel {
        border-bottom: 1px solid #4b545c;
    }
    
    .user-panel .image img {
        width: 35px;
        height: 35px;
        object-fit: cover;
    }
    
    .nav-sidebar .nav-link.active {
        background-color: #007bff;
        color: #fff;
    }
    
    .nav-sidebar .nav-link:hover {
        background-color: #2c3b41;
    }
    
    .nav-treeview .nav-link {
        padding-left: 2rem;
    }
    
    .nav-treeview .nav-link .nav-icon {
        font-size: 0.75rem;
    }
    
    .control-sidebar {
        background-color: #343a40;
        color: #fff;
    }
    
    .control-sidebar hr {
        border-top-color: #4b545c;
    }
    
    .control-sidebar .form-control {
        background-color: #454d55;
        border-color: #4b545c;
        color: #fff;
    }
    
    .control-sidebar .form-control:focus {
        background-color: #4b545c;
        border-color: #007bff;
    }
    
    /* Compact sidebar */
    .sidebar-compact .nav-sidebar .nav-link {
        padding: 0.5rem 0.5rem;
    }
    
    .sidebar-compact .nav-sidebar .nav-link p {
        font-size: 0.875rem;
    }
    
    /* Mini sidebar (icons only) */
    .sidebar-mini .main-sidebar {
        width: 4.6rem;
    }
    
    .sidebar-mini .main-sidebar .brand-text,
    .sidebar-mini .main-sidebar .user-panel .info,
    .sidebar-mini .main-sidebar .nav-sidebar .nav-link p {
        display: none;
    }
    
    .sidebar-mini .main-sidebar .nav-sidebar .nav-link {
        text-align: center;
        padding: 0.75rem 0;
    }
    
    .sidebar-mini .main-sidebar .nav-sidebar .nav-link .nav-icon {
        margin-right: 0;
        font-size: 1.2rem;
    }
    
    .sidebar-mini .content-wrapper {
        margin-left: 4.6rem;
    }
    
    /* Badge styling for notification counts */
    .nav-sidebar .nav-link .badge {
        padding: 3px 6px;
        font-size: 0.75rem;
        margin-left: 5px;
    }
    
    @media (max-width: 767.98px) {
        .sidebar-mini .main-sidebar {
            transform: translateX(-100%);
        }
        
        .sidebar-mini.sidebar-open .main-sidebar {
            transform: translateX(0);
            width: 250px;
        }
        
        .sidebar-mini.sidebar-open .main-sidebar .brand-text,
        .sidebar-mini.sidebar-open .main-sidebar .user-panel .info,
        .sidebar-mini.sidebar-open .main-sidebar .nav-sidebar .nav-link p {
            display: block;
        }
    }
</style>

<script>
    // Sidebar functionality
    document.addEventListener('DOMContentLoaded', function() {
        // Load saved settings
        loadSidebarSettings();
        
        // Theme switcher
        document.getElementById('themeSwitcher')?.addEventListener('change', function() {
            const theme = this.value;
            document.body.classList.remove('dark-mode', 'light-mode', 'auto-mode');
            document.body.classList.add(theme + '-mode');
            localStorage.setItem('theme', theme);
        });
        
        // Sidebar size switcher
        document.getElementById('sidebarSize')?.addEventListener('change', function() {
            const size = this.value;
            document.body.classList.remove('sidebar-compact', 'sidebar-mini');
            if (size !== 'normal') {
                document.body.classList.add('sidebar-' + size);
            }
            localStorage.setItem('sidebarSize', size);
        });
        
        // Fixed layout toggle
        document.getElementById('fixedLayout')?.addEventListener('change', function() {
            if (this.checked) {
                document.body.classList.add('fixed');
            } else {
                document.body.classList.remove('fixed');
            }
            localStorage.setItem('fixedLayout', this.checked);
        });
        
        // Boxed layout toggle
        document.getElementById('boxedLayout')?.addEventListener('change', function() {
            if (this.checked) {
                document.body.classList.add('layout-boxed');
            } else {
                document.body.classList.remove('layout-boxed');
            }
            localStorage.setItem('boxedLayout', this.checked);
        });
        
        // Handle active menu states
        const url = window.location.pathname;
        const menuItems = document.querySelectorAll('.nav-treeview .nav-link');
        menuItems.forEach(item => {
            if (item.getAttribute('href') === url) {
                item.classList.add('active');
                // Expand parent menu
                const parentLi = item.closest('.nav-item');
                if (parentLi) {
                    parentLi.classList.add('menu-open');
                }
            }
        });
    });
    
    function loadSidebarSettings() {
        // Load theme
        const savedTheme = localStorage.getItem('theme') || 'light';
        document.getElementById('themeSwitcher').value = savedTheme;
        document.body.classList.add(savedTheme + '-mode');
        
        // Load sidebar size
        const savedSize = localStorage.getItem('sidebarSize') || 'normal';
        document.getElementById('sidebarSize').value = savedSize;
        if (savedSize !== 'normal') {
            document.body.classList.add('sidebar-' + savedSize);
        }
        
        // Load layout settings
        const savedFixed = localStorage.getItem('fixedLayout') !== 'false';
        document.getElementById('fixedLayout').checked = savedFixed;
        if (savedFixed) {
            document.body.classList.add('fixed');
        }
        
        const savedBoxed = localStorage.getItem('boxedLayout') === 'true';
        document.getElementById('boxedLayout').checked = savedBoxed;
        if (savedBoxed) {
            document.body.classList.add('layout-boxed');
        }
    }
    
    function resetSettings() {
        localStorage.removeItem('theme');
        localStorage.removeItem('sidebarSize');
        localStorage.removeItem('fixedLayout');
        localStorage.removeItem('boxedLayout');
        location.reload();
    }
</script>