/* =========================================================================
   Pure Rank Admin — Control Panel
   Visual identity mirrors the public Pure Rank site (Anton + Space Mono,
   red / ink / gold / paper) rather than a generic dark-SaaS dashboard.
   Google Fonts are loaded from base.html; CSP allows only the two Google
   Fonts hosts needed for that (see app.py set_security_headers). No
   backend/auth/draft/publish logic lives in this file.
   ========================================================================= */

:root {
  --red: #D6142B;
  --red-dark: #A80F22;
  --gold: #F0B62C;
  --ink: #1A1414;
  --mural: #171414;
  --paper: #FFFFFF;
  --paper-dim: #F7F3EE;

  --bg: var(--mural);
  --surface: #221D1D;
  --surface-2: #2A2222;
  --border: #3B2F2F;
  --text: var(--paper-dim);
  --muted: #B7A9A4;
  --accent: var(--gold);
  --error: #F0554A;
  --info: #6FA9E8;
  --warn: var(--gold);

  --font-display: 'Anton', 'Arial Narrow', sans-serif;
  --font-body: 'Space Mono', 'SFMono-Regular', Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3, .pr-brand, .tile-label, .record-name, .detail-name,
.top-bar-title, .btn-primary, .badge, .dashboard-eyebrow, .pr-step-label {
  font-family: var(--font-display);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  font-weight: 400;
}

a { color: var(--gold); }

/* ---------- Shared shell / nav ---------- */

.pr-shell { min-height: 100vh; display: flex; flex-direction: column; }

.pr-nav {
  background: var(--ink);
  border-bottom: 3px solid var(--red);
  position: sticky;
  top: 0;
  z-index: 20;
}

.pr-nav-inner {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 18px;
  min-height: 60px;
  flex-wrap: wrap;
}

.pr-brand {
  color: var(--paper);
  text-decoration: none;
  font-size: 1.15rem;
  white-space: nowrap;
}

.pr-brand span { color: var(--red); }

.pr-nav-toggle {
  display: none;
  margin-left: auto;
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
  cursor: pointer;
}

.pr-nav-toggle span {
  display: block;
  width: 20px;
  height: 2px;
  background: var(--paper);
}

.pr-nav-links {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  flex-wrap: wrap;
}

.pr-nav-links a {
  color: var(--muted);
  text-decoration: none;
  font-family: var(--font-body);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 10px 12px;
  border-radius: 6px;
  border-bottom: 2px solid transparent;
}

.pr-nav-links a:hover { color: var(--paper); }

.pr-nav-links a.active {
  color: var(--paper);
  border-bottom: 2px solid var(--red);
}

.pr-nav-logout { margin: 0 0 0 6px; }

.pr-content { flex: 1; }

/* ---------- Login ---------- */

.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--mural);
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: 4px solid var(--red);
  border-radius: 4px;
  padding: 32px 24px;
}

.auth-card h1 {
  margin: 0 0 6px;
  font-size: 1.7rem;
  color: var(--paper);
}

.auth-sub {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 0.9rem;
}

form label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.82rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

form input[type="password"],
form input[type="text"] {
  width: 100%;
  padding: 14px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 16px;
}

form input:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.btn-primary {
  width: 100%;
  padding: 15px;
  font-size: 1.05rem;
  border: none;
  border-radius: 4px;
  background: var(--red);
  color: var(--paper);
  cursor: pointer;
  letter-spacing: 0.03em;
}

.btn-primary:hover { background: var(--red-dark); }
.btn-primary:active { opacity: 0.85; }

.notice {
  padding: 12px 14px;
  border-radius: 4px;
  font-size: 0.88rem;
  margin-bottom: 16px;
  border-left: 3px solid transparent;
}

.notice-error { background: rgba(240,85,74,0.14); color: var(--error); border-color: var(--error); }
.notice-info  { background: rgba(111,169,232,0.14); color: var(--info); border-color: var(--info); }
.notice-warn  { background: rgba(240,182,44,0.14); color: var(--gold); border-color: var(--gold); }

/* ---------- Dashboard ---------- */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.top-bar-title {
  font-size: 1.15rem;
  color: var(--paper);
}

.btn-logout {
  padding: 9px 16px;
  font-size: 0.78rem;
  font-family: var(--font-body);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.btn-logout:hover { color: var(--paper); border-color: var(--paper); }

.dashboard {
  padding: 28px 18px 40px;
  max-width: 720px;
  margin: 0 auto;
}

.dashboard-eyebrow {
  color: var(--red);
  font-size: 0.9rem;
  margin: 0 0 4px;
}

.dashboard-intro {
  color: var(--muted);
  font-size: 0.88rem;
  margin: 0 0 22px;
  max-width: 46em;
}

.tile-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 4px solid var(--red);
  border-radius: 4px;
  padding: 22px 16px;
  min-height: 92px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  transition: border-color 0.15s, background 0.15s;
}

