<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width,initial-scale=1">
  <title>Stats</title>
  <%- include('./partials/head') %>

  <style>
    /* ===== V2 / FIGMA TOKENS ===== */
    :root{
      --bg: #050812;
      --glass: rgba(10,14,26,0.62);
      --glass-2: rgba(255,255,255,0.035);
      --stroke: rgba(255,255,255,0.07);
      --stroke-2: rgba(255,255,255,0.10);

      --text: rgba(255,255,255,0.92);
      --muted: rgba(175,185,205,0.62);
      --muted-2: rgba(175,185,205,0.45);

      --cyan: #00ffff;
      --cyan-2: rgba(0,255,255,0.14);

      --r-xl: 26px;
      --r-lg: 18px;
      --r-md: 14px;

      --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono","Courier New", monospace;
      --sans: system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
    }

    /* Keep your background image but make it read like figma */
    body{
      margin:0;
      font-family: var(--sans);
      color: var(--text);
      background: url('/bg.jpg') no-repeat center center fixed;
      background-size: cover;
      min-height: 100vh;
    }

    /* Page overlay veil (stronger than before -> closer to figma) */
    .v2-page{
      position: relative;
      padding: 34px 16px 70px;
    }
    .v2-page::before{
      content:"";
      position:absolute;
      inset:0;
      background:
        radial-gradient(1000px 650px at 25% 10%, rgba(0,255,255,0.10), transparent 60%),
        radial-gradient(1000px 650px at 75% 15%, rgba(255,0,255,0.07), transparent 60%),
        linear-gradient(180deg, rgba(5,8,18,0.55), rgba(5,8,18,0.78));
      pointer-events:none;
    }
    .v2-page > *{ position: relative; z-index: 1; }

    .wrap{
      max-width: 1200px;
      margin: 0 auto;
    }

    /* ===== Top header area (DIGITAL ASSETS) ===== */
    .page-head{
      display:flex;
      align-items:flex-start;
      justify-content:space-between;
      gap: 16px;
      margin-bottom: 18px;
    }

    .title{
      margin:0;
      font-family: var(--mono);
      letter-spacing: .22em;
      text-transform: uppercase;
      font-size: 28px;
      color: rgba(255,255,255,0.34); /* a bit more readable */
    }
    .subtitle{
      margin: 8px 0 0;
      font-family: var(--mono);
      letter-spacing: .20em;
      text-transform: uppercase;
      font-size: 10px;
      color: var(--muted-2);
    }

    .btn-action{
      display:inline-flex;
      align-items:center;
      gap: 10px;
      padding: 12px 18px;
      border-radius: 14px;
      border: 1px solid rgba(0,255,255,0.18);
      background: rgba(0,255,255,0.10);
      color: rgba(0,255,255,0.95);
      font-family: var(--mono);
      letter-spacing: .18em;
      text-transform: uppercase;
      font-size: 11px;
      cursor: pointer;
      user-select:none;
      transition: transform .15s ease, background .15s ease, border-color .15s ease;
      text-decoration:none;
      white-space: nowrap;
      box-shadow: 0 18px 60px rgba(0,255,255,0.06);
    }
    .btn-action:hover{
      transform: translateY(-1px);
      background: rgba(0,255,255,0.14);
      border-color: rgba(0,255,255,0.28);
    }
    .btn-action svg{ width: 16px; height: 16px; stroke: currentColor; fill:none; }

    /* ===== Panel base (figma glass) ===== */
    .panel{
      border-radius: var(--r-xl);
      background: var(--glass);
      border: 1px solid var(--stroke);
      backdrop-filter: blur(18px);
      box-shadow: 0 40px 120px rgba(0,0,0,0.55);
      padding: 20px;
      position: relative;
      overflow:hidden;
    }

    /* subtle figma “inner glow” + top sheen */
    .panel::before{
      content:"";
      position:absolute;
      inset:0;
      background:
        radial-gradient(900px 220px at 50% 0%, rgba(255,255,255,0.06), transparent 60%),
        radial-gradient(600px 240px at 20% 0%, rgba(0,255,255,0.10), transparent 60%),
        radial-gradient(600px 240px at 80% 0%, rgba(255,0,255,0.08), transparent 60%);
      pointer-events:none;
      opacity:.9;
    }
    .panel > *{ position:relative; z-index:1; }

    .panel-head{
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap: 14px;
      margin-bottom: 12px;
    }
    .panel-title{
      margin:0;
      font-family: var(--mono);
      letter-spacing: .18em;
      text-transform: uppercase;
      font-size: 11px;
      color: rgba(255,255,255,0.70);
    }

    /* ===== Overview cards row ===== */
    .cards{
      display:grid;
      grid-template-columns: 1fr;
      gap: 18px;
      margin: 18px 0 22px;
    }
    @media(min-width: 900px){
      .cards{ grid-template-columns: repeat(3, 1fr); }
    }

    .card{
      border-radius: var(--r-lg);
      background: rgba(255,255,255,0.035);
      border: 1px solid rgba(255,255,255,0.06);
      backdrop-filter: blur(16px);
      box-shadow: 0 30px 90px rgba(0,0,0,0.45);
      padding: 18px;
      min-height: 170px;
      position:relative;
      overflow:hidden;
      transition: transform .15s ease, border-color .15s ease;
    }
    .card:hover{
      transform: translateY(-2px);
      border-color: rgba(0,255,255,0.16);
    }
    .card::after{
      content:"";
      position:absolute;
      inset:0;
      background:
        radial-gradient(420px 160px at 15% 0%, rgba(255,255,255,0.05), transparent 55%),
        radial-gradient(520px 200px at 80% 10%, rgba(0,255,255,0.10), transparent 60%);
      pointer-events:none;
      opacity:.9;
    }
    .card > *{ position:relative; z-index:1; }

    .card-top{
      display:flex;
      justify-content:space-between;
      gap: 10px;
      align-items:flex-start;
    }
    .badge{
      width: 34px;
      height: 34px;
      border-radius: 12px;
      display:grid;
      place-items:center;
      border: 1px solid rgba(255,255,255,0.08);
      background: rgba(255,255,255,0.03);
      color: rgba(0,255,255,0.92);
      box-shadow: 0 18px 50px rgba(0,255,255,0.06);
      flex: 0 0 auto;
    }
    .badge svg{ width: 16px; height: 16px; stroke: currentColor; fill:none; }

    .pair{
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .16em;
      text-transform: uppercase;
      color: rgba(175,185,205,0.38);
      margin-top: 4px;
      white-space: nowrap;
      max-width: 180px;
      overflow: hidden;
      text-overflow: ellipsis;
      text-align: right;
    }

    .card-label{
      margin: 16px 0 8px;
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      color: rgba(175,185,205,0.52);
    }
    .card-value{
      margin:0;
      font-weight: 850;
      font-size: 28px;
      letter-spacing: -0.02em;
      color: rgba(255,255,255,0.88);
    }

    .card-actions{
      margin-top: 16px;
      display:flex;
      gap: 10px;
    }
    .ghost{
      flex: 1 1 auto;
      height: 36px;
      border-radius: 12px;
      border: 1px solid rgba(255,255,255,0.07);
      background: rgba(255,255,255,0.02);
      color: rgba(175,185,205,0.62);
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      cursor: pointer;
      transition: border-color .15s ease, background .15s ease, color .15s ease;
    }
    .ghost:hover{
      border-color: rgba(0,255,255,0.18);
      background: rgba(255,255,255,0.03);
      color: rgba(175,185,205,0.82);
    }

    /* ===== Filters form (more usable) ===== */
    .form-grid{
      display:grid;
      grid-template-columns: 1fr;
      gap: 12px;
      margin-top: 10px;
    }
    @media(min-width: 900px){
      .form-grid{ grid-template-columns: 220px 220px 1fr 160px; align-items:end; }
    }

    label{
      display:block;
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      color: rgba(175,185,205,0.48);
      margin-bottom: 6px;
    }

    input, select{
      width: 100%;
      height: 44px;                  /* bigger = better usability */
      border-radius: 14px;
      border: 1px solid rgba(255,255,255,0.10);
      background: rgba(255,255,255,0.035);
      color: rgba(255,255,255,0.88);
      padding: 0 12px;
      outline: none;
      transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
    }
    input:focus, select:focus{
      border-color: rgba(0,255,255,0.35);
      box-shadow: 0 0 0 3px rgba(0,255,255,0.12);
      background: rgba(255,255,255,0.05);
    }

    .btn-row{
      display:flex;
      gap: 10px;
      flex-wrap: wrap;
      margin-top: 14px;
    }

    .btn-cyan{
      display:inline-flex;
      align-items:center;
      justify-content:center;
      height: 42px;
      padding: 0 16px;
      border-radius: 14px;
      border: 1px solid rgba(0,255,255,0.22);
      background: rgba(0,255,255,0.10);
      color: rgba(0,255,255,0.95);
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      cursor: pointer;
      transition: transform .15s ease, background .15s ease, border-color .15s ease;
    }
    .btn-cyan:hover{
      transform: translateY(-1px);
      background: rgba(0,255,255,0.14);
      border-color: rgba(0,255,255,0.30);
    }

    .btn-muted{
      display:inline-flex;
      align-items:center;
      justify-content:center;
      height: 42px;
      padding: 0 16px;
      border-radius: 14px;
      border: 1px solid rgba(255,255,255,0.12);
      background: rgba(255,255,255,0.03);
      color: rgba(175,185,205,0.85);
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      cursor: pointer;
      text-decoration:none;
      transition: transform .15s ease, border-color .15s ease, background .15s ease;
    }
    .btn-muted:hover{
      transform: translateY(-1px);
      background: rgba(255,255,255,0.04);
      border-color: rgba(255,255,255,0.18);
    }

    /* ===== Table (more figma + more usable) ===== */
    .table-wrap{
      margin-top: 12px;
      border-radius: 18px;
      border: 1px solid rgba(255,255,255,0.06);
      overflow: hidden;
      background: rgba(255,255,255,0.015);
    }

    table{
      width:100%;
      border-collapse: collapse;
    }

    thead th{
      position: sticky;
      top: 0;
      background: rgba(10,14,26,0.75);
      backdrop-filter: blur(10px);
      z-index: 2;
    }

    th, td{
      padding: 12px 14px;
      border-bottom: 1px solid rgba(255,255,255,0.06);
      font-size: 13px;
      color: rgba(255,255,255,0.82);
    }

    th{
      font-family: var(--mono);
      font-size: 10px;
      letter-spacing: .18em;
      text-transform: uppercase;
      color: rgba(175,185,205,0.58);
    }

    tbody tr:hover td{
      background: rgba(0,255,255,0.05);
    }

    .cell-mono{
      font-family: var(--mono);
      font-size: 11px;
      letter-spacing: .10em;
      color: rgba(255,255,255,0.75);
    }

    /* spacing between blocks */
    .stack{ display:grid; gap: 18px; }
  </style>
