<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Mastermind — Draft</title>
  <style>
    body{font-family:system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;margin:0;background:#0b0f14;color:#e8eef7}
    header{background:#111824;border-bottom:1px solid #233043;padding:14px 16px;position:sticky;top:0}
    main{max-width:1100px;margin:0 auto;padding:16px}
    .card{background:#111824;border:1px solid #233043;border-radius:12px;padding:14px;margin:12px 0}
    a{color:#7cc4ff;text-decoration:none}
    .muted{color:#a9b7c6}
    textarea,input,select{width:100%;padding:12px;border-radius:10px;border:1px solid #233043;background:#0e1520;color:#e8eef7}
    button{padding:12px 14px;border-radius:10px;border:1px solid #233043;background:#1c2a3d;color:#e8eef7}
    .grid{display:grid;grid-template-columns:repeat(12,1fr);gap:12px}
    .col6{grid-column:span 12}
    @media(min-width:900px){.col6{grid-column:span 6}}
    pre{white-space:pre-wrap;background:#0e1520;border:1px solid #233043;border-radius:10px;padding:12px;color:#d6e3f3}
  </style>
</head>
<body>
<header>
  <div style="display:flex;justify-content:space-between;align-items:center;gap:10px">
    <div style="font-weight:700"><%= kind.toUpperCase() %> Draft</div>
    <div style="display:flex;gap:10px">
      <a href="/">Dashboard</a>
      <a href="/logout">Logout</a>
    </div>
  </div>
</header>
<main>
  <div class="card">
    <div class="muted"><b>Project:</b> <%= project ? project.name : '(unassigned)' %></div>
    <div class="muted"><b>Source email:</b> <% if (email) { %><a href="/inbox/<%= email.id %>"><%= email.subject || email.id %></a><% } else { %>—<% } %></div>
  </div>

  <div class="card">
    <div style="display:flex;gap:10px;flex-wrap:wrap;justify-content:flex-end;margin-bottom:10px">
      <a href="/drafts/<%= kind %>/<%= draft.id %>/export.md">Download .md</a>
    </div>

    <form method="post" action="/drafts/<%= kind %>/<%= draft.id %>/save" class="grid">
      <div class="col6">
        <label class="muted">Title</label>
        <input name="title" value="<%= draft.title || '' %>" />
      </div>
      <div class="col6">
        <label class="muted">Status</label>
        <select name="status">
          <% ['draft','ready','sent'].forEach(s => { %>
            <option value="<%= s %>" <%= draft.status===s?'selected':'' %>><%= s %></option>
          <% }) %>
        </select>
      </div>
      <div style="grid-column:span 12">
        <label class="muted">Body (Markdown)</label>
        <textarea name="body" rows="14"><%= draft.body || '' %></textarea>
      </div>
      <div style="grid-column:span 12">
        <button type="submit">Save</button>
      </div>
    </form>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Preview</h2>
    <div class="muted" style="margin-bottom:8px">Rendered Markdown preview</div>
    <div style="background:#0e1520;border:1px solid #233043;border-radius:10px;padding:12px;overflow:auto">
      <%- previewHtml %>
    </div>
  </div>
</main>
</body>
</html>
