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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}Dashboard - {{ request.app.title }}{% endblock %}</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <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=Outfit:wght@300;400;600;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary-bg: #030712;
            --card-bg: rgba(17, 24, 39, 0.7);
            --border-color: rgba(255, 255, 255, 0.08);
            --accent-color: #38bdf8;
            --text-main: #f8fafc;
            --text-muted: #94a3b8;
            --danger: #ef4444;
            --success: #22c55e;
            --warning: #f59e0b;
        }

        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            background-color: var(--primary-bg);
            color: var(--text-main);
            font-family: 'Outfit', sans-serif;
            line-height: 1.5;
            min-height: 100vh;
            display: flex;
            flex-direction: column;
        }

        /* Layout */
        .container {
            width: 100%;
            max-width: 1200px;
            margin: 0 auto;
            padding: 0 1.5rem;
        }

        /* Navbar */
        .navbar {
            background: rgba(3, 7, 18, 0.8);
            backdrop-filter: blur(12px);
            border-bottom: 1px solid var(--border-color);
            position: sticky;
            top: 0;
            z-index: 100;
        }

        .nav-content {
            height: 70px;
            display: flex;
            align-items: center;
            justify-content: space-between;
        }

        .brand {
            font-size: 1.25rem;
            font-weight: 700;
            color: var(--text-main);
            text-decoration: none;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .user-info {
            display: flex;
            align-items: center;
            gap: 1.5rem;
        }

        .email-display {
            color: var(--text-muted);
            font-size: 0.875rem;
        }

        /* Components */
        .glass-card {
            background: var(--card-bg);
            backdrop-filter: blur(12px);
            border: 1px solid var(--border-color);
            border-radius: 1.25rem;
            box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        }

        .btn {
            display: inline-flex;
            align-items: center;
            gap: 0.5rem;
            padding: 0.625rem 1.25rem;
            border-radius: 0.75rem;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
            border: 1px solid transparent;
            font-size: 0.875rem;
            text-decoration: none;
        }

        .btn-primary {
            background: var(--accent-color);
            color: var(--primary-bg);
        }

        .btn-primary:hover {
            opacity: 0.9;
            transform: translateY(-1px);
        }

        .btn-outline {
            background: transparent;
            border-color: var(--border-color);
            color: var(--text-main);
        }

        .btn-outline:hover {
            border-color: var(--accent-color);
            color: var(--accent-color);
            background: rgba(56, 189, 248, 0.05);
        }

        .btn-danger-outline {
            background: transparent;
            border-color: rgba(239, 68, 68, 0.2);
            color: var(--danger);
        }

        .btn-danger-outline:hover {
            background: rgba(239, 68, 68, 0.1);
            border-color: var(--danger);
        }

        .badge {
            display: inline-flex;
            padding: 0.25rem 0.625rem;
            border-radius: 9999px;
            font-size: 0.75rem;
            font-weight: 600;
            border: 1px solid transparent;
        }

        .badge-success {
            background: rgba(34, 197, 94, 0.1);
            color: var(--success);
            border-color: rgba(34, 197, 94, 0.2);
        }

        .badge-danger {
            background: rgba(239, 68, 68, 0.1);
            color: var(--danger);
            border-color: rgba(239, 68, 68, 0.2);
        }

        .badge-muted {
            background: rgba(148, 163, 184, 0.1);
            color: var(--text-muted);
            border-color: rgba(148, 163, 184, 0.2);
        }

        /* Utils */
        .flex {
            display: flex;
        }

        .flex-col {
            flex-direction: column;
        }

        .items-center {
            align-items: center;
        }

        .justify-center {
            justify-content: center;
        }

        .justify-between {
            justify-content: space-between;
        }

        .gap-2 {
            gap: 0.5rem;
        }

        .gap-4 {
            gap: 1rem;
        }

        .gap-6 {
            gap: 1.5rem;
        }

        .gap-8 {
            gap: 2rem;
        }

        .mb-2 {
            margin-bottom: 0.5rem;
        }

        .mb-4 {
            margin-bottom: 1rem;
        }

        .mb-6 {
            margin-bottom: 1.5rem;
        }

        .mb-8 {
            margin-bottom: 2rem;
        }

        .mb-10 {
            margin-bottom: 2.5rem;
        }

        .mt-8 {
            margin-top: 2rem;
        }

        .mt-10 {
            margin-top: 2.5rem;
        }

        .p-6 {
            padding: 1.5rem;
        }

        .p-8 {
            padding: 2rem;
        }

        .p-10 {
            padding: 2.5rem;
        }

        .py-3 {
            padding-top: 0.75rem;
            padding-bottom: 0.75rem;
        }

        .py-4 {
            padding-top: 1rem;
            padding-bottom: 1rem;
        }

        .py-8 {
            padding-top: 2rem;
            padding-bottom: 2rem;
        }

        .w-full {
            width: 100%;
        }

        .max-w-md {
            max-width: 28rem;
        }

        .text-center {
            text-align: center;
        }

        .text-accent {
            color: var(--accent-color);
        }

        .text-muted {
            color: var(--text-muted);
        }

        .text-danger {
            color: var(--danger);
        }

        .text-sm {
            font-size: 0.875rem;
        }

        .text-lg {
            font-size: 1.125rem;
        }

        .text-xl {
            font-size: 1.25rem;
        }

        .text-2xl {
            font-size: 1.5rem;
        }

        .text-3xl {
            font-size: 1.875rem;
        }

        .font-bold {
            font-weight: 700;
        }

        .uppercase {
            text-transform: uppercase;
        }

        .tracking-widest {
            letter-spacing: 0.1em;
        }

        .opacity-50 {
            opacity: 0.5;
        }

        .opacity-80 {
            opacity: 0.8;
        }

        .border-top {
            border-top: 1px solid var(--border-color);
        }

        .border-secondary {
            border-color: var(--border-color);
        }

        /* Forms */
        .form-group {
            display: flex;
            flex-direction: column;
            gap: 0.625rem;
            margin-bottom: 1.5rem;
        }

        .form-label {
            font-size: 0.875rem;
            font-weight: 600;
            color: var(--text-muted);
            margin-bottom: 0.25rem;
        }

        .form-control {
            background: rgba(255, 255, 255, 0.02);
            border: 1px solid rgba(255, 255, 255, 0.1);
            border-radius: 1rem;
            padding: 0.875rem 1.25rem;
            color: var(--text-main);
            outline: none;
            transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
            font-family: inherit;
            font-size: 0.9375rem;
            width: 100%;
            backdrop-filter: blur(4px);
            box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .form-control:hover {
            background: rgba(255, 255, 255, 0.04);
            border-color: rgba(255, 255, 255, 0.2);
            transform: translateY(-1px);
        }

        .form-control:focus {
            background: rgba(255, 255, 255, 0.08);
            border-color: var(--accent-color);
            box-shadow: 0 0 0 4px rgba(56, 189, 248, 0.15),
                inset 0 2px 4px rgba(0, 0, 0, 0.1),
                0 4px 6px -1px rgba(0, 0, 0, 0.1);
            transform: translateY(-1px);
        }

        .form-control::placeholder {
            color: rgba(148, 163, 184, 0.4);
            font-weight: 300;
        }

        /* Custom Checkbox */
        .checkbox-group {
            display: flex;
            align-items: center;
            gap: 0.75rem;
            cursor: pointer;
            padding: 0.5rem 0;
        }

        .checkbox-group input {
            width: 1.25rem;
            height: 1.25rem;
            accent-color: var(--accent-color);
            cursor: pointer;
        }

        /* Custom Styles from RBAC configuration */
            {
                {
                custom_css | safe if custom_css else ''
            }
        }

        .nav-link {
            color: var(--text-muted);
            text-decoration: none;
            font-size: 0.875rem;
            font-weight: 600;
            transition: all 0.2s;
            padding: 0.5rem 0.75rem;
            border-radius: 0.5rem;
        }

        .nav-link:hover {
            color: var(--text-main);
            background: rgba(255, 255, 255, 0.05);
        }

        .nav-link.active {
            color: var(--accent-color);
            background: rgba(56, 189, 248, 0.1);
        }

        .ml-8 {
            margin-left: 2rem;
        }
    </style>
</head>

<body>
    <header class="navbar">
        <div class="container nav-content">
            <div class="flex items-center gap-6">
                <a class="brand" href="{{ url_for('dashboard_index') }}">
                    <i class="fas fa-shield-halved text-accent"></i>
                    <span>{{ request.app.title }}</span>
                </a>
                <nav class="flex gap-4 ml-8">
                    <a href="{{ url_for('dashboard_index') }}"
                        class="nav-link {% if request.url.path == url_for('dashboard_index') %}active{% endif %}">
                        Users
                    </a>
                    {% if 'roles:manage' in user_perms %}
                    <a href="{{ url_for('roles_index') }}"
                        class="nav-link {% if request.url.path == url_for('roles_index') %}active{% endif %}">
                        Roles
                    </a>
                    {% endif %}
                    {% if 'dashboard.audit:read' in user_perms %}
                    <a href="{{ url_for('audit_dashboard') }}"
                        class="nav-link {% if request.url.path == url_for('audit_dashboard') %}active{% endif %}">
                        Audit
                    </a>
                    {% endif %}
                </nav>
            </div>
            {% if user_email %}
            <div class="user-info">
                <span class="email-display text-sm">{{ user_email }}</span>
                <button onclick="logout()" class="btn btn-danger-outline">Logout</button>
            </div>
            {% endif %}
        </div>
    </header>

    <main class="container py-8" style="padding-top: 3rem; padding-bottom: 3rem; flex: 1;">
        {% block content %}{% endblock %}
    </main>

    <script>
        function toggleModal(id) {
            const modal = document.getElementById(id);
            if (modal) {
                modal.classList.toggle('show');

                // Disable background scroll when any modal is open
                const anyModalShown = document.querySelectorAll('.modal-backdrop.show').length > 0;
                if (anyModalShown) {
                    document.body.style.overflow = 'hidden';
                } else {
                    document.body.style.overflow = '';
                }
            }
        }

        function logout() {
            document.cookie = "access_token=; path=/; expires=Thu, 01 Jan 1970 00:00:00 UTC;";
            localStorage.removeItem('access_token');
            window.location.href = "{{ url_for('dashboard_index') }}";
        }
    </script>
    {% block extra_js %}{% endblock %}
</body>

</html>