{% extends "base.html" %}
{% block title %}Security Settings — ComplyForm Dashboard{% endblock %}
{% block content %}
<div class="max-w-3xl mx-auto px-4 py-6">
  <h1 class="text-xl font-semibold mb-6" style="color: var(--text-primary);">Security Settings</h1>

  <section class="mb-8 p-4 rounded-lg" style="background: var(--bg-surface); border: 1px solid var(--border-default);">
    <h2 class="text-lg font-semibold mb-3" style="color: var(--text-primary);">IP Allowlist</h2>

    <div class="mb-4 p-3 rounded text-sm" style="background: #fffbeb; color: #854d0e; border: 1px solid #fde68a;">
      Enabling IP restrictions will block dashboard access from non-allowed IPs, including yours. Ensure your current IP is included.
    </div>

    <p class="text-sm mb-4" style="color: var(--text-secondary);">Your current IP: <code style="background: var(--bg-surface-hover); padding: 2px 6px; border-radius: 4px;">{{ client_ip }}</code></p>

    <form method="POST" action="/dashboard/settings/security/ip-allowlist">
      <input type="hidden" name="_csrf" value="{{ csrf_token }}">

      <div class="space-y-4">
        <div class="flex items-center gap-2">
          <input type="checkbox" name="enabled" id="ip_enabled" {% if ip_config and ip_config.enabled %}checked{% endif %}>
          <label for="ip_enabled" class="text-sm" style="color: var(--text-primary);">Enable IP Allowlist</label>
        </div>

        <div>
          <label class="block text-sm mb-1" style="color: var(--text-secondary);">Allowed CIDRs (one per line)</label>
          <textarea name="cidrs" rows="6" class="w-full px-3 py-2 rounded text-sm font-mono"
            style="background: var(--bg-default); border: 1px solid var(--border-default); color: var(--text-primary);"
            placeholder="10.0.0.0/8&#10;192.168.1.0/24&#10;203.0.113.5/32">{% if ip_config %}{% for cidr in ip_config.cidrs %}{{ cidr }}
{% endfor %}{% endif %}</textarea>
          <p class="text-xs mt-1" style="color: var(--text-secondary);">IPv4 and IPv6 CIDR notation supported (e.g. 10.0.0.0/8, 2001:db8::/32)</p>
        </div>

        <button type="submit" class="px-4 py-2 rounded text-sm font-medium text-white" style="background: var(--accent);">Save IP Allowlist</button>
      </div>
    </form>
  </section>
</div>
{% endblock %}
