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

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ module.name }} - STRACONX Technical Documentation</title>
    <!-- Tabler Icons -->
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@tabler/icons-webfont@latest/tabler-icons.min.css">
    <!-- Google Fonts -->
    <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">
    <!-- Pygments for Code Highlighting -->
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pygments/2.15.1/pygments.min.css">
    <style>
        :root {
            --strx-navy: #002B49;
            --strx-navy-light: #004e80;
            --strx-gold: #d4af37;
            --strx-gold-muted: rgba(212, 175, 55, 0.1);
            --strx-bg: #F8FAFC;
            --strx-white: #ffffff;
            --strx-text: #1e293b;
            --border: #e2e8f0;
            --radius: 0px;
            /* SHARP BORDERS as requested */
        }

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

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

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

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 40px 20px;
        }

        /* --- NAVIGATION --- */
        .doc-navigation {
            display: flex;
            background: var(--strx-bg);
            padding: 5px;
            margin-bottom: 40px;
            border: 1px solid var(--border);
            overflow-x: auto;
            gap: 2px;
            position: sticky;
            top: 0;
            z-index: 1000;
        }

        .nav-tab {
            flex: 1;
            padding: 14px;
            border: none;
            background: transparent;
            color: var(--strx-navy);
            font-family: 'Outfit', sans-serif;
            font-weight: 600;
            cursor: pointer;
            transition: all 0.2s;
            display: flex;
            align-items: center;
            justify-content: center;
            gap: 8px;
            white-space: nowrap;
        }

        .nav-tab.active {
            background: var(--strx-navy);
            color: white;
        }

        .nav-tab:hover:not(.active) {
            background: var(--strx-gold-muted);
        }

        /* --- CONTENT --- */
        .tab-panel {
            display: none;
        }

        .tab-panel.active {
            display: block;
            animation: fadeIn 0.3s;
        }

        @keyframes fadeIn {
            from {
                opacity: 0;
            }

            to {
                opacity: 1;
            }
        }

        .content-card {
            border: 1px solid var(--border);
            padding: 40px;
            margin-bottom: 30px;
            background: white;
            position: relative;
        }

        /* --- BADGES --- */
        .badge-group {
            display: flex;
            gap: 10px;
            margin-top: 15px;
        }

        .badge {
            padding: 4px 12px;
            background: var(--strx-gold-muted);
            color: var(--strx-navy);
            font-size: 0.75rem;
            font-weight: 700;
            border: 1px solid var(--strx-gold);
        }

        /* --- CODE BROWSER & TOC --- */
        .code-block {
            background: #0f172a;
            color: #f8fafc;
            padding: 20px;
            overflow-x: auto;
            margin-bottom: 20px;
            white-space: pre;
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 0.9rem;
            line-height: 1.4;
        }

        .mermaid {
            margin: 20px 0;
            text-align: center;
        }

        /* --- MARKDOWN --- */
        .markdown h2 {
            margin: 30px 0 15px;
            border-left: 5px solid var(--strx-gold);
            padding-left: 15px;
        }

        .markdown p {
            margin-bottom: 15px;
        }

        .markdown ul {
            margin-left: 30px;
            margin-bottom: 20px;
        }

        /* --- FOOTER --- */
        footer {
            background: var(--strx-navy);
            color: white;
            padding: 40px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-top: 60px;
        }

        .footer-logo {
            height: 45px;
        }

        /* --- RESPONSIVE --- */
        @media (max-width: 900px) {
            .doc-navigation {
                flex-wrap: wrap;
            }

            .nav-tab {
                width: calc(50% - 2px);
                flex: none;
            }

            footer {
                flex-direction: column;
                text-align: center;
                gap: 20px;
            }
        }
    </style>
</head>

