<?php 
require_once __DIR__ . '/auth.php';
require_once __DIR__ . '/functions.php';
startSession();

if (!isset($pageTitle)) $pageTitle = 'Dashboard';
?>
<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title><?= htmlspecialchars($pageTitle) ?> - Lintas Fiber Nusantara</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">

<!-- Google Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap" rel="stylesheet">

<!-- ============================================
     GLOBAL CSS - SEMUA STYLE ADA DI SINI
     ============================================ -->
<style>
/* ============================================
   CSS VARIABLES
   ============================================ */
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #e0e7ff;
    --success: #10b981;
    --success-light: #d1fae5;
    --warning: #f59e0b;
    --warning-light: #fef3c7;
    --danger: #ef4444;
    --danger-light: #fee2e2;
    --info: #06b6d4;
    --info-light: #cffafe;
    --bg-body: #f1f5f9;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --radius: 12px;
    --radius-sm: 8px;
    --sidebar-width: 260px;
}

/* ============================================
   GLOBAL RESET
   ============================================ */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
}

/* ============================================
   SIDEBAR
   ============================================ */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--bg-sidebar);
    color: white;
    z-index: 1040;
    transition: transform 0.3s ease;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sidebar-brand-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), #7c3aed);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.sidebar-brand-text h5 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
}

.sidebar-brand-text small {
    font-size: 11px;
    opacity: 0.6;
    text-transform: uppercase;
}

.sidebar-close {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
}

.sidebar-nav {
    padding: 12px;
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.sidebar-nav::-webkit-scrollbar { width: 6px; }
.sidebar-nav::-webkit-scrollbar-track { background: rgba(255, 255, 255, 0.05); }
.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 3px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: var(--radius-sm);
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s;
}

.sidebar-nav .nav-link:hover {
    background: var(--bg-sidebar-hover);
    color: white;
}

.sidebar-nav .nav-link.active {
    background: var(--primary);
    color: white;
}

.sidebar-nav .nav-link i {
    font-size: 18px;
    width: 24px;
    text-align: center;
}

.sidebar-section-title {
    padding: 8px 16px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
    margin-top: 8px;
}

/* ============================================
   SIDEBAR FOOTER
   ============================================ */
.sidebar-footer {
    padding: 15px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(0, 0, 0, 0.2);
    flex-shrink: 0;
    margin-top: auto;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    padding: 8px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 14px;
    flex-shrink: 0;
}

