<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Mastermind — Email</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}
    pre{white-space:pre-wrap;background:#0e1520;border:1px solid #233043;border-radius:10px;padding:12px;color:#d6e3f3}
    table{width:100%;border-collapse:collapse}
    th,td{border-bottom:1px solid #233043;padding:10px 6px;text-align:left;color:#a9b7c6;font-size:13px;vertical-align:top}
    th{color:#e8eef7}
    button{padding:10px 12px;border-radius:10px;border:1px solid #233043;background:#1c2a3d;color:#e8eef7}
  </style>
</head>
<body>
<header>
  <div style="display:flex;justify-content:space-between;align-items:center;gap:10px">
    <div style="font-weight:700">Email</div>
    <div style="display:flex;gap:10px">
      <a href="/inbox">Inbox</a>
      <a href="/projects">Projects</a>
      <a href="/">Dashboard</a>
    </div>
  </div>
</header>
<main>
  <div class="card">
    <div class="muted"><b>Date:</b> <%= email.date || '' %></div>
    <div class="muted"><b>From:</b> <%= email.from_addr || '' %></div>
    <div class="muted"><b>To:</b> <%= email.to_addr || '' %></div>
    <div class="muted"><b>Subject:</b> <%= email.subject || '' %></div>
    <div class="muted"><b>Status:</b> <%= email.status %></div>
    <div class="muted"><b>Raw file:</b> <%= email.raw_path || '' %></div>

    <div style="height:10px"></div>
    <div style="display:flex;gap:10px;flex-wrap:wrap">
      <form method="post" action="/drafts/pco/from-email">
        <input type="hidden" name="emailId" value="<%= email.id %>" />
        <button type="submit">Create PCO draft from this email</button>
      </form>
      <form method="post" action="/drafts/rfi/from-email">
        <input type="hidden" name="emailId" value="<%= email.id %>" />
        <button type="submit">Create RFI draft from this email</button>
      </form>
    </div>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Attachments</h2>
    <% if (!attachments.length) { %>
      <div class="muted">No attachments stored for this email.</div>
    <% } else { %>
      <table>
        <thead>
          <tr>
            <th>Filename</th>
            <th>Type</th>
            <th>Size</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <% attachments.forEach(a => { %>
            <tr>
              <td><%= a.filename || '' %></td>
              <td><%= a.content_type || '' %></td>
              <td><%= a.size_bytes || '' %></td>
              <td><a href="/attachments/<%= a.id %>">Download</a></td>
            </tr>
          <% }) %>
        </tbody>
      </table>
    <% } %>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Body (text)</h2>
    <pre><%= email.body_text || '' %></pre>
  </div>
</main>
</body>
</html>