<body>

    <header class="container">
        <div style="display: flex; justify-content: space-between; align-items: flex-start;">
            <div>
                <h1>{{ module.name }}</h1>
                <p style="color: var(--strx-navy-light); font-size: 1.1rem;">{{ module.summary }}</p>
                <div class="badge-group">
                    <span class="badge">Version: {{ module.version }}</span>
                    <span class="badge">License: OPL-1</span>
                    <span class="badge">Author: {{ module.author }}</span>
                    {% if module.test_status %}
                    <span class="badge" style="background: #dcfce7; color: #166534; border-color: #22c55e;">Tests:
                        PASSING</span>
                    {% endif %}
                </div>
            </div>
            {% if module.icon_path %}
            <img src="{{ module.icon_path }}" style="width: 80px; height: 80px;" alt="Icon">
            {% endif %}
        </div>
    </header>

    <div class="container">
        <nav class="doc-navigation">
            <button class="nav-tab active" onclick="showPanel(this, 'readme')"><i class="ti ti-info-circle"></i>
                Readme</button>
            <button class="nav-tab" onclick="showPanel(this, 'views')"><i class="ti ti-layout"></i> Views & UI</button>
            <button class="nav-tab" onclick="showPanel(this, 'models')"><i class="ti ti-database"></i> Models &
                Logic</button>
            <button class="nav-tab" onclick="showPanel(this, 'graph')"><i class="ti ti-hierarchy-2"></i>
                Dependencies</button>
            <button class="nav-tab" onclick="showPanel(this, 'config')"><i class="ti ti-settings"></i> Setup</button>
            <button class="nav-tab" onclick="showPanel(this, 'changelog')"><i class="ti ti-history"></i>
                History</button>
        </nav>

        <!-- README PANEL -->
        <div id="readme" class="tab-panel active">
            <div class="content-card markdown">
                {{ content.readme }}
                {% if module.screenshots %}
                <h3 style="margin-top: 30px;">Screenshots</h3>
                <div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 15px;">
                    {% for img in module.screenshots %}
                    <div style="border: 4px solid var(--strx-navy);">
                        <img src="{{ img }}" style="width: 100%; display: block;">
                    </div>
                    {% endfor %}
                </div>
                {% endif %}
            </div>
        </div>

        <!-- VIEWS PANEL -->
        <div id="views" class="tab-panel">
            <div class="content-card">
                <div style="display: flex; align-items: center; gap: 15px; margin-bottom: 25px;">
                    <i class="ti ti-layout" style="font-size: 2rem; color: var(--strx-gold);"></i>
                    <h2>Visual Elements (XML)</h2>
                </div>
                {% for view in content.views %}
                <div style="margin-bottom: 30px;">
                    <h4 style="margin-bottom: 10px; color: var(--strx-navy-light);">{{ view.filename }}</h4>
                    <pre class="code-block">{{ view.content }}</pre>
                </div>
                {% endfor %}
            </div>
        </div>

        <!-- MODELS PANEL -->
        <div id="models" class="tab-panel">
            <div class="content-card">
                <div style="display: flex; align-items: center; gap: 15px; margin-bottom: 25px;">
                    <i class="ti ti-database" style="font-size: 2rem; color: var(--strx-gold);"></i>
                    <h2>Business Logic & Models</h2>
                </div>
                {% for model in content.models %}
                <div style="margin-bottom: 40px; border-bottom: 1px solid var(--border); padding-bottom: 20px;">
                    <h3 style="color: var(--strx-navy);">{{ model.name }}</h3>
                    <p style="color: var(--strx-text-light); font-style: italic; margin-bottom: 15px;">{{
                        model.docstring }}</p>
                    <pre class="code-block">{{ model.code }}</pre>
                </div>
                {% endfor %}
            </div>
        </div>

        <!-- DEPENDENCY GRAPH -->
        <div id="graph" class="tab-panel">
            <div class="content-card">
                <div style="display: flex; align-items: center; gap: 15px; margin-bottom: 25px;">
                    <i class="ti ti-hierarchy-2" style="font-size: 2rem; color: var(--strx-gold);"></i>
                    <h2>Module Dependencies</h2>
                </div>
                <div class="mermaid">
                    graph TD
                    This[{{ module.technical_name }}]
                    {% for dep in module.dependencies %}
                    This --> {{ dep }}
                    {% endfor %}
                </div>
            </div>
        </div>

        <!-- CONFIG & SETUP -->
        <div id="config" class="tab-panel">
            <div class="content-card markdown">
                {{ content.config }}
                {{ content.usage }}
                {{ content.tests }}
            </div>
        </div>

        <!-- CHANGELOG -->
        <div id="changelog" class="tab-panel">
            <div class="content-card markdown">
                {{ content.changelog }}
            </div>
        </div>
    </div>

    <footer>
        <div class="license-info">
            <h3 style="margin-bottom: 5px;">Property of {{ module.author }}</h3>
            <p style="opacity: 0.7; font-size: 0.85rem;">Licensed under ODOO PROPRIETARY LICENSE v1.0 (OPL-1)</p>
        </div>
        <img src="https://initium.cloud/logo.svg" class="footer-logo" alt="STRACONX"
            onerror="this.src='https://initium.cloud/logo.svg'">
    </footer>

    <script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
    <script>
        mermaid.initialize({ startOnLoad: true, theme: 'neutral' });
        function showPanel(btn, id) {
            document.querySelectorAll('.nav-tab').forEach(b => b.classList.remove('active'));
            btn.classList.add('active');
            document.querySelectorAll('.tab-panel').forEach(p => p.classList.remove('active'));
            document.getElementById(id).classList.add('active');
        }
    </script>
</body>

</html>