.tile:hover { background: var(--surface-2); border-left-color: var(--gold); }

.tile-disabled { opacity: 0.5; border-left-color: var(--border); }

.tile-label {
  font-size: 1.05rem;
  color: var(--paper);
}

.tile-status {
  font-size: 0.78rem;
  color: var(--muted);
  font-family: var(--font-body);
  text-transform: none;
}

@media (min-width: 700px) {
  .tile-grid { grid-template-columns: 1fr 1fr 1fr; }
}

.tile { text-decoration: none; color: inherit; }

.back-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.back-link:hover { color: var(--gold); }

/* ---------- List pages ---------- */

.list-page {
  padding: 20px 16px 40px;
  max-width: 760px;
  margin: 0 auto;
}

.search-bar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 16px;
}

.search-bar input[type="search"],
.search-bar select {
  width: 100%;
  padding: 13px 12px;
  font-size: 16px;
  font-family: var(--font-body);
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.btn-compact { padding: 12px; }

.result-count {
  color: var(--muted);
  font-size: 0.82rem;
  margin: 0 0 14px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.record-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.record-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid transparent;
  border-radius: 4px;
  padding: 14px 16px;
  text-decoration: none;
  color: var(--text);
  transition: border-left-color 0.15s, background 0.15s;
}

.record-card:hover { border-left-color: var(--red); background: var(--surface-2); }

.record-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 3px;
}

.record-name { font-size: 1.05rem; color: var(--paper); }
.record-title { color: var(--muted); font-size: 0.85rem; }

.record-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.meta-chip {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.72rem;
  color: var(--muted);
}

.meta-chip-derived {
  color: var(--gold);
  background: rgba(240,182,44,0.1);
  border-color: rgba(240,182,44,0.3);
}

.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 3px;
  font-size: 0.68rem;
  letter-spacing: 0.05em;
}

.badge-current { background: var(--red); color: var(--paper); }
.badge-derived { background: rgba(240,182,44,0.16); color: var(--gold); }

.empty-state { color: var(--muted); padding: 24px 0; font-size: 0.92rem; }

/* ---------- Detail pages ---------- */

.detail-page {
  padding: 20px 16px 48px;
  max-width: 760px;
  margin: 0 auto;
}

.detail-name { margin: 8px 0 2px; font-size: 1.7rem; color: var(--paper); }
.detail-title { margin: 0 0 14px; color: var(--muted); font-size: 0.9rem; }

.badge-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}

.field-block {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 18px 16px;
  margin-bottom: 16px;
}

.field-block h2 {
  margin: 0 0 14px;
  font-size: 1rem;
  color: var(--paper);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.hint { color: var(--muted); font-size: 0.72rem; font-weight: 400; text-transform: none; letter-spacing: 0; font-family: var(--font-body); }

.field-list {
  display: grid;
  grid-template-columns: auto;
  gap: 4px 0;
  margin: 0;
}

.field-list dt {
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 700;
}

.field-list dt:first-child { margin-top: 0; }

.field-list dd {
  margin: 3px 0 0;
  word-break: break-word;
  font-size: 0.95rem;
}

.field-list a { color: var(--info); }

.rendered-preview {
  background: var(--surface-2);
  border-radius: 4px;
  padding: 10px 12px;
  margin: 6px 0 12px;
}

.raw-value {
  display: block;
  background: var(--surface-2);
  border-radius: 4px;
  padding: 10px 12px;
  font-size: 0.8rem;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--muted);
  font-family: var(--font-body);
}

/* ---------- Poll results ---------- */

.poll-result-table {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.poll-result-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.poll-result-pct {
  font-family: var(--font-body);
  font-size: 0.92rem;
}

.poll-bar-track {
  height: 10px;
  border-radius: 999px;
  background: var(--surface-2);
  overflow: hidden;
  margin-bottom: 4px;
}

.poll-bar-fill {
  height: 100%;
  background: var(--red);
}

.poll-result-row-winner .poll-result-pct { color: var(--gold); font-weight: 700; }
.poll-result-row-winner .poll-bar-fill { background: var(--gold); }

/* ---------- Stage 3: forms, drafts ---------- */

.field-block input[type="text"],
.field-block input[type="search"],
.field-block select,
.field-block textarea {
  width: 100%;
  padding: 13px 12px;
  font-size: 16px;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-top: 4px;
  font-family: var(--font-body);
}

.field-block input:focus,
.field-block select:focus,
.field-block textarea:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.field-block textarea { resize: vertical; }

.radio-row, .checkbox-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 0;
  font-size: 0.92rem;
}

