:root {
  --bg: #0d0d0d;
  --surface: #1a1a1a;
  --surface2: #242424;
  --border: #333;
  --accent: #c0392b;
  --accent2: #e74c3c;
  --gold: #f39c12;
  --text: #e8e8e8;
  --text-muted: #888;
  --owned: #27ae60;
  --radius: 8px;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

/* ── Header ─────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1a0000 0%, #2a0000 50%, #1a0000 100%);
  border-bottom: 2px solid var(--accent);
  padding: 16px 20px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 4px 20px rgba(0,0,0,0.8);
}

.header-top {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.app-title {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent2);
  text-transform: uppercase;
  white-space: nowrap;
}

.app-title span {
  color: var(--gold);
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  flex-wrap: wrap;
}

.collection-select {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 12px;
  font-size: 14px;
  cursor: pointer;
  min-width: 220px;
}

.collection-select:focus { outline: 1px solid var(--accent); }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { opacity: .85; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary   { background: var(--accent);  color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-sm        { padding: 4px 10px; font-size: 12px; }

/* ── Stats bar ─────────────────────────────── */
.stats-bar {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-label { color: var(--text-muted); font-size: 12px; }

.stat-count {
  font-size: 20px;
  font-weight: 800;
  color: var(--gold);
}

.stat-total { font-size: 14px; color: var(--text-muted); }

.progress-bar-wrap {
  flex: 1;
  min-width: 120px;
  max-width: 300px;
  height: 8px;
  background: var(--surface2);
  border-radius: 4px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--owned), #2ecc71);
  transition: width .4s ease;
  border-radius: 4px;
}

.progress-pct {
  font-size: 13px;
  color: var(--owned);
  font-weight: 700;
  min-width: 40px;
}

/* ── Filter bar ─────────────────────────────── */
.filter-bar {
  padding: 10px 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-input {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
  width: 220px;
}
.search-input:focus { outline: 1px solid var(--accent); }
.search-input::placeholder { color: var(--text-muted); }

.filter-label { color: var(--text-muted); font-size: 12px; }

.filter-btn {
  padding: 5px 12px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
  transition: all .15s;
}
.filter-btn.active,
.filter-btn:hover {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

/* ── Main content ─────────────────────────────── */
main {
  padding: 0;
}

.issue-list {
  width: 100%;
  border-collapse: collapse;
}

.issue-list thead {
  background: var(--surface);
  position: sticky;
  top: 0;
}

.issue-list th {
  padding: 10px 14px;
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.issue-list th.col-check { width: 50px; text-align: center; }
.issue-list th.col-cover { width: 80px; text-align: center; }
.issue-list th.col-num   { width: 80px; }
.issue-list th.col-date  { width: 120px; }
.issue-list th.col-price { width: 120px; }
.issue-list th.col-notes { }

.issue-row {
  border-bottom: 1px solid rgba(255,255,255,0.04);
  transition: background .1s;
}
.issue-row:hover { background: rgba(255,255,255,0.04); }
.issue-row.owned { background: rgba(39,174,96,0.06); }
.issue-row.owned:hover { background: rgba(39,174,96,0.10); }
.issue-row.is-reprint { opacity: .7; }

.issue-row td {
  padding: 10px 14px;
  vertical-align: middle;
}

/* Checkbox column */
.col-check { text-align: center; }

.own-checkbox {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--owned);
}

/* Cover column */
.cover-cell { text-align: center; padding: 6px 14px; }

.cover-img-wrap {
  width: 52px;
  height: 78px;
  margin: 0 auto;
  border-radius: 3px;
  overflow: hidden;
  background: var(--surface2);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: border-color .15s, box-shadow .15s;
}
.cover-img-wrap:hover {
  border-color: var(--accent);
  box-shadow: 0 0 8px rgba(192,57,43,0.4);
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: linear-gradient(160deg, #1a0000 0%, #2d0a0a 100%);
  padding: 4px;
  text-align: center;
  user-select: none;
}
.cover-placeholder .cover-series {
  font-size: 5px;
  font-weight: 800;
  color: var(--accent2);
  text-transform: uppercase;
  letter-spacing: .3px;
  line-height: 1.1;
}
.cover-placeholder .cover-num {
  font-size: 14px;
  font-weight: 900;
  color: var(--gold);
  margin-top: 2px;
  line-height: 1;
}
.cover-placeholder .cover-date-small {
  font-size: 5px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* Number column */
.issue-num {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
}
.reprint-badge {
  display: inline-block;
  font-size: 9px;
  background: #444;
  color: #aaa;
  border-radius: 3px;
  padding: 1px 4px;
  margin-left: 5px;
  vertical-align: middle;
  font-weight: 600;
  letter-spacing: .3px;
}

/* Date column */
.issue-date {
  color: var(--text-muted);
  font-size: 13px;
}

/* Price column */
.price-cell { white-space: nowrap; }

.price-value {
  font-weight: 700;
  color: var(--gold);
  font-size: 14px;
}
.price-na    { color: var(--text-muted); font-size: 12px; }
.price-loading { color: var(--text-muted); font-style: italic; font-size: 12px; }

.btn-fetch-price {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
  transition: all .15s;
}
.btn-fetch-price:hover {
  border-color: var(--gold);
  color: var(--gold);
}

/* ── Modal ─────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px;
  width: 480px;
  max-width: 95vw;
  max-height: 80vh;
  overflow-y: auto;
}

.modal h2 {
  font-size: 18px;
  margin-bottom: 20px;
  color: var(--text);
}

.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 6px; }
.form-group input {
  width: 100%;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-size: 14px;
}
.form-group input:focus { outline: 1px solid var(--accent); }

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
}

/* ── Sortable column headers ─────────────────────── */
.issue-list th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.issue-list th.sortable:hover { color: var(--text); }

.sort-arrow::after { content: '⇅'; color: var(--border); margin-left: 4px; font-size: 11px; }
th[data-sort-active="asc"]  .sort-arrow::after { content: '↑'; color: var(--gold); }
th[data-sort-active="desc"] .sort-arrow::after { content: '↓'; color: var(--gold); }

/* ── Actions column ──────────────────────────────── */
.col-actions { width: 44px; text-align: center; }

.btn-icon {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 15px;
  line-height: 1;
  opacity: 0;
  transition: opacity .15s, background .15s;
}
.issue-row:hover .btn-icon { opacity: 1; }

.btn-delete:hover { background: rgba(192,57,43,0.25); }

/* ── Change-cover button overlay ─────────────────── */
.btn-change-cover {
  position: absolute;
  top: 2px;
  right: 2px;
  background: rgba(0,0,0,0.7);
  border: none;
  color: #fff;
  font-size: 11px;
  width: 18px;
  height: 18px;
  border-radius: 3px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .15s;
  padding: 0;
  line-height: 1;
}
.cover-img-wrap:hover .btn-change-cover { opacity: 1; }

/* ── Form row (side-by-side fields) ──────────────── */
.form-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
}

/* ── Cover-change modal extras ───────────────────── */
.cover-or-divider {
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
  margin: 4px 0 12px;
}

.cover-preview-wrap {
  min-height: 40px;
  display: flex;
  justify-content: center;
  margin-bottom: 8px;
}

#cover-preview {
  max-height: 200px;
  max-width: 100%;
  border-radius: 4px;
  border: 1px solid var(--border);
  object-fit: contain;
}

/* ── Cover lightbox ─────────────────────────────── */
.lightbox-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 300;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.lightbox-overlay.open { display: flex; }

.lightbox-img {
  max-height: 90vh;
  max-width: 60vw;
  border-radius: 6px;
  box-shadow: 0 0 60px rgba(0,0,0,0.9);
}

/* ── Empty state ─────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state h3 { font-size: 20px; margin-bottom: 8px; color: var(--text); }

/* ── Loading overlay ────────────────────────── */
.loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 500;
  align-items: center;
  justify-content: center;
}
.loading-overlay.open { display: flex; }

.loading-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px 40px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent2);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-msg {
  font-size: 14px;
  color: var(--text-muted);
}

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

/* ── Responsive ─────────────────────────────── */
@media (max-width: 700px) {
  .issue-list th.col-date,
  .issue-list td:nth-child(4) { display: none; }
  .cover-img-wrap { width: 40px; height: 60px; }
  .col-actions { display: none; }
}

/* ── Header user area ───────────────────────── */
.header-user {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  flex-shrink: 0;
}

.user-badge {
  font-size: 13px;
  color: var(--text-muted);
  white-space: nowrap;
}

.admin-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 2px 5px;
  border-radius: 3px;
  letter-spacing: 0.5px;
  vertical-align: middle;
}

