<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>{% block title %}supyagent{% endblock %}</title>
  <style>
    *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

    :root {
      --bg: #0a0a0a;
      --surface: #141414;
      --surface-hover: #1a1a1a;
      --border: #262626;
      --border-light: #333;
      --text: #e5e5e5;
      --text-dim: #888;
      --text-muted: #555;
      --accent: #06b6d4;
      --accent-dim: #0e7490;
      --green: #22c55e;
      --red: #ef4444;
      --yellow: #eab308;
      --radius: 8px;
      --font: "SF Mono", "Cascadia Code", "Fira Code", "JetBrains Mono", monospace;
    }

    body {
      font-family: var(--font);
      background: var(--bg);
      color: var(--text);
      line-height: 1.6;
      font-size: 14px;
      min-height: 100vh;
    }

    .container {
      max-width: 860px;
      margin: 0 auto;
      padding: 40px 24px 80px;
    }

    h1 {
      font-size: 20px;
      font-weight: 600;
      margin-bottom: 8px;
    }

    h2 {
      font-size: 16px;
      font-weight: 600;
      margin-bottom: 16px;
      color: var(--text);
    }

    h3 {
      font-size: 14px;
      font-weight: 600;
      margin-bottom: 12px;
      color: var(--text-dim);
      text-transform: uppercase;
      letter-spacing: 0.05em;
    }

    .subtitle {
      color: var(--text-dim);
      margin-bottom: 32px;
    }

    .section {
      background: var(--surface);
      border: 1px solid var(--border);
      border-radius: var(--radius);
      padding: 24px;
      margin-bottom: 24px;
    }

    .section-header {
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 16px;
    }

    /* Forms */
    label {
      display: block;
      font-size: 13px;
      color: var(--text-dim);
      margin-bottom: 6px;
    }

    input[type="text"],
    input[type="password"],
    select,
    textarea {
      width: 100%;
      padding: 8px 12px;
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 6px;
      color: var(--text);
      font-family: var(--font);
      font-size: 13px;
      outline: none;
      transition: border-color 0.15s;
    }

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

    textarea { resize: vertical; min-height: 80px; }

    .input-row {
      display: flex;
      gap: 8px;
      align-items: flex-end;
    }

    .input-row .grow { flex: 1; }

    /* Buttons */
    .btn {
      display: inline-flex;
      align-items: center;
      gap: 6px;
      padding: 8px 16px;
      border: 1px solid var(--border);
      border-radius: 6px;
      background: var(--surface);
      color: var(--text);
      font-family: var(--font);
      font-size: 13px;
      cursor: pointer;
      transition: all 0.15s;
      white-space: nowrap;
    }

    .btn:hover { background: var(--surface-hover); border-color: var(--border-light); }
    .btn:disabled { opacity: 0.4; cursor: not-allowed; }

    .btn-primary {
      background: var(--accent);
      border-color: var(--accent);
      color: #000;
      font-weight: 600;
    }
    .btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); }

    .btn-danger {
      color: var(--red);
      border-color: transparent;
      background: transparent;
    }
    .btn-danger:hover { background: rgba(239,68,68,0.1); }

    .btn-sm { padding: 4px 10px; font-size: 12px; }

    .btn-group { display: flex; gap: 8px; }

    /* Table */
    table {
      width: 100%;
      border-collapse: collapse;
    }

    th {
      text-align: left;
      font-size: 12px;
      font-weight: 600;
      color: var(--text-dim);
      text-transform: uppercase;
      letter-spacing: 0.05em;
      padding: 8px 12px;
      border-bottom: 1px solid var(--border);
    }

    td {
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      vertical-align: middle;
    }

    tr:last-child td { border-bottom: none; }
    tr:hover td { background: var(--surface-hover); }

    /* Status indicators */
    .status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; }
    .status-dot {
      width: 8px; height: 8px;
      border-radius: 50%;
      display: inline-block;
    }
    .status-ok .status-dot { background: var(--green); }
    .status-missing .status-dot { background: var(--red); }
    .status-warn .status-dot { background: var(--yellow); }

    /* Cards */
    .card {
      background: var(--bg);
      border: 1px solid var(--border);
      border-radius: 6px;
      padding: 16px;
    }

    .card-grid {
      display: grid;
      grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
      gap: 12px;
    }

    /* Radio cards */
    .radio-card {
      background: var(--bg);
      border: 2px solid var(--border);
      border-radius: 6px;
      padding: 16px;
      cursor: pointer;
      transition: all 0.15s;
    }
    .radio-card:hover { border-color: var(--border-light); }
    .radio-card.selected { border-color: var(--accent); }
    .radio-card-title { font-weight: 600; margin-bottom: 4px; }
    .radio-card-desc { font-size: 12px; color: var(--text-dim); }

    /* Badges */
    .badge {
      display: inline-block;
      padding: 2px 8px;
      border-radius: 4px;
      font-size: 11px;
      font-weight: 600;
    }
    .badge-default { background: var(--accent-dim); color: #fff; }
    .badge-role { background: #1e293b; color: var(--accent); }

    /* Toast */
    .toast-container {
      position: fixed;
      bottom: 24px;
      right: 24px;
      z-index: 1000;
      display: flex;
      flex-direction: column;
      gap: 8px;
    }

    .toast {
      padding: 10px 16px;
      border-radius: 6px;
      font-size: 13px;
      animation: slideIn 0.2s ease-out;
    }
    .toast-success { background: #052e16; border: 1px solid #166534; color: var(--green); }
    .toast-error { background: #2d0808; border: 1px solid #7f1d1d; color: var(--red); }

    @keyframes slideIn {
      from { opacity: 0; transform: translateY(10px); }
      to { opacity: 1; transform: translateY(0); }
    }

    /* Footer bar */
    .footer-bar {
      position: fixed;
      bottom: 0;
      left: 0;
      right: 0;
      background: var(--surface);
      border-top: 1px solid var(--border);
      padding: 12px 24px;
      display: flex;
      justify-content: flex-end;
      gap: 12px;
      z-index: 100;
    }

    /* Spinner */
    .spinner {
      display: inline-block;
      width: 14px; height: 14px;
      border: 2px solid var(--border);
      border-top-color: var(--accent);
      border-radius: 50%;
      animation: spin 0.6s linear infinite;
    }
    @keyframes spin { to { transform: rotate(360deg); } }

    /* Utilities */
    .mt-4 { margin-top: 16px; }
    .mt-2 { margin-top: 8px; }
    .mb-4 { margin-bottom: 16px; }
    .mb-2 { margin-bottom: 8px; }
    .text-dim { color: var(--text-dim); }
    .text-muted { color: var(--text-muted); }
    .text-accent { color: var(--accent); }
    .text-green { color: var(--green); }
    .text-red { color: var(--red); }
    .text-sm { font-size: 12px; }
    .hidden { display: none !important; }
    .flex { display: flex; }
    .items-center { align-items: center; }
    .gap-2 { gap: 8px; }
    .gap-4 { gap: 16px; }

    {% block extra_css %}{% endblock %}
  </style>
</head>
<body>
  <div class="container">
    {% block content %}{% endblock %}
  </div>

  <div class="toast-container" id="toasts"></div>

  <script>
    async function apiCall(method, path, body) {
      const opts = {
        method,
        headers: { "Content-Type": "application/json" },
      };
      if (body !== undefined) opts.body = JSON.stringify(body);
      const res = await fetch(path, opts);
      if (!res.ok) {
        const text = await res.text();
        throw new Error(text || `HTTP ${res.status}`);
      }
      return res.json();
    }

    function toast(message, type = "success") {
      const el = document.createElement("div");
      el.className = `toast toast-${type}`;
      el.textContent = message;
      document.getElementById("toasts").appendChild(el);
      setTimeout(() => el.remove(), 3000);
    }

    function signalDone(data = {}) {
      navigator.sendBeacon("/api/done", JSON.stringify({ action: "done", data }));
    }

    window.addEventListener("beforeunload", () => {
      signalDone();
    });

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