{# env配置:CSS Tab(无需 JS)+ 双列表单 #}
<div class="env-config-page full">
    <div class="env-config-head card">
        <div class="env-config-head-row">
            <div>
                <h2>env 配置</h2>
                <p class="settings-env-hint env-config-head-hint">按分类修改,改完点保存.含「需重启」的项请用「保存并重启」.<strong>AI 配置</strong>请在中控 → 系统设置 → AI 配置统一维护.</p>
            </div>
            <div class="env-config-toolbar">
                <button type="button" class="btn-primary btn-sm" id="env-config-save">保存</button>
                <button type="button" class="btn-secondary btn-sm" id="env-config-save-restart">保存并重启</button>
                <button type="button" class="btn-secondary btn-sm" id="env-config-reload">重新加载</button>
            </div>
        </div>
        <span class="settings-status-line" id="env-config-status"></span>
    </div>

    {% if env_config_groups %}
    <div class="env-config-body card" data-env-ssr="1" id="env-config-body">
        {% for group in env_config_groups %}
        <input type="radio" name="env-section" id="env-sec-{{ loop.index0 }}" class="env-tab-radio"{% if loop.first %} checked{% endif %}>
        {% endfor %}
        <div class="env-config-tabs" role="tablist" aria-label="配置分类">
            {% for group in env_config_groups %}
            <label for="env-sec-{{ loop.index0 }}" class="env-tab-btn" role="tab">{{ group.title }}</label>
            {% endfor %}
        </div>
        <div class="env-config-panels" id="env-config-grid">
            {% for group in env_config_groups %}
            <section class="env-panel env-panel--{{ loop.index0 }}" role="tabpanel">
                {% if group.has_restart %}
                <p class="env-panel-hint">本组含需重启项,修改后请点「保存并重启」.</p>
                {% endif %}
                <div class="env-form-grid">
                    {% for field in group.fields %}
                    <div class="env-field-row{% if field.restart_required %} env-field-row--restart{% endif %}">
                        <label class="env-field-label" for="env-f-{{ field.key }}">
                            {{ field.label or field.key }}
                            {% if field.restart_required %}<span class="env-restart-mark" title="需重启">*</span>{% endif %}
                        </label>
                        {% if field.note %}
                        <div class="env-field-note muted">{{ field.note }}</div>
                        {% endif %}
                        {% if field.type == 'bool' %}
                        <select class="env-field-input" id="env-f-{{ field.key }}" data-env-key="{{ field.key }}">
                            {% set cur = (field.current or field.default or 'false')|lower %}
                            <option value="true"{% if cur in ('true', '1', 'yes', 'on') %} selected{% endif %}>开启</option>
                            <option value="false"{% if cur not in ('true', '1', 'yes', 'on') %} selected{% endif %}>关闭</option>
                        </select>
                        {% elif field.sensitive %}
                        {% if field.has_value %}
                        <div class="env-sensitive-current muted">已配置 <span class="env-masked-value">{{ field.masked }}</span></div>
                        {% endif %}
                        <input
                            class="env-field-input"
                            id="env-f-{{ field.key }}"
                            type="password"
                            data-env-key="{{ field.key }}"
                            placeholder="{% if field.has_value %}修改时填写新值,留空不修改{% else %}请输入{% endif %}"
                            autocomplete="off"
                        >
                        {% else %}
                        <input
                            class="env-field-input"
                            id="env-f-{{ field.key }}"
                            type="text"
                            data-env-key="{{ field.key }}"
                            value="{{ field.current or field.default or '' }}"
                        >
                        {% endif %}
                    </div>
                    {% endfor %}
                </div>
            </section>
            {% endfor %}
        </div>
    </div>
    {% else %}
    <div id="env-config-grid" class="env-config-loading-wrap card">
        <div class="env-config-loading muted">加载配置中…</div>
    </div>
    {% endif %}
</div>
