<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <link rel="icon" type="image/png" href="/analytics-grade.png" />
  <link rel="apple-touch-icon" href="/analytics-grade.png" />
  <meta name="robots" content="noindex, nofollow" />
  <title><%= typeof title !== 'undefined' && title ? title : 'Admin — Analytics Grade' %></title>
  <script src="https://cdn.tailwindcss.com"></script>
  <script src="/js/tailwind-config.js"></script>
  <link rel="preconnect" href="https://fonts.googleapis.com" />
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
  <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet" />
  <% if (typeof chartJs !== 'undefined' && chartJs) { %>
  <script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0/dist/chart.umd.min.js"></script>
  <% } %>
  <% if (typeof useFileManager !== 'undefined' && useFileManager) { %>
  <link rel="stylesheet" href="/css/admin-files.css" />
  <% } %>
  <% if (typeof useProfilePage !== 'undefined' && useProfilePage) { %>
  <link rel="stylesheet" href="/css/admin-profile.css" />
  <% } %>
  <% if (typeof useFilePicker !== 'undefined' && useFilePicker) { %>
  <link rel="stylesheet" href="/css/admin-file-picker.css" />
  <% } %>
  <% if (typeof useQuill !== 'undefined' && useQuill) { %>
  <link href="https://cdn.jsdelivr.net/npm/quill@1.3.7/dist/quill.snow.css" rel="stylesheet" />
  <link rel="stylesheet" href="/css/admin-quill.css" />
  <script src="https://cdn.jsdelivr.net/npm/quill@1.3.7/dist/quill.min.js"></script>
  <% } %>
  <style>
    * { box-sizing: border-box; }
    body { font-family: 'Inter', sans-serif; background: #070f1d; color: #fff; }
    ::-webkit-scrollbar { width: 4px; height: 4px; }
    ::-webkit-scrollbar-thumb { background: rgba(255,255,255,.15); border-radius: 4px; }
    .sidebar { background: #0b1628; border-right: 1px solid rgba(255,255,255,.07); width: 240px; flex-shrink: 0; }
    .sidebar-link {
      display: flex; align-items: center; gap: 10px; padding: 9px 16px; border-radius: 10px;
      font-size: .8125rem; font-weight: 500; color: rgba(255,255,255,.55);
      transition: background .15s, color .15s; text-decoration: none; margin: 1px 0;
    }
    .sidebar-link:hover { background: rgba(255,255,255,.06); color: rgba(255,255,255,.9); }
    .sidebar-link.active { background: rgba(128,101,248,.18); color: #a78bfa; }
    .sidebar-section {
      font-size: .65rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
      color: rgba(255,255,255,.25); padding: 16px 16px 6px;
    }
    .sidebar::before {
      content: ''; position: fixed; top: 0; left: 0; width: 240px; height: 2px;
      background: linear-gradient(90deg, #8065f8, #13b3b4); z-index: 10;
    }
    .card { background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.08); border-radius: 16px; padding: 20px; }
    .stat-card { transition: transform .2s, box-shadow .2s; }
    .stat-card:hover { transform: translateY(-2px); box-shadow: 0 12px 32px rgba(0,0,0,.3); }
    .table-row { border-bottom: 1px solid rgba(255,255,255,.05); transition: background .12s; }
    .table-row:hover { background: rgba(255,255,255,.03); }
    .trend-up { color: #34d399; }
    .trend-down { color: #f87171; }
    .badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 99px; font-size: .7rem; font-weight: 600; }
    .badge-green { background: rgba(16,185,129,.15); color: #34d399; border: 1px solid rgba(16,185,129,.25); }
    .badge-yellow { background: rgba(245,158,11,.12); color: #fbbf24; border: 1px solid rgba(245,158,11,.2); }
    .badge-gray { background: rgba(255,255,255,.06); color: rgba(255,255,255,.5); border: 1px solid rgba(255,255,255,.1); }
    .badge-red { background: rgba(239,68,68,.12); color: #f87171; border: 1px solid rgba(239,68,68,.2); }
    .badge-blue { background: rgba(68,144,211,.15); color: #93c5fd; border: 1px solid rgba(68,144,211,.25); }
    .badge-purple { background: rgba(128,101,248,.15); color: #c4b5fd; border: 1px solid rgba(128,101,248,.25); }
    .badge-teal { background: rgba(19,179,180,.15); color: #5eead4; border: 1px solid rgba(19,179,180,.25); }
    .btn-primary {
      background: linear-gradient(135deg,#8065f8,#4490d3); color: #fff; border: none;
      padding: 8px 18px; border-radius: 10px; font-size: .8125rem; font-weight: 600; cursor: pointer;
      transition: opacity .2s; display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
    }
    .btn-primary:hover { opacity: .9; }
    .btn-ghost {
      background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.7);
      padding: 8px 16px; border-radius: 10px; font-size: .8125rem; font-weight: 500; cursor: pointer;
      transition: background .15s; display: inline-flex; align-items: center; gap: 7px; text-decoration: none;
    }
    .btn-ghost:hover { background: rgba(255,255,255,.1); }
    .btn-danger {
      background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.25); color: #f87171;
      padding: 6px 12px; border-radius: 8px; font-size: .75rem; font-weight: 500; cursor: pointer;
      display: inline-flex; align-items: center; gap: 5px;
    }
    .btn-danger:hover { background: rgba(239,68,68,.25); }
    .btn-sm { padding: 5px 12px; border-radius: 8px; font-size: .75rem; font-weight: 500; display: inline-flex; align-items: center; gap: 5px; text-decoration: none; border: none; cursor: pointer; }
    .btn-edit { background: rgba(128,101,248,.15); border: 1px solid rgba(128,101,248,.2); color: #c4b5fd; }
    .btn-edit:hover { background: rgba(128,101,248,.25); }
    .btn-teal { background: rgba(19,179,180,.2); border: 1px solid rgba(19,179,180,.3); color: #5eead4; padding: 8px 16px; border-radius: 10px; font-size: .8125rem; font-weight: 500; cursor: pointer; display: inline-flex; align-items: center; gap: 7px; }
    .btn-teal:hover { background: rgba(19,179,180,.3); }
    th { font-size: .7rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: rgba(255,255,255,.3); padding: 10px 12px; text-align: left; border-bottom: 1px solid rgba(255,255,255,.06); }
    td { padding: 12px; font-size: .8rem; border-bottom: 1px solid rgba(255,255,255,.04); vertical-align: middle; }
    tr:last-child td { border-bottom: none; }
    tr:hover td { background: rgba(255,255,255,.02); }
    .filter-pill { padding: 6px 14px; border-radius: 99px; font-size: .75rem; font-weight: 600; cursor: pointer; border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.5); background: transparent; transition: all .15s; }
    .filter-pill.active { background: linear-gradient(135deg,#8065f8,#4490d3); border-color: transparent; color: #fff; }
    .filter-pill:hover:not(.active) { background: rgba(255,255,255,.06); color: rgba(255,255,255,.8); }
    .filter-tab { padding: 8px 16px; font-size: .8rem; font-weight: 600; cursor: pointer; border-bottom: 2px solid transparent; color: rgba(255,255,255,.4); transition: color .15s, border-color .15s; background: none; border-top: none; border-left: none; border-right: none; }
    .filter-tab.active { color: #a78bfa; border-bottom-color: #8065f8; }
    .filter-tab:hover:not(.active) { color: rgba(255,255,255,.7); }
    .form-label { font-size: .75rem; font-weight: 600; color: rgba(255,255,255,.6); display: block; margin-bottom: 6px; }
    .form-input {
      width: 100%; padding: 9px 13px; border-radius: 10px; font-size: .85rem; font-weight: 500; color: #fff;
      background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.1); outline: none;
      transition: border-color .15s; font-family: 'Inter', sans-serif;
    }
    .form-input:focus { border-color: #8065f8; box-shadow: 0 0 0 3px rgba(128,101,248,.12); }
    .form-input::placeholder { color: rgba(255,255,255,.25); }
    textarea.form-input { resize: vertical; }
    select.form-input,
    input[type="datetime-local"].form-input {
      color-scheme: dark;
      color: rgba(255, 255, 255, 0.9);
      background-color: #0b1628;
    }
    select.form-input option {
      background-color: #0b1628;
      color: #e2e8f0;
    }
    .toolbar-btn { padding: 5px 10px; border-radius: 7px; font-size: .75rem; font-weight: 600; color: rgba(255,255,255,.55); background: rgba(255,255,255,.05); border: 1px solid rgba(255,255,255,.08); cursor: pointer; transition: background .15s; }
    .toolbar-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
    .status-option { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid rgba(255,255,255,.08); cursor: pointer; margin-bottom: 8px; transition: border-color .15s, background .15s; }
    .status-option.selected { border-color: rgba(128,101,248,.4); background: rgba(128,101,248,.1); }
    .status-option input { accent-color: #8065f8; margin-top: 2px; }
    .tag-chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 10px; border-radius: 99px; font-size: .75rem; font-weight: 600; background: rgba(128,101,248,.15); color: #c4b5fd; border: 1px solid rgba(128,101,248,.2); cursor: pointer; }
    .tag-chip .remove { opacity: .6; font-size: 1rem; line-height: 1; }
    .char-count { font-size: .7rem; color: rgba(255,255,255,.35); text-align: right; margin-top: 4px; }
    .char-count.char-warn { color: #fbbf24; }
    .seo-bar { height: 3px; border-radius: 99px; margin-top: 4px; transition: width .2s, background .2s; }
    .modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.75); z-index: 50; display: none; align-items: center; justify-content: center; }
    .modal-overlay.open { display: flex; }
    .modal-box { background: #0e1c30; border: 1px solid rgba(255,255,255,.1); border-radius: 20px; padding: 28px; max-width: 540px; width: 100%; margin: 0 16px; max-height: 90vh; overflow-y: auto; }
    @keyframes pulse { 0%,100%{opacity:1}50%{opacity:.4} }
    .pulse { animation: pulse 2s infinite; }
    .admin-flash { padding: 10px 16px; border-radius: 10px; font-size: .8125rem; margin-bottom: 16px; }
    .admin-flash-success { background: rgba(16,185,129,.12); border: 1px solid rgba(16,185,129,.25); color: #34d399; }
    .admin-flash-error { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.25); color: #f87171; }
    .sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
    @media (max-width: 767px) {
      .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        z-index: 40;
        transform: translateX(-100%);
        transition: transform .2s ease-out;
        box-shadow: 8px 0 32px rgba(0,0,0,.35);
      }
      .sidebar.admin-sidebar-open { transform: translateX(0); }
      body.admin-nav-open { overflow: hidden; }
    }
    .admin-main { padding: 1rem; }
    @media (min-width: 640px) {
      .admin-main { padding: 1.5rem; }
    }
    .admin-stat-grid {
      display: grid;
      grid-template-columns: 1fr;
      gap: .75rem;
      margin-bottom: 1.5rem;
    }
    @media (min-width: 451px) {
      .admin-stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
    }
    @media (min-width: 1024px) {
      .admin-stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    }
    .admin-feed-list { display: flex; flex-direction: column; }
    .admin-feed-row {
      display: flex;
      align-items: center;
      gap: .75rem;
      padding: .75rem 0;
      border-bottom: 1px solid rgba(255,255,255,.05);
      text-decoration: none;
      color: inherit;
      transition: background .12s;
    }
    .admin-feed-row:first-child { padding-top: 0; }
    .admin-feed-row:last-child { border-bottom: none; padding-bottom: 0; }
    .admin-feed-row:hover { background: rgba(255,255,255,.03); border-radius: 10px; margin: 0 -.5rem; padding-left: .5rem; padding-right: .5rem; }
    .admin-feed-main { display: flex; align-items: center; gap: .75rem; flex: 1; min-width: 0; }
    .admin-feed-thumb {
      width: 2.5rem;
      height: 2.5rem;
      border-radius: .5rem;
      flex-shrink: 0;
      object-fit: cover;
    }
    .admin-feed-thumb-placeholder {
      width: 2.5rem;
      height: 2.5rem;
      border-radius: .5rem;
      flex-shrink: 0;
      background: linear-gradient(135deg,rgba(128,101,248,.3),rgba(68,144,211,.3));
    }
    .admin-feed-body { min-width: 0; flex: 1; }
    .admin-feed-title {
      font-size: .75rem;
      font-weight: 600;
      color: #fff;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .admin-feed-meta {
      font-size: .625rem;
      margin-top: 2px;
      color: rgba(255,255,255,.35);
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    .admin-feed-row .badge { flex-shrink: 0; }

    .admin-stat-chip {
      display: flex;
      align-items: center;
      gap: .75rem;
      padding: 12px 16px !important;
    }
    .admin-filter-input {
      background: rgba(255,255,255,.07);
      border: 1px solid rgba(255,255,255,.1);
      color: rgba(255,255,255,.8);
      outline: none;
    }
    .admin-filter-input:focus {
      border-color: rgba(128,101,248,.45);
      box-shadow: 0 0 0 3px rgba(128,101,248,.12);
    }
    select.admin-filter-input {
      color-scheme: dark;
      background-color: #0b1628;
      color: rgba(255,255,255,.85);
    }
    select.admin-filter-input option {
      background-color: #0b1628;
      color: #e2e8f0;
    }
    .admin-table-card .card { padding: 0; }
    .admin-post-cards { border-top: 1px solid rgba(255,255,255,.06); }
    .admin-post-card {
      padding: 1rem;
      border-bottom: 1px solid rgba(255,255,255,.06);
    }
    .admin-post-card:last-child { border-bottom: none; }
    .admin-post-card-head {
      display: flex;
      align-items: flex-start;
      justify-content: space-between;
      gap: .75rem;
      margin-bottom: .625rem;
    }
    .admin-post-card-meta {
      display: flex;
      flex-wrap: wrap;
      align-items: center;
      gap: .5rem .625rem;
      margin-bottom: .75rem;
    }
    .admin-post-card-actions {
      display: flex;
      align-items: center;
      gap: .5rem;
    }
    .admin-table-scroll {
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
      max-width: 100%;
    }
    .admin-data-table {
      width: 100%;
      min-width: 1050px;
      table-layout: auto;
    }
    .admin-data-table th,
    .admin-data-table td {
      white-space: nowrap;
      vertical-align: middle;
    }
    .admin-data-table .col-title {
      white-space: normal;
      min-width: 260px;
      max-width: 380px;
    }
    .admin-data-table .col-title .admin-table-title,
    .admin-data-table .col-title .admin-table-slug {
      display: block;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      max-width: 100%;
    }
    .admin-data-table .col-actions {
      width: 1%;
    }
    .admin-data-table .col-actions .flex {
      flex-wrap: nowrap;
    }
    @media (max-width: 450px) {
      .card { padding: 14px; border-radius: 12px; }
      .stat-card .text-2xl { font-size: 1.25rem; line-height: 1.75rem; }
      .admin-topbar-actions .btn-primary,
      .admin-topbar-actions .btn-ghost { width: 100%; justify-content: center; }
      .admin-feed-row { gap: .625rem; }
      .admin-feed-main { gap: .625rem; }
      .admin-feed-thumb,
      .admin-feed-thumb-placeholder { width: 2.25rem; height: 2.25rem; }
      .admin-post-card { padding: .875rem; }
      .admin-post-card-actions .btn-sm { min-height: 2rem; }
    }
  </style>
  <% if (typeof adminStyles !== 'undefined' && adminStyles) { %><%- adminStyles %><% } %>
</head>
<body class="flex h-screen overflow-hidden">
  <%- include('../partials/adminSidebar') %>
  <div class="flex-1 flex flex-col min-w-0 overflow-hidden">
    <%- body %>
  </div>
  <% if (typeof useFilePicker !== 'undefined' && useFilePicker) { %>
  <script src="/js/admin-file-picker.js"></script>
  <% } %>
  <script src="/js/admin-nav.js" defer></script>
  <% if (typeof adminScript !== 'undefined' && adminScript) { %>
  <script src="<%= adminScript %>"></script>
  <% } %>
</body>
</html>
