<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    <style>
        :root {
            --primary-color: {{ theme.primary_color|default('#4CAF50') }};
            --secondary-color: {{ theme.secondary_color|default('#8b5d3b') }};
            --background-color: {{ theme.background_color|default('#f5f5f5') }};
            --text-color: {{ theme.text_color|default('#331201') }};
        }

        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
            line-height: 1.6;
            color: var(--text-color);
            background-color: var(--background-color);
            margin: 0;
            padding: 0;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
            padding: 2rem;
        }

        .header {
            background-color: var(--primary-color);
            color: white;
            padding: 2rem;
            margin-bottom: 2rem;
        }

        .header h1 {
            margin: 0;
            font-size: 2.5rem;
        }

        .header p {
            margin: 0.5rem 0 0;
            opacity: 0.9;
        }

        .section {
            background: white;
            border-radius: 8px;
            padding: 2rem;
            margin-bottom: 2rem;
            box-shadow: 0 2px 4px rgba(0,0,0,0.1);
        }

        .section h2 {
            color: var(--primary-color);
            margin-top: 0;
            border-bottom: 2px solid var(--primary-color);
            padding-bottom: 0.5rem;
        }

        .endpoint {
            background: #f8f9fa;
            border-left: 4px solid var(--primary-color);
            padding: 1rem;
            margin: 1rem 0;
        }

        .endpoint-header {
            display: flex;
            align-items: center;
            gap: 1rem;
            margin-bottom: 1rem;
        }

        .method {
            background: var(--primary-color);
            color: white;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            font-weight: bold;
        }

        .path {
            font-family: monospace;
            font-size: 1.1rem;
        }

        .parameters {
            margin: 1rem 0;
        }

        .parameter {
            display: grid;
            grid-template-columns: 1fr 1fr 2fr;
            gap: 1rem;
            padding: 0.5rem;
            border-bottom: 1px solid #eee;
        }

        .parameter:last-child {
            border-bottom: none;
        }

        .type-definition {
            background: #f8f9fa;
            padding: 1rem;
            margin: 1rem 0;
            border-radius: 4px;
        }

        .property {
            margin: 0.5rem 0;
            padding: 0.5rem;
            background: white;
            border-radius: 4px;
        }

        code {
            background: #272822;
            color: #f8f8f2;
            padding: 1rem;
            border-radius: 4px;
            display: block;
            overflow-x: auto;
            margin: 1rem 0;
        }

        .status {
            font-size: 0.9rem;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            margin-left: 1rem;
        }

        .status.production {
            background: #28a745;
            color: white;
        }

        .status.review {
            background: #ffc107;
            color: black;
        }

        .status.planned {
            background: #6c757d;
            color: white;
        }

        .tag {
            background: var(--secondary-color);
            color: white;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            font-size: 0.9rem;
        }

        .version {
            font-size: 0.9rem;
            color: #6c757d;
        }
    </style>
</head>
<body>
    <div class="header">
        <div class="container">
            <h1>{{ title }}</h1>
            <p>{{ description }}</p>
            <span class="version">v{{ version }}</span>
        </div>
    </div>

    <div class="container">
        {% if api_docs %}
        <div class="section">
            <h2>API Documentation</h2>
            {% for doc in api_docs %}
            <div class="endpoint">
                <div class="endpoint-header">
                    <span class="method">{{ doc.method }}</span>
                    <span class="path">{{ doc.endpoint }}</span>
                    <span class="status {{ doc.status|lower }}">{{ doc.status }}</span>
                    <span class="tag">{{ doc.tag }}</span>
                </div>
                <p>{{ doc.description }}</p>
                
                {% if doc.parameters %}
                <div class="parameters">
                    <h4>Parameters</h4>
                    {% for name, param in doc.parameters.items() %}
                    <div class="parameter">
                        <span>{{ name }}</span>
                        <span>{{ param.type|format_type }}</span>
                        <span>{{ param.description }}</span>
                    </div>
                    {% endfor %}
                </div>
                {% endif %}

                {% if doc.responses %}
                <div class="responses">
                    <h4>Responses</h4>
                    {% for status, response in doc.responses.items() %}
                    <div class="response">
                        <strong>{{ status }}</strong>
                        {% if response.description %}
                        <p>{{ response.description }}</p>
                        {% endif %}
                        {% if response.example %}
                        <code>{{ response.example }}</code>
                        {% endif %}
                    </div>
                    {% endfor %}
                </div>
                {% endif %}

                {% if doc.source %}
                <details>
                    <summary>Source Code</summary>
                    <code>{{ doc.source|format_code }}</code>
                </details>
                {% endif %}
            </div>
            {% endfor %}
        </div>
        {% endif %}

        {% if type_docs %}
        <div class="section">
            <h2>Type Definitions</h2>
            {% for doc in type_docs %}
            <div class="type-definition">
                <h3>{{ doc.name }}</h3>
                <p>{{ doc.description }}</p>

                {% if doc.properties %}
                <h4>Properties</h4>
                {% for name, prop in doc.properties.items() %}
                <div class="property">
                    <strong>{{ name }}</strong>: {{ prop.type|format_type }}
                    {% if prop.description %}
                    <p>{{ prop.description }}</p>
                    {% endif %}
                </div>
                {% endfor %}
                {% endif %}

                {% if doc.methods %}
                <h4>Methods</h4>
                {% for name, method in doc.methods.items() %}
                <div class="method-definition">
                    <code>{{ name }}{{ method.signature }}</code>
                    {% if method.doc %}
                    <p>{{ method.doc }}</p>
                    {% endif %}
                </div>
                {% endfor %}
                {% endif %}
            </div>
            {% endfor %}
        </div>
        {% endif %}

        {% if general_docs %}
        <div class="section">
            <h2>General Documentation</h2>
            {% for doc in general_docs %}
            <div class="doc-section">
                <h3>{{ doc.title }}</h3>
                {{ doc.content }}
                
                {% for section_title, section_content in doc.sections.items() %}
                <h4>{{ section_title }}</h4>
                {{ section_content }}
                {% endfor %}
            </div>
            {% endfor %}
        </div>
        {% endif %}
    </div>
</body>
</html>
