<?php $currentTheme = \App\Services\ThemeService::getCurrent(); ?>
<!DOCTYPE html>
<html lang="<?php echo \App\Services\LanguageService::getLang(); ?>" data-theme="<?php echo $currentTheme; ?>">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?php echo __('admin_dashboard'); ?> - <?php echo htmlspecialchars(get_setting('site_name', 'APK ADMIN')); ?></title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <link rel="icon" type="image/x-icon" href="/<?php echo get_setting('site_favicon'); ?>">
    <script>
        // Early theme initialization
        (function() {
            const savedTheme = localStorage.getItem('theme');
            if (savedTheme) {
                document.documentElement.setAttribute('data-theme', savedTheme);
            }
        })();
    </script>
    <style>
        :root {
            --primary-color: #4e73df;
            --success-color: #1cc88a;
            --bg-color: #f8f9fc;
            --card-bg: #ffffff;
            --text-color: #5a5c69;
            --navbar-bg: #ffffff;
            --border-color: #e3e6f0;
            --subtle-bg: #eaecf4;
            --accent-color: #4e73df;
        }

        [data-theme="dark"] {
            --bg-color: #0f172a;
            --card-bg: #1e293b;
            --text-color: #f1f5f9;
            --navbar-bg: #1e293b;
            --border-color: rgba(255, 255, 255, 0.1);
            --subtle-bg: #0f172a;
            --accent-color: #60a5fa;
        }

        body {
            background-color: var(--bg-color);
            color: var(--text-color);
            font-family: 'Inter', sans-serif;
            transition: background-color 0.3s, color 0.3s;
        }
        .navbar-admin {
            background-color: var(--navbar-bg);
            box-shadow: 0 .15rem 1.75rem 0 rgba(58,59,69,.15);
            border-bottom: 1px solid var(--border-color);
        }
        .nav-link {
            color: var(--primary-color);
            padding: 0.5rem 1rem;
            border-radius: 0.35rem;
            transition: all 0.2s;
            font-weight: 600;
        }
        [data-theme="dark"] .nav-link {
            color: #858796;
        }
        .nav-link:hover {
            background-color: rgba(78, 115, 223, 0.1);
            color: #224abe;
        }
        .nav-link.active {
            background-color: var(--primary-color);
            color: #fff !important;
        }
        .card {
            background-color: var(--card-bg);
            border-color: var(--border-color);
            color: var(--text-color);
        }
        .theme-toggle-btn {
            cursor: pointer;
            padding: 8px;
            border-radius: 50%;
            transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
            width: 38px;
            height: 38px;
            display: flex;
            align-items: center;
            justify-content: center;
            border: 1px solid var(--border-color);
            background: var(--subtle-bg);
            color: var(--text-color);
        }
        .theme-toggle-btn:hover {
            background-color: var(--border-color);
            transform: rotate(15deg) scale(1.05);
        }
        [data-theme="dark"] .theme-toggle-btn {
            box-shadow: 0 0 10px rgba(245, 158, 11, 0.2);
            border-color: rgba(245, 158, 11, 0.3);
            color: #F59E0B;
        }
        [data-theme="dark"] .bg-white {
            background-color: var(--card-bg) !important;
        }
        [data-theme="dark"] .text-muted {
            color: #94a3b8 !important;
        }
        [data-theme="dark"] .form-control {
            background-color: #0f172a;
            border-color: rgba(255, 255, 255, 0.1);
            color: #f1f5f9;
        }
        [data-theme="dark"] .navbar-toggler-icon {
            filter: invert(1);
        }

        .lang-selector-btn {
            background: var(--subtle-bg);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 0.4rem 0.8rem;
            font-size: 0.85rem;
            font-weight: 600;
            color: var(--text-color);
            display: flex;
            align-items: center;
            gap: 6px;
            transition: all 0.2s ease;
        }
        .lang-selector-btn:hover {
            background-color: var(--border-color);
        }

        @media (max-width: 991.98px) {
            .navbar-collapse {
                background-color: var(--card-bg);
                margin-top: 1rem;
                padding: 1rem;
                border-radius: 0.75rem;
                border: 1px solid var(--border-color);
                box-shadow: 0 0.5rem 1rem rgba(0,0,0,0.1);
            }
            .admin-controls-row {
                display: flex;
                flex-direction: column;
                align-items: stretch;
                gap: 1rem;
                padding-top: 1rem;
                margin-top: 1rem;
                border-top: 1px solid var(--border-color);
            }
            .admin-controls-row > div, 
            .admin-controls-row > button {
                width: 100%;
                justify-content: space-between !important;
            }
            .mobile-theme-row {
                display: flex;
                align-items: center;
                justify-content: space-between;
                background: var(--subtle-bg);
                padding: 0.5rem 1rem;
                border-radius: 8px;
            }
        }
    </style>
