:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --primary: #6c5ce7;
  --primary-hover: #7d6ff0;
  --success: #00b894;
  --danger: #d63031;
  --warning: #fdcb6e;
  --text: #dfe6e9;
  --text-muted: #636e72;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }

nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}

nav .brand { font-weight: 700; font-size: 1.2em; color: var(--primary); }
nav a { color: var(--text-muted); padding: 6px 12px; border-radius: 6px; }
nav a:hover, nav a.active { color: var(--text); background: var(--border); }
nav .spacer { flex: 1; }

/* Nav dropdown menus — keeps the top bar from getting too crowded.
   Hover-to-open on desktop; click also toggles via a tiny inline script
   in layout-head.ejs (added after the nav). */
.nav-dropdown { position: relative; }
.nav-dropdown-toggle {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: 6px;
  font: inherit;
  font-size: inherit;
  cursor: pointer;
}
.nav-dropdown-toggle:hover,
.nav-dropdown.open .nav-dropdown-toggle {
  color: var(--text);
  background: var(--border);
}
.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 180px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 2px;
  z-index: 200;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown.open .nav-dropdown-menu {
  display: flex;
}
.nav-dropdown-menu a {
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
}
.nav-dropdown-section {
  font-size: 0.7em;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 6px 10px 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.nav-dropdown-section:not(:first-child) {
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.nav-dropdown-tag {
  font-size: 0.85em;
  background: rgba(108, 92, 231, 0.18);
  color: var(--primary);
  padding: 1px 6px;
  border-radius: 50px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

/* Cards */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin: 24px 0;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  text-align: center;
}

.stat-card .value {
  font-size: 2em;
  font-weight: 700;
  color: var(--primary);
}

.stat-card .label {
  color: var(--text-muted);
  font-size: 0.85em;
  margin-top: 4px;
}

/* Tables */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  margin: 16px 0;
}

th, td {
  padding: 12px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  background: rgba(108, 92, 231, 0.1);
  color: var(--primary);
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

tr:hover { background: rgba(255, 255, 255, 0.02); }

tr.since-payout { background: rgba(108, 92, 231, 0.12); box-shadow: inset 3px 0 0 var(--primary); }
tr.since-payout:hover { background: rgba(108, 92, 231, 0.18); }

/* Payout breakdown panel */
.bd-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.bd-heading { color: var(--text-muted); margin-bottom: 8px; font-weight: 600; }
.bd-table { display: grid; grid-template-columns: 1fr auto auto; column-gap: 16px; row-gap: 4px; font-variant-numeric: tabular-nums; }
.bd-table .bd-label { color: var(--text-muted); }
.bd-table .bd-math { color: var(--text-muted); text-align: right; font-size: 0.9em; }
.bd-table .bd-amount { text-align: right; min-width: 64px; }
.bd-total-row { display: contents; }
.bd-total-row > div { padding-top: 6px; border-top: 1px solid var(--border); margin-top: 2px; }
@media (max-width: 700px) { .bd-grid { grid-template-columns: 1fr; } }

/* Forms */
.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 6px;
  color: var(--text-muted);
  font-size: 0.85em;
  font-weight: 600;
}

input, textarea, select {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95em;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 18px;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9em;
  font-weight: 600;
  transition: 0.15s;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-info { background: #0984e3; color: white; }
.btn-info:hover { background: #1b95f2; }
.btn-secondary { background: #4b5563; color: white; }
.btn-secondary:hover { background: #5b6574; }
.btn:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}
.btn-sm { padding: 4px 12px; font-size: 0.8em; }

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 50px;
  font-size: 0.75em;
  font-weight: 600;
}

.badge-success { background: rgba(0, 184, 148, 0.2); color: var(--success); }
.badge-warning { background: rgba(253, 203, 110, 0.2); color: var(--warning); }
.badge-danger { background: rgba(214, 48, 49, 0.2); color: var(--danger); }
.badge-info { background: rgba(9, 132, 227, 0.18); color: #74b9ff; }

.backfill-dry-run {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.4;
  max-width: 420px;
}
.backfill-dry-run code {
  font-size: 11px;
  color: var(--text);
}
.backfill-candidate {
  margin-top: 3px;
}

/* Card form */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  margin: 16px 0;
}

.card h3 { margin-bottom: 16px; }

/* Filter bar */
.filter-bar {
  display: flex;
  gap: 8px;
  margin: 16px 0;
}

.filter-bar a {
  padding: 6px 16px;
  border-radius: 50px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85em;
}

.filter-bar a.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

/* Image thumbnails */
.thumb {
  width: 60px;
  height: 60px;
  object-fit: cover;
  border-radius: 8px;
}
.js-lightbox-thumb { cursor: zoom-in; }

/* In-page image viewer */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  z-index: 9999;
  align-items: center;
  justify-content: center;
}
.lightbox-overlay.open { display: flex; }
.lightbox-img {
  max-width: 92vw;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.6);
  background: #111;
}
.lightbox-close,
.lightbox-prev,
.lightbox-next {
  position: absolute;
  background: rgba(255, 255, 255, 0.14);
  border: none;
  color: #fff;
  cursor: pointer;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  line-height: 1;
}
.lightbox-close:hover,
.lightbox-prev:hover,
.lightbox-next:hover { background: rgba(255, 255, 255, 0.28); }
.lightbox-close { top: 18px; right: 18px; font-size: 24px; }
.lightbox-prev { left: 18px; top: 50%; transform: translateY(-50%); }
.lightbox-next { right: 18px; top: 50%; transform: translateY(-50%); }
.lightbox-counter {
  position: absolute;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  padding: 4px 12px;
  border-radius: 14px;
  font-size: 13px;
}

/* Login page */
.login-wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 24px;
  color: var(--primary);
}

.login-choice-box {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-choice-btn {
  display: block;
  width: 100%;
  text-align: center;
  background: var(--border);
  color: var(--text);
}

.error-msg {
  background: rgba(214, 48, 49, 0.15);
  color: var(--danger);
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 16px;
  text-align: center;
}

h1, h2 { margin-bottom: 8px; }

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.page-header h1 {
  margin-bottom: 2px;
}

.page-header p {
  color: var(--text-muted);
  font-size: 0.9em;
}

.submission-rate {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 4px 12px;
  border: 1px solid rgba(0, 184, 148, 0.35);
  border-radius: 999px;
  background: rgba(0, 184, 148, 0.14);
  color: var(--success);
  font-size: 0.85em;
  font-weight: 700;
  white-space: nowrap;
}

.inline-form { display: inline; }

.reject-form {
  display: inline-flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
  max-width: 280px;
  margin: 0 4px 6px 0;
  vertical-align: top;
}

.reject-form textarea {
  min-height: 52px;
  padding: 8px 10px;
  font-size: 0.85em;
  resize: vertical;
}

.review-comment {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: 0.85em;
  line-height: 1.4;
  max-width: 320px;
  white-space: pre-wrap;
}

.character-submission-list {
  display: grid;
  gap: 14px;
  margin: 16px 0 28px;
}

.character-submission-card {
  display: grid;
  grid-template-columns: minmax(210px, 0.85fr) minmax(320px, 1.4fr) minmax(260px, 320px);
  gap: 18px;
  align-items: stretch;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.submission-info {
  min-width: 0;
}

.submission-overline {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  color: var(--text-muted);
  font-size: 0.84em;
  line-height: 1.4;
}

.submission-overline time {
  overflow-wrap: anywhere;
}

.submission-user {
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.submission-separator {
  color: var(--border);
}

.submission-character {
  margin: 6px 0 10px;
  font-size: 1.35em;
  line-height: 1.2;
  overflow-wrap: anywhere;
}

.submission-meta-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.submission-earning,
.submission-image-count {
  color: var(--text-muted);
  font-size: 0.86em;
  font-weight: 700;
}

.submission-earning {
  color: var(--text);
}

.review-comment-card {
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(15, 17, 23, 0.56);
}

.review-comment-label {
  display: block;
  margin-bottom: 3px;
  color: var(--text);
  font-size: 0.78em;
  font-weight: 700;
  text-transform: uppercase;
}

.submission-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(92px, 1fr));
  align-content: start;
  gap: 8px;
  min-width: 0;
}

.submission-thumb {
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
  border: 1px solid var(--border);
  background: var(--bg);
}

.submission-thumb:hover {
  border-color: rgba(108, 92, 231, 0.7);
  transform: translateY(-1px);
}

.submission-empty-gallery,
.submission-empty-state {
  padding: 22px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: rgba(15, 17, 23, 0.42);
  color: var(--text-muted);
  text-align: center;
}

.submission-review-panel {
  display: grid;
  align-content: start;
  gap: 10px;
  min-width: 0;
}

.review-primary-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.review-form {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.review-form .btn,
.review-primary-actions > .btn {
  width: 100%;
  text-align: center;
}

.review-note-form textarea {
  min-height: 58px;
  padding: 8px 10px;
  font-size: 0.86em;
  resize: vertical;
}

.review-note-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.submission-filter-bar {
  flex-wrap: wrap;
  align-items: center;
}

.submission-filter-bar a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.filter-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 0.78em;
  text-align: center;
}

.submission-filter-bar a.active .filter-count {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.nav-user {
  color: var(--text-muted);
  font-size: 0.9em;
}

.flash {
  margin-top: 0;
  padding: 12px 16px;
}

.flash-success {
  border-left: 3px solid var(--success);
  color: var(--success);
}

.flash-error {
  border-left: 3px solid var(--danger);
  color: var(--danger);
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin: 20px 0;
}

.user-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.user-item {
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-item-claimed {
  border-color: rgba(0, 184, 148, 0.45);
}

.user-item h3 {
  margin: 0;
  font-size: 1.05em;
}

.user-item p {
  color: var(--text-muted);
  font-size: 0.9em;
}

.user-item-media {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
  min-height: 118px;
}

.user-item-media img,
.empty-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.empty-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  grid-column: 1 / -1;
}

.empty-state {
  color: var(--text-muted);
}

.claim-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 14px;
}

.claim-card h3 {
  margin-bottom: 4px;
}

.claim-card p {
  color: var(--text-muted);
  font-size: 0.9em;
}

.claim-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.claim-actions {
  margin-top: 10px;
}

.claim-form {
  display: grid;
  gap: 8px;
  max-width: 640px;
}

.claim-form label {
  color: var(--text-muted);
  font-size: 0.85em;
  font-weight: 600;
}

.edit-request-card h2 {
  margin: 0;
  font-size: 1.2em;
}

.edit-request-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 10px;
}

.edit-request-header p {
  color: var(--text-muted);
  font-size: 0.9em;
  margin-top: 4px;
}

.edit-request-earnings {
  color: var(--primary);
  font-weight: 700;
  font-size: 1.1em;
  white-space: nowrap;
}

.edit-request-comment {
  max-width: 720px;
  margin-bottom: 16px;
}

.edit-request-form {
  max-width: 760px;
}

.edit-image-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.edit-image-item {
  width: 112px;
  display: grid;
  gap: 6px;
}

.edit-image-thumb {
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  cursor: zoom-in;
}

.edit-image-keep {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 0.85em;
}

.edit-image-keep input {
  width: auto;
}

@media (max-width: 800px) {
  nav {
    flex-wrap: wrap;
    gap: 8px;
  }
  nav .spacer {
    flex-basis: 100%;
  }
  table {
    display: block;
    overflow-x: auto;
  }

  .page-header,
  .character-submission-card {
    grid-template-columns: 1fr;
  }

  .page-header {
    display: grid;
  }

  .submission-rate {
    justify-self: start;
  }

  .submission-gallery {
    grid-template-columns: repeat(auto-fill, minmax(78px, 1fr));
  }
}

.char-source-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 150px;
}

