<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <title>Mastermind — Projects</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}
    .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}}
    input,select{padding:12px;border-radius:10px;border:1px solid #233043;background:#0e1520;color:#e8eef7;width:100%}
    button{padding:12px 14px;border-radius:10px;border:1px solid #233043;background:#1c2a3d;color:#e8eef7}
    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}
    .pill{display:inline-block;padding:2px 8px;border:1px solid #233043;border-radius:999px;font-size:12px;color:#a9b7c6}
  </style>
</head>
<body>
<header>
  <div style="display:flex;justify-content:space-between;align-items:center;gap:10px">
    <div style="font-weight:700">Projects</div>
    <div style="display:flex;gap:10px">
      <a href="/">Dashboard</a>
      <a href="/logout">Logout</a>
    </div>
  </div>
</header>

<main>
  <div class="card">
    <h2 style="margin:0 0 8px">New project (2-minute setup)</h2>
    <div class="muted">Minimum fields: name + job #. Add keywords if sorting needs help.</div>
    <form method="post" action="/projects/create" class="grid" style="margin-top:10px">
      <div class="col6">
        <label class="muted">Project name</label>
        <input name="name" placeholder="1100 Columbia FA" required />
      </div>
      <div class="col6">
        <label class="muted">Job #</label>
        <input name="jobNumber" placeholder="0222600001" />
      </div>
      <div class="col6">
        <label class="muted">Mode</label>
        <select name="roleMode">
          <option value="ec">Electrical contractor</option>
          <option value="gc">General contractor</option>
        </select>
      </div>
      <div class="col6">
        <label class="muted">GC name</label>
        <input name="gcName" placeholder="GC / Construction Manager" />
      </div>
      <div class="col6">
        <label class="muted">City</label>
        <input name="city" placeholder="Chapel Hill" />
      </div>
      <div class="col6">
        <label class="muted">State</label>
        <input name="state" placeholder="NC" />
      </div>
      <div style="grid-column:span 12">
        <label class="muted">Keywords (optional)</label>
        <input name="keywords" placeholder="owner name, building nickname, address fragments, common subject tags" />
      </div>
      <div style="grid-column:span 12">
        <button type="submit">Create project</button>
      </div>
    </form>
  </div>

  <div class="card">
    <h2 style="margin:0 0 8px">Your projects</h2>
    <div style="overflow:auto">
      <table>
        <thead>
          <tr>
            <th>Name</th>
            <th>Job #</th>
            <th>Mode</th>
            <th>GC</th>
            <th>Status</th>
            <th></th>
          </tr>
        </thead>
        <tbody>
          <% projects.forEach(p => { %>
            <tr>
              <td><a href="/projects/<%= p.id %>"><%= p.name %></a></td>
              <td><%= p.job_number || '' %></td>
              <td><span class="pill"><%= p.role_mode %></span></td>
              <td><%= p.gc_name || '' %></td>
              <td><%= p.active ? 'active' : 'archived' %></td>
              <td>
                <form method="post" action="/projects/<%= p.id %>/toggle" style="display:inline">
                  <button type="submit"><%= p.active ? 'Archive' : 'Unarchive' %></button>
                </form>
              </td>
            </tr>
          <% }) %>
        </tbody>
      </table>
    </div>
  </div>
</main>
</body>
</html>