</head>
<body>
    <nav class="navbar navbar-expand-lg navbar-admin sticky-top py-3">
        <div class="container-fluid px-4">
            <a class="navbar-brand fw-bold text-primary d-flex align-items-center" href="/admin/dashboard">
                <?php if (get_setting('site_icon')): ?>
                    <img src="/<?php echo get_setting('site_icon'); ?>" alt="Logo" class="me-2" style="height: 30px;">
                <?php else: ?>
                    <i class="fas fa-shield-halved me-2"></i>
                <?php endif; ?>
                <?php echo htmlspecialchars(get_setting('site_name', 'APK ADMIN')); ?>
            </a>
            <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
                <span class="navbar-toggler-icon"></span>
            </button>
            <div class="collapse navbar-collapse" id="navbarNav">
                <ul class="navbar-nav me-auto">
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/dashboard"><i class="fas fa-tachometer-alt me-1"></i> Dashboard</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/users"><i class="fas fa-users me-1"></i> Members</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/apks"><i class="fas fa-mobile-alt me-1"></i> APKs</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/apks/mass-upload"><i class="fas fa-cloud-upload-alt me-1"></i> Mass Upload</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/posts"><i class="fas fa-newspaper me-1"></i> Blog</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/categories"><i class="fas fa-list me-1"></i> <?php echo __('categories'); ?></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/withdrawals"><i class="fas fa-wallet me-1"></i> <?php echo __('manage_withdrawals'); ?></a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link px-3 mb-1" href="/admin/settings"><i class="fas fa-cog me-1"></i> <?php echo __('settings'); ?></a>
                    </li>
                </ul>
                
                <div class="d-lg-flex align-items-center ms-auto admin-controls-row">
                    <!-- Theme & Lang Row (Desktop) / Column (Mobile) -->
                    <div class="d-none d-lg-flex align-items-center">
                        <button id="theme-toggle" class="theme-toggle-btn me-3" aria-label="Toggle theme">
                            <i class="fa-solid <?php echo $currentTheme === 'dark' ? 'fa-sun' : 'fa-moon'; ?>"></i>
                        </button>

                        <div class="dropdown me-3">
                            <button class="lang-selector-btn dropdown-toggle" type="button" data-bs-toggle="dropdown">
                                <i class="fas fa-globe"></i> <?php echo \App\Services\LanguageService::getLang() == 'id' ? 'ID' : 'EN'; ?>
                            </button>
                            <ul class="dropdown-menu dropdown-menu-end shadow border-0">
                                <li><a class="dropdown-item" href="/lang/id">🇮🇩 Indonesia</a></li>
                                <li><a class="dropdown-item" href="/lang/en">🇺🇸 English</a></li>
                            </ul>
                        </div>
                    </div>

                    <!-- Mobile Specific Controls -->
                    <div class="d-lg-none">
                        <div class="mobile-theme-row mb-2">
                            <span class="theme-status-text small fw-bold"><?php echo $currentTheme === 'dark' ? 'Dark Mode' : 'Light Mode'; ?></span>
                            <button id="theme-toggle-mobile" class="theme-toggle-btn" aria-label="Toggle theme">
                                <i class="fa-solid <?php echo $currentTheme === 'dark' ? 'fa-sun' : 'fa-moon'; ?>"></i>
                            </button>
                        </div>
                        <div class="dropdown mb-3">
                            <button class="lang-selector-btn w-100 justify-content-between dropdown-toggle" type="button" data-bs-toggle="dropdown">
                                <span><i class="fas fa-globe me-2"></i>Language</span>
                                <span><?php echo \App\Services\LanguageService::getLang() == 'id' ? 'ID' : 'EN'; ?></span>
                            </button>
                            <ul class="dropdown-menu shadow border-0 w-100">
                                <li><a class="dropdown-item" href="/lang/id">🇮🇩 Indonesia</a></li>
                                <li><a class="dropdown-item" href="/lang/en">🇺🇸 English</a></li>
                            </ul>
                        </div>
                    </div>

                    <div class="d-flex align-items-center justify-content-between">
                        <div class="d-flex align-items-center">
                            <span class="text-muted me-3"><b><?php echo $_SESSION['username'] ?? 'Admin'; ?></b></span>
                            <a href="/" class="btn btn-outline-secondary btn-sm me-2" target="_blank" title="View Site"><i class="fas fa-external-link-alt"></i></a>
                        </div>
                        <a href="/admin/logout" class="btn btn-danger btn-sm px-3"><i class="fas fa-sign-out-alt me-1"></i> Logout</a>
                    </div>
                </div>
            </div>
        </div>
    </nav>
    <main class="min-vh-100">