.radio-row input, .checkbox-row input {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  accent-color: var(--red);
}

.add-new-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin: 16px 0;
}

.btn-add { text-align: center; text-decoration: none; }

.btn-danger {
  width: 100%;
  padding: 14px;
  font-size: 0.85rem;
  font-family: var(--font-body);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  border: 1px solid var(--error);
  background: transparent;
  color: var(--error);
  cursor: pointer;
  margin-bottom: 24px;
}

.btn-danger:hover { background: rgba(240,85,74,0.1); }

.top-bar .back-link + .back-link { margin-left: auto; }
.top-bar { gap: 12px; }

/* Generic secondary/ghost button, used across draft & publish screens */
.btn-secondary {
  display: inline-block;
  padding: 13px 18px;
  font-size: 0.85rem;
  font-family: var(--font-body);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

.btn-secondary:hover { border-color: var(--gold); color: var(--gold); }

/* ---------- Stage 4: poll editor ---------- */

.poll-edit-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.poll-edit-row:last-child { border-bottom: none; }

.poll-edit-row input[type="text"] {
  width: 100%;
  padding: 12px;
  font-size: 16px;
  font-family: var(--font-body);
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
}

.poll-edit-pct { font-family: var(--font-body); }

.poll-edit-winner, .poll-edit-remove {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--muted);
  padding: 6px 0;
}

.poll-edit-winner input, .poll-edit-remove input {
  width: 22px;
  height: 22px;
  accent-color: var(--red);
}

textarea[name="paste_text"] { font-family: var(--font-body); }

/* ---------- Stage 5: certificate upload ---------- */

.cert-preview {
  display: block;
  width: 100%;
  max-width: 320px;
  border-radius: 4px;
  border: 6px solid var(--paper);
  outline: 1px solid var(--border);
  margin: 8px auto;
  background: var(--paper);
}

input[type="file"] {
  width: 100%;
  padding: 10px 0;
  color: var(--text);
  font-size: 0.85rem;
  font-family: var(--font-body);
}

/* ---------- Phase 3: draft workflow step tracker ---------- */

.pr-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
  margin: 0 0 22px;
  padding: 0;
  list-style: none;
  width: 100%;
}

.pr-step {
  flex: 1 1 0;
  min-width: 0;
  text-align: center;
  position: relative;
  padding: 0 4px;
}

.pr-step::before {
  content: "";
  position: absolute;
  top: 13px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.pr-step:first-child::before { display: none; }

.pr-step-dot {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--border);
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 6px;
  font-family: var(--font-body);
  font-size: 0.75rem;
  font-weight: 700;
  position: relative;
  z-index: 1;
}

.pr-step-label {
  font-size: 0.62rem;
  color: var(--muted);
  letter-spacing: 0.02em;
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 420px) {
  .pr-step-dot { width: 20px; height: 20px; font-size: 0.65rem; margin-bottom: 4px; }
  .pr-step-label { font-size: 0.52rem; }
  .pr-step::before { top: 10px; }
}

.pr-step.done .pr-step-dot { background: var(--red); border-color: var(--red); color: var(--paper); }
.pr-step.done::before { background: var(--red); }
.pr-step.current .pr-step-dot { border-color: var(--gold); color: var(--gold); }
.pr-step.current .pr-step-label { color: var(--paper); font-weight: 700; }
.pr-step.failed .pr-step-dot {
  background: var(--surface);
  border: 2px dashed var(--error);
  color: var(--error);
  font-size: 0;
}
.pr-step.failed .pr-step-dot::after { content: "!"; font-size: 0.85rem; }
.pr-step.failed .pr-step-label { color: var(--error); font-weight: 700; }
.pr-step.failed::before { background: var(--error); }

/* ---------- Responsive nav ---------- */

@media (max-width: 760px) {
  .pr-nav-toggle { display: flex; }

  .pr-nav-links {
    display: none;
    width: 100%;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    margin: 10px 0 12px;
  }

  .pr-nav-links.open { display: flex; }

  .pr-nav-links a {
    padding: 12px 10px;
    border-bottom: 1px solid var(--border);
    border-radius: 0;
  }

  .pr-nav-links a.active { border-bottom: 1px solid var(--red); background: var(--surface); }

  .pr-nav-logout { width: 100%; margin: 6px 0 0; }
  .pr-nav-logout .btn-logout { width: 100%; }
}
