<!DOCTYPE html>
<html lang="en" data-theme="{{ theme }}">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}{{ title }}{% endblock %}</title>
    <style>
        :root {
            --bg-primary: #f8fafc;
            --bg-secondary: #ffffff;
            --bg-tertiary: #f1f5f9;
            --text-primary: #1e293b;
            --text-secondary: #64748b;
            --border-color: #e2e8f0;
            --accent-color: #0ea5e9;
            --accent-hover: #0284c7;
            --success-color: #10b981;
            --error-color: #ef4444;
            --shadow: 0 1px 3px rgba(0,0,0,0.1);
        }

        [data-theme="dark"] {
            --bg-primary: #0f172a;
            --bg-secondary: #1e293b;
            --bg-tertiary: #334155;
            --text-primary: #f1f5f9;
            --text-secondary: #94a3b8;
            --border-color: #475569;
            --shadow: 0 1px 3px rgba(0,0,0,0.3);
        }

        @media (prefers-color-scheme: dark) {
            [data-theme="auto"] {
                --bg-primary: #0f172a;
                --bg-secondary: #1e293b;
                --bg-tertiary: #334155;
                --text-primary: #f1f5f9;
                --text-secondary: #94a3b8;
                --border-color: #475569;
                --shadow: 0 1px 3px rgba(0,0,0,0.3);
            }
        }

        * { box-sizing: border-box; }

        body {
            font-family: system-ui, -apple-system, sans-serif;
            background: var(--bg-primary);
            color: var(--text-primary);
            margin: 0;
            padding: 0;
            min-height: 100vh;
        }

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

        header {
            background: var(--bg-secondary);
            border-bottom: 1px solid var(--border-color);
            padding: 1rem 0;
            margin-bottom: 1.5rem;
        }

        header .container {
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-top: 0;
            padding-bottom: 0;
        }

        .logo {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--accent-color);
            text-decoration: none;
        }

        nav {
            display: flex;
            gap: 1rem;
        }

        nav a {
            color: var(--text-secondary);
            text-decoration: none;
            padding: 0.5rem 1rem;
            border-radius: 6px;
            transition: all 0.2s;
        }

        nav a:hover, nav a.active {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

        .card {
            background: var(--bg-secondary);
            border: 1px solid var(--border-color);
            border-radius: 8px;
            padding: 1.5rem;
            margin-bottom: 1rem;
            box-shadow: var(--shadow);
        }

        .card h2 {
            margin-top: 0;
            color: var(--text-primary);
        }

        .btn {
            display: inline-block;
            padding: 0.5rem 1rem;
            background: var(--accent-color);
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            text-decoration: none;
            font-weight: 500;
            transition: background 0.2s;
        }

        .btn:hover {
            background: var(--accent-hover);
        }

        .btn-secondary {
            background: var(--bg-tertiary);
            color: var(--text-primary);
        }

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

        input, select, textarea {
            width: 100%;
            padding: 0.75rem;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            background: var(--bg-primary);
            color: var(--text-primary);
            font-size: 1rem;
        }

        input:focus, select:focus, textarea:focus {
            outline: none;
            border-color: var(--accent-color);
        }

        label {
            display: block;
            margin-bottom: 0.5rem;
            color: var(--text-secondary);
            font-weight: 500;
        }

        .form-group {
            margin-bottom: 1rem;
        }

        table {
            width: 100%;
            border-collapse: collapse;
        }

        th, td {
            padding: 0.75rem;
            text-align: left;
            border-bottom: 1px solid var(--border-color);
        }

        th {
            background: var(--bg-tertiary);
            font-weight: 600;
        }

        tr:hover {
            background: var(--bg-tertiary);
        }

        .pagination {
            display: flex;
            gap: 0.5rem;
            justify-content: center;
            margin-top: 1rem;
        }

        .pagination a, .pagination span {
            padding: 0.5rem 0.75rem;
            border: 1px solid var(--border-color);
            border-radius: 4px;
            text-decoration: none;
            color: var(--text-primary);
        }

        .pagination a:hover {
            background: var(--bg-tertiary);
        }

        .pagination .current {
            background: var(--accent-color);
            color: white;
            border-color: var(--accent-color);
        }

        .error {
            background: #fef2f2;
            border: 1px solid var(--error-color);
            color: var(--error-color);
            padding: 1rem;
            border-radius: 6px;
            margin-bottom: 1rem;
        }

        .success {
            background: #ecfdf5;
            border: 1px solid var(--success-color);
            color: var(--success-color);
            padding: 1rem;
            border-radius: 6px;
            margin-bottom: 1rem;
        }

        code {
            background: var(--bg-tertiary);
            padding: 0.2rem 0.4rem;
            border-radius: 3px;
            font-family: monospace;
            font-size: 0.9em;
        }

        pre {
            background: var(--bg-tertiary);
            padding: 1rem;
            border-radius: 6px;
            overflow-x: auto;
            font-family: monospace;
        }

        .grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 1rem;
        }

        footer {
            margin-top: 3rem;
            padding: 1rem 0;
            border-top: 1px solid var(--border-color);
            color: var(--text-secondary);
            text-align: center;
            font-size: 0.9rem;
        }

        footer a {
            color: var(--accent-color);
        }
    </style>
    {% block extra_css %}{% endblock %}
</head>
<body>
    <header>
        <div class="container">
            <a href="{{ webui_url('index') }}" class="logo">{{ title }}</a>
            <nav>
                <a href="{{ webui_url('index') }}" {% if current_page == 'index' %}class="active"{% endif %}>Dashboard</a>
                {% if enable_entity_browser %}
                <a href="{{ webui_url('entities') }}" {% if current_page == 'entities' or current_page == 'entity_list' or current_page == 'entity_detail' %}class="active"{% endif %}>Entities</a>
                {% endif %}
                {% if enable_playground %}
                <a href="{{ webui_url('playground') }}" {% if current_page == 'playground' %}class="active"{% endif %}>Playground</a>
                {% endif %}
            </nav>
        </div>
    </header>

    <main class="container">
        {% block content %}{% endblock %}
    </main>

    <footer>
        <div class="container">
            Powered by <a href="https://github.com/JacobCoffee/civi-py">civi-py</a>
        </div>
    </footer>

    {% block extra_js %}{% endblock %}
</body>
</html>
