/* ── Variables & Reset ────────────────────────────────────────────────────── */
:root {
  --primary:     #3b82f6;
  --primary-dk:  #2563eb;
  --danger:      #ef4444;
  --danger-dk:   #dc2626;
  --success-txt: #15803d;
  --success-bg:  #f0fdf4;
  --success-bd:  #bbf7d0;
  --error-txt:   #b91c1c;
  --error-bg:    #fef2f2;
  --error-bd:    #fecaca;
  --bg:          #f1f5f9;
  --card:        #ffffff;
  --text:        #0f172a;
  --muted:       #64748b;
  --border:      #e2e8f0;
  --radius:      10px;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}

/* ── Centered layout (index & login pages) ────────────────────────────────── */
.center-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.center-page .card {
  width: 100%;
  max-width: 430px;
}

/* ── Card ─────────────────────────────────────────────────────────────────── */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2rem 2.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.card-icon {
  font-size: 2.25rem;
  margin-bottom: .5rem;
  display: block;
}

.card h1 {
  font-size: 1.45rem;
  font-weight: 700;
  margin-bottom: .3rem;
}

.card h2 {
  font-size: 1.05rem;
  font-weight: 600;
  margin-bottom: .25rem;
}

.subtitle {
  color: var(--muted);
  font-size: .9rem;
  margin-bottom: 1.5rem;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
label {
  display: block;
  font-weight: 600;
  font-size: .85rem;
  margin-bottom: .35rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="file"] {
  display: block;
  width: 100%;
  padding: .6rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 1rem;
  background: #fff;
  color: var(--text);
  margin-bottom: 1rem;
  transition: border-color .15s, box-shadow .15s;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}

/* Monospaced code input */
.code-input {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.4rem;
  letter-spacing: .2em;
  text-align: center;
  text-transform: uppercase;
  padding: .7rem;
}

/* Newsletter opt-in row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: .5rem;
  margin: .75rem 0 .25rem;
}
.checkbox-row input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
  flex-shrink: 0;
  cursor: pointer;
}
.checkbox-row label {
  display: inline;
  font-size: .9rem;
  font-weight: 400;
  margin: 0;
  cursor: pointer;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .35rem;
  padding: .6rem 1.2rem;
  border-radius: 6px;
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  border: 1.5px solid transparent;
  transition: background .15s, border-color .15s, color .15s;
  white-space: nowrap;
  line-height: 1.4;
}

.btn-full {
  width: 100%;
  margin-top: .5rem;
  padding: .75rem;
  font-size: 1rem;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}
.btn-primary:hover {
  background: var(--primary-dk);
  border-color: var(--primary-dk);
}

.btn-outline {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}
.btn-danger:hover {
  background: var(--danger-dk);
  border-color: var(--danger-dk);
}

.btn-sm {
  padding: .3rem .65rem;
  font-size: .8rem;
}

/* ── Flash alerts ─────────────────────────────────────────────────────────── */
.alert {
  padding: .7rem 1rem;
  border-radius: 6px;
  margin-bottom: 1rem;
  font-size: .9rem;
  font-weight: 500;
  border: 1px solid transparent;
}

.alert-error {
  background: var(--error-bg);
  color: var(--error-txt);
  border-color: var(--error-bd);
}

.alert-success {
  background: var(--success-bg);
  color: var(--success-txt);
  border-color: var(--success-bd);
}

/* ── Admin full-page layout ───────────────────────────────────────────────── */
.admin-layout {
  max-width: 1020px;
  margin: 0 auto;
  padding: 1.5rem 1.5rem 3rem;
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.admin-header h1 {
  font-size: 1.35rem;
}

.header-actions {
  display: flex;
  gap: .75rem;
}

.back-link {
  display: block;
  color: var(--muted);
  font-size: .82rem;
  text-decoration: none;
  margin-bottom: .15rem;
}
.back-link:hover { color: var(--primary); }

main > * + * {
  margin-top: 1.25rem;
}

/* ── Form row ─────────────────────────────────────────────────────────────── */
.form-row {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.form-group { flex: 1 1 220px; }
.form-group-sm { flex: 0 0 160px; }

/* ── Data table ───────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: .9rem;
}

.table th {
  text-align: left;
  padding: .55rem .75rem;
  font-size: .775rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: .65rem .75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.table tbody tr:hover {
  background: #f8fafc;
}

.filename-cell {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.actions {
  display: flex;
  gap: .5rem;
}

.muted          { color: var(--muted); }
.used-count     { color: var(--muted); }
.remaining-count { color: #16a34a; font-weight: 700; }
.download-count  { color: #1d4ed8; font-weight: 700; }

/* ── Section header (title + action button on same row) ──────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .25rem;
}

.section-header h2 { margin-bottom: 0; }

/* ── Redemption report ────────────────────────────────────────────────────── */
.report-filter-form { margin-bottom: 0; }

.report-select {
  display: block;
  width: 100%;
  padding: .6rem .8rem;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  background: #fff;
  color: var(--text);
  margin-bottom: 0;
}

.report-export-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 0;
}

.report-table .report-code {
  font-family: "Courier New", Courier, monospace;
  font-size: .85rem;
  letter-spacing: .06em;
  white-space: nowrap;
}

.report-table .report-email {
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--primary);
  font-weight: 600;
  font-size: .85rem;
}

.report-never {
  color: var(--muted);
  font-style: italic;
  font-size: .82rem;
}

.report-row-pending td { opacity: .75; }

.empty-state {
  text-align: center;
  padding: 2.5rem 1rem;
  font-size: .95rem;
}

/* ── Stats row (codes page) ───────────────────────────────────────────────── */
.stats-row {
  display: flex;
  gap: 1rem;
}

.stat-card {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
}

.stat-num {
  display: block;
  font-size: 2rem;
  font-weight: 800;
  line-height: 1.2;
}

.stat-label {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Config list (publishers / genres) ───────────────────────────────────── */
.config-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.config-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem 0;
  border-bottom: 1px solid var(--border);
  font-size: .9rem;
}

.config-list-item:last-child {
  border-bottom: none;
}

/* ── Print hint ───────────────────────────────────────────────────────────── */
.print-hint {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 6px;
  padding: .7rem 1rem;
  font-size: .875rem;
  color: #1e40af;
}

/* ── Generate more codes (collapsible) ───────────────────────────────────── */
.generate-more {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 1px 4px rgba(0,0,0,.06);
}

.generate-more > summary {
  list-style: none;
  cursor: pointer;
  padding: .85rem 1.25rem;
  font-weight: 600;
  font-size: .9rem;
  color: var(--primary);
  user-select: none;
}

.generate-more > summary::-webkit-details-marker { display: none; }

.generate-more[open] > summary {
  border-bottom: 1px solid var(--border);
}

.generate-more-body {
  padding: 1rem 1.25rem 1.25rem;
}

.generate-more-form label {
  font-size: .85rem;
  font-weight: 600;
  margin-bottom: .4rem;
}

/* ── Redemption code tickets ──────────────────────────────────────────────── */
.print-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(185px, 1fr));
  gap: .75rem;
  margin-top: 1rem;
}