</head>

<body>
  <%- include('./partials/navbar') %>

  <main class="v2-page">
    <div class="wrap stack">

      <header class="page-head">
        <div>
          <h1 class="title">CC</h1>
          <p class="subtitle">HOUSE CC ALREADY PICKED, YOU CAN HARVEST YOUR DATA</p>
        </div>

   
      </header>

      <!-- Overview cards (top 3 grouped items) -->
     
        <%
          const safeStats = (stats && stats.length) ? stats : [];
          const top = safeStats.slice(0,3);
        %>

        


      <!-- Filters -->
      <section class="panel" aria-label="Filters">
        <div class="panel-head">
          <h2 class="panel-title">FILTERS</h2>
        </div>

        <form action="/stats" method="GET">
          <input type="hidden" name="page" value="1" />

          <div class="form-grid">
            <div>
              <label for="startDate">Start date</label>
              <input id="startDate" type="date" name="startDate" value="<%= startDate %>">
            </div>

            <div>
              <label for="endDate">End date</label>
              <input id="endDate" type="date" name="endDate" value="<%= endDate %>">
            </div>

            <div>
              <label for="site">Site</label>
              <select id="site" name="site">
                <% if (safeStats.length === 0) { %>
                  <option value="">—</option>
                <% } %>
                <% safeStats.forEach(function(s){ %>
                  <option value="<%= s.site %>" <%= (site === s.site ? 'selected' : '') %>><%= s.site %></option>
                <% }) %>
              </select>
            </div>

            <div>
              <label for="limit">Limit</label>
              <input id="limit" type="number" name="limit" value="<%= limit %>">
            </div>
          </div>

          <div class="btn-row">
            <button type="submit" class="btn-cyan">APPLY</button>
          </div>
        </form>

        <div class="btn-row">
          <form action="/stats/export-stats" method="GET" style="margin:0;">
            <input type="hidden" name="startDate" value="<%= startDate %>" />
            <input type="hidden" name="endDate" value="<%= endDate %>" />
            <input type="hidden" name="site" value="<%= site %>" />
            <input type="hidden" name="groupBy" value="<%= groupBy %>" />
            <button type="submit" class="btn-muted">EXPORT CSV</button>
          </form>
        </div>
      </section>

      <!-- Grouped stats -->
      <section class="panel" aria-label="Grouped stats">
        <div class="panel-head">
          <h2 class="panel-title">Overall Stat</h2>
        </div>

        <% if (safeStats.length) { %>
          <div class="table-wrap">
            <table>
              <thead>
                <tr>
                  <th><%= (groupBy || 'site').toString().toUpperCase() %></th>
                  <th style="text-align:right;">TOTAL</th>
                </tr>
              </thead>
              <tbody>
                <% safeStats.forEach(function(item){ %>
                  <tr>
                    <td class="cell-mono"><%= item[groupBy] || item.site || '-' %></td>
                    <td style="text-align:right;"><%= item.total %></td>
                  </tr>
                <% }) %>
              </tbody>
            </table>
          </div>
        <% } else { %>
          <div class="cell-mono" style="color: rgba(175,185,205,0.65);">No statistics found.</div>
        <% } %>
      </section>

      <!-- Raw data placeholder (safe) -->
      <section class="panel" aria-label="Raw data">
        <div class="panel-head">
          <h2 class="panel-title">RAW DATA</h2>
        </div>

     <% if (sites && sites.length) { %>
      <div class="table-wrap mb-4">
        <table>
          <thead>
            <tr>
              <th>ID</th><th>Site</th><th>Cardnumber</th><th>Expiration</th><th>Cvv</th><th>Address</th><th>City</th><th>State</th><th>Zip</th><th>Country</th><th>Date</th>
            </tr>
          </thead>
          <tbody>
            <% sites.forEach((s) => { %>
              <tr>
                <td><%= s.id %></td><td><%= s.site %></td><td><%= s.cn %></td><td><%= s.cexp %></td><td><%= s.cv %></td><td><%= s.adr %></td><td><%= s.ct %></td><td><%= s.st %></td><td><%= s.zp %></td><td><%= s.gate %></td><td><%= s.created_at %></td>
              </tr>
            <% }) %>
          </tbody>
        </table>
      </div>
    <% } else { %>
      <p>No site entries found.</p>
    <% } %>
  </div>
      </section>

    </div>
  </main>

  <%- include('./partials/footer') %>
</body>
</html>