/* ── Auth modal ─────────────────────────────── */
.auth-modal-overlay {
  background: rgba(0,0,0,0.92);
  z-index: 1000;
}

.auth-modal {
  width: 420px;
  max-width: 95vw;
  text-align: center;
}

.auth-logo {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 1px;
  color: var(--accent2);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.auth-logo span { color: var(--gold); }

.auth-tagline {
  color: var(--text-muted);
  font-size: 13px;
  margin-bottom: 24px;
}

.auth-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--border);
}

.auth-tab {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  padding: 10px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.auth-tab.active {
  color: var(--accent2);
  border-bottom-color: var(--accent2);
}
.auth-tab:hover:not(.active) { color: var(--text); }

.auth-modal .form-group { text-align: left; }

.auth-error {
  background: rgba(192,57,43,0.15);
  border: 1px solid var(--accent);
  color: var(--accent2);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 14px;
  text-align: left;
}
.auth-error.auth-success {
  background: rgba(39,174,96,0.15);
  border-color: var(--owned);
  color: #2ecc71;
}

.auth-submit-btn {
  width: 100%;
  padding: 11px;
  font-size: 14px;
  margin-top: 4px;
}

/* ── Admin panel modal ──────────────────────── */
.admin-modal {
  width: 780px;
  max-width: 96vw;
  max-height: 85vh;
}

.modal-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-header-row h2 { margin-bottom: 0; }

.admin-table-wrap {
  overflow-x: auto;
}

.admin-user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.admin-user-table th {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.admin-user-table td {
  padding: 12px 12px;
  border-bottom: 1px solid var(--surface2);
  vertical-align: middle;
}
.admin-user-table tr:last-child td { border-bottom: none; }
.admin-user-table tr:hover td { background: var(--surface2); }

.admin-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.btn-danger {
  background: rgba(192,57,43,0.2);
  color: var(--accent2);
  border: 1px solid var(--accent);
}
.btn-danger:hover { background: rgba(192,57,43,0.4); }

/* ── Account modal ──────────────────────────── */
.account-modal {
  width: 440px;
  max-width: 95vw;
}

.account-info {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 14px;
}
.account-label {
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-right: 8px;
}