.char-source-cell strong {
  max-width: 180px;
  overflow-wrap: anywhere;
}

/* Subreddit multi-select picker */
.sub-picker {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.sub-picker-header {
  display: flex;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.sub-picker-search {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.9em;
}

.sub-picker-count {
  color: var(--text-muted);
  font-size: 0.8em;
  padding: 0 8px;
  white-space: nowrap;
}

.sub-picker-options {
  max-height: 220px;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.sub-picker-option {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 50px;
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.85em;
  user-select: none;
  transition: 0.15s;
}

.sub-picker-option:hover {
  border-color: var(--primary);
}

.sub-picker-option input {
  width: auto;
  margin: 0;
  accent-color: var(--primary);
}

.sub-picker-option:has(input:checked) {
  background: rgba(108, 92, 231, 0.18);
  border-color: var(--primary);
  color: var(--text);
}

.sub-picker-empty {
  padding: 12px;
  background: var(--bg);
  border: 1px dashed var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  font-size: 0.9em;
}

/* Popup window mode (chrome stripped so the form fills the popup). */
body.popup-mode .container {
  padding: 16px;
  max-width: 100%;
}

/* Character pool: per-row kebab + modal for editing default subreddits. */
.char-kebab {
  font-size: 1.1em;
  line-height: 1;
  padding: 4px 10px;
}
.char-subs-dialog {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  max-width: 640px;
  width: 90vw;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
}
.char-subs-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}
.char-subs-dialog-form {
  padding: 20px;
}
.char-subs-dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
