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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>STRACONX - Module Documentation Portal</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/tabler-icons.min.css">
    <link
        href="https://fonts.googleapis.com/css2?family=Outfit:wght@400;600;700;800&family=Inter:wght@300;400;500;600&display=swap"
        rel="stylesheet">
    <style>
        :root {
            --strx-navy: #002B49;
            --strx-celeste: #3AB5E5;
            --strx-bg: #F8FAFC;
            --strx-white: #ffffff;
            --strx-text: #1e293b;
            --border: #e2e8f0;
        }

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

        body {
            font-family: 'Inter', sans-serif;
            background: var(--strx-bg);
            color: var(--strx-text);
        }

        h1,
        h2,
        h3 {
            font-family: 'Outfit', sans-serif;
            color: var(--strx-navy);
        }

        header {
            background: var(--strx-navy);
            padding: 50px 20px;
            color: white;
            text-align: center;
        }

        .search-container {
            max-width: 800px;
            margin: 25px auto -60px;
            position: relative;
            z-index: 10;
        }

        .search-bar {
            width: 100%;
            padding: 22px 65px;
            font-size: 1.15rem;
            border: none;
            box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
            border-radius: 0px;
            outline: none;
            border-bottom: 4px solid var(--strx-celeste);
        }

        .search-container i {
            position: absolute;
            left: 25px;
            top: 50%;
            transform: translateY(-50%);
            color: var(--strx-navy);
            font-size: 1.6rem;
        }

        .container {
            max-width: 1400px;
            margin: 90px auto 40px;
            display: grid;
            grid-template-columns: 320px 1fr;
            gap: 40px;
            padding: 0 20px;
        }

        .sidebar {
            background: white;
            padding: 30px;
            border: 1px solid var(--border);
            height: fit-content;
            position: sticky;
            top: 40px;
        }

        .sidebar h3 {
            font-size: 0.9rem;
            text-transform: uppercase;
            letter-spacing: 1.5px;
            margin-bottom: 25px;
            color: var(--strx-celeste);
            border-bottom: 1px solid var(--border);
            padding-bottom: 10px;
        }

        .category-list {
            list-style: none;
        }

        .category-item {
            padding: 12px 10px;
            border-bottom: 1px solid #f1f5f9;
            cursor: pointer;
            transition: all 0.2s;
            font-size: 0.9rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .category-item:hover {
            background: var(--strx-bg);
            color: var(--strx-celeste);
            border-left: 4px solid var(--strx-celeste);
        }

        .category-item span {
            background: var(--strx-navy);
            color: white;
            padding: 2px 8px;
            font-size: 0.75rem;
            font-weight: 700;
        }

        .module-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
            gap: 25px;
        }

        .module-card {
            background: white;
            border: 1px solid var(--border);
            padding: 30px;
            transition: all 0.3s ease;
            cursor: pointer;
            display: flex;
            flex-direction: column;
            text-decoration: none;
            color: inherit;
        }

        .module-card:hover {
            transform: translateY(-8px);
            border-color: var(--strx-celeste);
            box-shadow: 0 15px 30px rgba(0, 43, 73, 0.1);
        }

        .module-card h4 {
            font-size: 1.25rem;
            margin-bottom: 12px;
            line-height: 1.2;
        }

        .module-card p {
            font-size: 0.9rem;
            color: #64748b;
            margin-bottom: 20px;
            flex-grow: 1;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }

        .module-meta {
            display: flex;
            justify-content: space-between;
            align-items: center;
            font-size: 0.8rem;
            padding-top: 18px;
            border-top: 1px solid #f1f5f9;
        }

        .version-tag {
            background: var(--strx-navy);
            color: white;
            padding: 3px 10px;
            font-weight: 700;
            letter-spacing: 0.5px;
        }

        .category-pill {
            color: var(--strx-celeste);
            font-weight: 800;
            text-transform: uppercase;
            font-size: 0.75rem;
            margin-bottom: 8px;
            display: block;
        }

        .logo-main {
            height: 50px;
            margin-bottom: 15px;
        }
    </style>
</head>

<body>

    <header>
        <img src="https://initium.cloud/logo.svg" class="logo-main" alt="STRACONX">
        <h1>Module Documentation Portal</h1>
        <p style="opacity: 0.8; font-size: 1.1rem; margin-top: 5px;">Comprehensive Technical Directory for {{
            modules|length }} Modules</p>

        <div class="search-container">
            <i class="ti ti-search"></i>
            <input type="text" id="searchInput" class="search-bar"
                placeholder="Search by name, technical ID, summary or author..." onkeyup="filterModules()">
        </div>
    </header>

    <div class="container">
        <!-- SIDEBAR: Categorías reales de la DB -->
        <aside class="sidebar">
            <h3>Categories</h3>
            <ul class="category-list">
                <li class="category-item" onclick="filterByCategory('all')">All Modules <span>{{ modules|length
                        }}</span></li>
                {% for cat, count in categories %}
                <li class="category-item" onclick="filterByCategory('{{ cat }}')">{{ cat|replace('strx_',
                    '')|replace('_', ' ')|title }} <span>{{ count }}</span></li>
                {% endfor %}
            </ul>
        </aside>

        <!-- MAIN GRID: Módulos reales -->
        <main class="module-grid" id="moduleGrid">
            {% for mod in modules %}
            <a href="{{ mod.url }}" class="module-card" data-category="{{ mod.category }}"
                data-search="{{ mod.display_name.lower() }} {{ mod.technical_name.lower() }} {{ mod.summary.lower() }} {{ mod.author.lower() }}">
                <div>
                    <span class="category-pill">{{ mod.category }}</span>
                    <h4>{{ mod.display_name }}</h4>
                    <p>{{ mod.summary }}</p>
                </div>
                <div class="module-meta">
                    <span class="version-tag">{{ mod.version }}</span>
                    <span style="color: var(--strx-navy); font-weight: 700;">{{ mod.author }}</span>
                </div>
            </a>
            {% endfor %}
        </main>
    </div>

    <script>
        function filterModules() {
            let input = document.getElementById('searchInput').value.toLowerCase();
            let cards = document.getElementsByClassName('module-card');

            for (let card of cards) {
                let text = card.getAttribute('data-search');
                card.style.display = text.includes(input) ? "flex" : "none";
            }
        }

        function filterByCategory(cat) {
            let cards = document.getElementsByClassName('module-card');
            for (let card of cards) {
                if (cat === 'all') {
                    card.style.display = "flex";
                } else {
                    card.style.display = card.getAttribute('data-category') === cat ? "flex" : "none";
                }
            }
            // Clear search when filtering by category
            document.getElementById('searchInput').value = "";
        }
    </script>
</body>

</html>