.user-details {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.user-name {
    color: white;
    font-size: 13px;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    line-height: 1.2;
}

.user-role {
    color: rgba(255, 255, 255, 0.6);
    font-size: 11px;
    margin: 0;
    line-height: 1.2;
    margin-top: 2px;
}

.btn-logout {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: white;
    text-decoration: none;
    font-size: 13px;
    transition: all 0.2s;
    width: 100%;
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.btn-logout:hover {
    background: rgba(220, 53, 69, 0.8);
    color: white;
    border-color: rgba(220, 53, 69, 0.8);
}

/* ============================================
   SIDEBAR OVERLAY
   ============================================ */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* ============================================
   MAIN CONTENT
   ============================================ */
/* ============================================
   MAIN CONTENT - FORCE MARGIN LEFT
   ============================================ */
.main-content {
    margin-left: var(--sidebar-width) !important;
    padding: 0 !important;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

.content-wrapper {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

body.sidebar-hidden .main-content {
    margin-left: 0 !important;
}

@media (max-width: 768px) {
    .main-content {
        margin-left: 0 !important;
    }
    .content-wrapper {
        padding: 15px;
    }
}

@media (max-width: 576px) {
    .content-wrapper {
        padding: 12px;
    }
}

/* ============================================
   NAVBAR MODERN
   ============================================ */
.navbar-modern {
    position: sticky;
    top: 0;
    z-index: 1030;
    background: linear-gradient(135deg, #0066CC 0%, #00B4FF 100%);
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.navbar-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.burger-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    transition: all 0.3s ease;
}

.burger-btn:hover {
    background: rgba(255,255,255,0.25);
    transform: scale(1.05);
}

.navbar-greeting {
    color: rgba(255,255,255,0.85);
    font-size: 0.78rem;
    margin: 0;
}

.navbar-title {
    color: white;
    font-size: 1.2rem;
    font-weight: 700;
    margin: 0;
}

.navbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
}

.navbar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(255,255,255,0.15);
    padding: 6px 14px 6px 6px;
    border-radius: 30px;
    color: white;
    text-decoration: none;
    transition: all 0.3s ease;
}

.navbar-user:hover {
    background: rgba(255,255,255,0.25);
    color: white;
}

.navbar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: linear-gradient(135deg, #FF9900 0%, #FFB84D 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 0.9rem;
}

.navbar-user-name {
    font-size: 0.88rem;
    font-weight: 600;
}

.navbar-badge {
    background: rgba(255,255,255,0.2);
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.82rem;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

/* ============================================
   CONTENT WRAPPER
   ============================================ */
.content-wrapper {
    padding: 20px;
    max-width: 1400px;
    margin: 0 auto;
}

/* ============================================
   TOP BAR (LEGACY)
   ============================================ */
.top-bar {
    background: var(--bg-card);
    padding: 16px 24px;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.top-bar-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-primary);
}

.top-bar h3 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-card);
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.card-header {
    background: transparent;
    border-bottom: 1px solid var(--border-color);
    padding: 16px 20px;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.card-body { padding: 20px; }

/* ============================================
   STAT CARDS
   ============================================ */
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: all 0.3s;
    border-left: 4px solid transparent;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
}

.stat-card.primary { border-left-color: var(--primary); }
.stat-card.success { border-left-color: var(--success); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.info { border-left-color: var(--info); }

.stat-content { flex: 1; }

.stat-label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.stat-subtitle { font-size: 12px; color: var(--text-muted); }

.stat-icon {
    width: 56px;
    height: 56px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
}

.stat-card.primary .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card.success .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card.warning .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card.danger .stat-icon { background: var(--danger-light); color: var(--danger); }
.stat-card.info .stat-icon { background: var(--info-light); color: var(--info); }

/* ============================================
   TABLES
   ============================================ */
.table-responsive { border-radius: var(--radius); overflow: hidden; }

.table { margin-bottom: 0; font-size: 14px; }

.table thead th {
    background: #f8fafc;
    border-bottom: 2px solid var(--border-color);
    padding: 12px 16px;
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.table tbody td {
    padding: 14px 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--border-color);
}

.table tbody tr:hover { background: #f8fafc; }

/* ============================================
   BUTTONS
   ============================================ */
.btn {
    font-weight: 600;
    font-size: 14px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
    color: white;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); color: white; }

.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }

.btn-outline-primary {
    background: transparent;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}

.btn-outline-primary:hover {
    background: var(--primary);
    color: white;
}

.btn-outline-danger {
    background: transparent;
    color: var(--danger);
    border: 1.5px solid var(--danger);
}

.btn-outline-secondary {
    background: transparent;
    color: var(--text-secondary);
    border: 1.5px solid var(--border-color);
}

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-lg { padding: 14px 28px; font-size: 16px; }

/* ============================================
   BADGES
   ============================================ */
.badge {
    font-weight: 600;
    font-size: 11px;
    padding: 4px 10px;
    border-radius: 20px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-secondary { background: #f1f5f9; color: var(--text-secondary); }

/* ============================================
   FORMS
   ============================================ */
.form-control, .form-select {
    border: 1.5px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 14px;
    transition: all 0.2s;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
    outline: none;
}

.form-label {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 6px;
}

/* ============================================
   ALERTS
   ============================================ */
.alert {
    border: none;
    border-radius: var(--radius);
    padding: 16px 20px;
    font-size: 14px;
    margin-bottom: 20px;
}

.alert-success { background: var(--success-light); color: #065f46; border-left: 4px solid var(--success); }
.alert-warning { background: var(--warning-light); color: #92400e; border-left: 4px solid var(--warning); }
.alert-danger { background: var(--danger-light); color: #991b1b; border-left: 4px solid var(--danger); }
.alert-info { background: var(--info-light); color: #155e75; border-left: 4px solid var(--info); }

/* ============================================
   MODAL
   ============================================ */
.modal-content {
    border: none;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ============================================
   RESPONSIVE - DESKTOP
   ============================================ */
@media (min-width: 769px) {
    .menu-toggle { display: none !important; }
    .sidebar-close { display: none !important; }
    .sidebar { transform: translateX(0) !important; }
    .sidebar-overlay { display: none !important; }
    
    .burger-btn {
        display: flex !important;
    }
    
    body.sidebar-hidden .sidebar {
        transform: translateX(-100%);
    }
    body.sidebar-hidden .main-content {
        margin-left: 0;
    }
}

/* ============================================
   RESPONSIVE - MOBILE
   ============================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.active {
        transform: translateX(0);
    }
    
    .sidebar-close {
        display: block;
    }
    
    .main-content {
        margin-left: 0;
    }
    
    .navbar-modern {
        padding: 12px 15px;
    }
    
    .navbar-title {
        font-size: 1rem;
    }
    
    .navbar-greeting {
        display: none;
    }
    
    .navbar-user-name {
        display: none;
    }
    
    .navbar-user {
        padding: 4px;
    }
    
    .navbar-badge {
        display: none;
    }
    
    .content-wrapper {
        padding: 15px;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
    
    .top-bar { padding: 12px 16px; }
    .top-bar h3 { font-size: 18px; }
    
    .stat-card { padding: 16px; }
    .stat-value { font-size: 22px; }
    .stat-icon { width: 48px; height: 48px; font-size: 20px; }
    
    .card-body { padding: 16px; }
    .btn { padding: 8px 16px; font-size: 13px; }
}


@media (max-width: 576px) {
    .content-wrapper { padding: 12px; }
    .stat-value { font-size: 20px; }
}
</style>
</head>
<body>

<!-- Sidebar Overlay -->
<div class="sidebar-overlay" id="sidebarOverlay"></div>