.code-ticket {
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: .9rem .75rem;
  text-align: center;
  background: var(--card);
}

.code-ticket.available {
  border-color: #93c5fd;
  background: #eff6ff;
}

.code-ticket.used {
  border-color: var(--border);
  background: #f8fafc;
  opacity: .5;
}

.code-ticket.revoked {
  border-color: #fca5a5;
  background: #fef2f2;
  opacity: .75;
}

.code-ticket.revoked .ticket-code {
  color: #dc2626;
  text-decoration: line-through;
}

.ticket-label {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
  margin-bottom: .3rem;
}

.ticket-code {
  font-family: "Courier New", Courier, monospace;
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: .12em;
  color: var(--text);
  margin: .25rem 0;
}

.code-ticket.used .ticket-code {
  color: var(--muted);
  text-decoration: line-through;
}

.ticket-note {
  font-size: .72rem;
  color: var(--muted);
}

.code-ticket.available .ticket-note {
  color: #16a34a;
}

.ticket-email {
  font-size: .72rem;
  color: var(--primary);
  word-break: break-all;
  margin: .25rem 0 .1rem;
  font-weight: 600;
}

.ticket-history {
  font-size: .65rem;
  color: var(--muted);
  margin-bottom: .1rem;
}

.ticket-dl-count {
  font-size: .72rem;
  font-weight: 700;
  color: #1d4ed8;
  margin: .15rem 0 .1rem;
}

.reactivate-btn {
  width: 100%;
  font-size: .7rem;
  padding: .25rem .5rem;
}
