:root {
  --primary:       #1e3a8a;
  --primary-hover: #1d4ed8;
  --accent:        #3b82f6;
  --bg:            #f1f5f9;
  --card:          #ffffff;
  --text:          #0f172a;
  --text-muted:    #64748b;
  --border:        #e2e8f0;
  --success:       #059669;
  --danger:        #dc2626;
  --radius:        12px;
  --shadow:        0 1px 3px rgba(0,0,0,.07), 0 4px 12px rgba(0,0,0,.04);
  --shadow-md:     0 4px 12px rgba(0,0,0,.10), 0 8px 24px rgba(0,0,0,.05);
}

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

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

/* ── Header ────────────────────────────────────────── */
.site-header {
  background: #ffffff;
  color: var(--primary);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 3px solid var(--primary);
  flex-wrap: wrap;
}
.logo-group { display: flex; align-items: center; gap: .875rem; flex-shrink: 0; }
.logo-mark  { width: 44px; height: 44px; border-radius: 6px; flex-shrink: 0; image-rendering: pixelated; }
.site-header h1 { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.5px; color: var(--primary); }
.site-tagline   { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ── Nav ────────────────────────────────────────────── */
.site-nav {
  display: flex;
  gap: .2rem;
  background: #eff6ff;
  border-radius: 100px;
  padding: .25rem;
  flex-wrap: wrap;
}
.site-nav a {
  color: var(--primary);
  text-decoration: none;
  padding: .3rem .875rem;
  border-radius: 100px;
  font-size: .8rem;
  font-weight: 600;
  transition: all .15s;
  white-space: nowrap;
}
.site-nav a:hover {
  background: #dbeafe;
  color: var(--primary);
}
.site-nav a.active {
  background: var(--primary);
  color: #fff;
}

.header-badge {
  background: #dbeafe;
  border: 1px solid #bfdbfe;
  border-radius: 100px;
  padding: .25rem .85rem;
  font-size: .75rem;
  font-weight: 600;
  color: var(--primary);
  white-space: nowrap;
}

/* view page back link */
.back-link { color: var(--primary); font-size: .825rem; text-decoration: none; opacity: .75; font-weight: 600; }
.back-link:hover { opacity: 1; text-decoration: underline; }

/* ── Layout ────────────────────────────────────────── */
main {
  max-width: 1180px;
  margin: 0 auto;
  padding: 2rem;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ── Cards ─────────────────────────────────────────── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 1.5rem;
}
.card-title {
  font-size: .8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-muted);
  margin-bottom: 1.1rem;
}

/* ── Type selector ─────────────────────────────────── */
.type-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: .625rem;
}
.type-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
  padding: .875rem .5rem;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  transition: all .15s ease;
  text-align: center;
}
.type-btn:hover {
  border-color: var(--accent);
  background: #eff6ff;
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.type-btn.active {
  border-color: var(--primary);
  background: #eff6ff;
  box-shadow: 0 0 0 3px rgba(59,130,246,.18);
}
.type-btn .t-icon { font-size: 1.4rem; }
.type-btn .t-name { font-size: .72rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.type-btn .t-desc { font-size: .63rem; color: var(--text-muted); line-height: 1.25; }

/* ── Generator grid ────────────────────────────────── */
.gen-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

/* ── Form ──────────────────────────────────────────── */
.form-group { margin-bottom: .875rem; }
.form-group label {
  display: block;
  font-size: .825rem;
  font-weight: 600;
  margin-bottom: .35rem;
  color: var(--text);
}
.form-group input[type=text],
.form-group textarea,
.form-group select {
  width: 100%;
  padding: .55rem .825rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-group input[type=text]:focus,
.form-group textarea:focus,
.form-group select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,.12);
}
.form-group textarea { min-height: 90px; resize: vertical; }
.form-hint { font-size: .72rem; color: var(--text-muted); margin-top: .25rem; }

.aamva-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem .875rem;
}

/* ── Preview ───────────────────────────────────────── */
.preview-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
  background: #f8fafc;
  border: 2px dashed var(--border);
  border-radius: 8px;
  padding: 1rem;
  overflow: hidden;
}
#preview-canvas { max-width: 100%; display: none; }
.preview-ph {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .5rem;
  color: var(--text-muted);
  font-size: .825rem;
  text-align: center;
}
.preview-ph .ph-icon { font-size: 2.5rem; opacity: .25; }

/* ── Customize ─────────────────────────────────────── */
.customize-row {
  display: flex;
  gap: 1.5rem;
  align-items: flex-end;
  flex-wrap: wrap;
}
.customize-row .form-group { margin-bottom: 0; }
.color-pair { display: flex; align-items: center; gap: .5rem; }
input[type=color] {
  width: 38px; height: 38px;
  border: none; border-radius: 8px;
  cursor: pointer; padding: 2px;
  background: var(--border);
}
input[type=range] {
  width: 100%;
  accent-color: var(--accent);
}

/* ── Save row ──────────────────────────────────────── */
.save-row { display: flex; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.save-row .form-group { margin-bottom: 0; }

/* ── Buttons ───────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  padding: .55rem 1.15rem;
  border: none;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all .15s ease;
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
}
.btn:disabled { opacity: .55; cursor: not-allowed; transform: none !important; }
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)  { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(30,64,175,.28); }
.btn-secondary { background: var(--bg); color: var(--text); border: 1.5px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)   { filter: brightness(1.1); transform: translateY(-1px); }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled)  { filter: brightness(1.1); transform: translateY(-1px); }
.btn-lg { padding: .75rem 1.75rem; font-size: .95rem; }
.btn-sm { padding: .35rem .8rem; font-size: .8rem; }

/* ── Error / success ───────────────────────────────── */
.error-msg {
  color: var(--danger);
  font-size: .825rem;
  padding: .55rem .875rem;
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: 8px;
  margin-bottom: .75rem;
  display: none;
}

/* ── Result box ────────────────────────────────────── */
.result-card { border-color: #a7f3d0; background: #f0fdf4; }
.result-card .card-title { color: var(--success); }
.result-link-row { display: flex; gap: .625rem; align-items: center; margin-top: .625rem; }
.result-link-input {
  flex: 1;
  padding: .55rem .875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .825rem;
  background: #fff;
  font-family: 'Courier New', monospace;
  color: var(--primary);
  outline: none;
}

/* ── API teaser ────────────────────────────────────── */
.api-teaser { background: #0f172a; border-color: #1e293b; }
.api-teaser .card-title { color: #94a3b8; }
.api-teaser-desc { color: #64748b; font-size: .825rem; margin-bottom: .875rem; }
.api-code-block {
  background: #020617;
  border-radius: 8px;
  padding: 1rem 1.25rem;
  font-family: 'Courier New', Courier, monospace;
  font-size: .8rem;
  color: #e2e8f0;
  overflow-x: auto;
  line-height: 1.7;
}
.token-method { color: #38bdf8; font-weight: 700; }
.token-url    { color: #a5f3fc; }
.token-key    { color: #fbbf24; }
.token-val    { color: #86efac; }
.token-com    { color: #475569; }
.api-cta { display: flex; align-items: center; gap: .75rem; margin-top: 1rem; }
.api-cta p { color: #64748b; font-size: .8rem; }

/* ── Spinner ───────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2.5px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badge ─────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2rem .65rem;
  border-radius: 100px;
  font-size: .72rem;
  font-weight: 700;
}
.badge-blue  { background: #dbeafe; color: #1e40af; }
.badge-green { background: #d1fae5; color: #065f46; }
.badge-gray  { background: #f1f5f9; color: #475569; }

/* ── View page ─────────────────────────────────────── */

.view-grid { display: grid; grid-template-columns: 1fr 380px; gap: 1.5rem; align-items: start; }

.bc-image-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fff;
  border: 2px solid var(--border);
  border-radius: 10px;
  padding: 2rem;
  min-height: 220px;
}
.bc-image-wrap img { max-width: 100%; height: auto; }

.bc-name { font-size: 1.5rem; font-weight: 800; line-height: 1.2; margin-bottom: .35rem; }
.bc-desc { color: var(--text-muted); font-size: .9rem; margin-bottom: 1rem; }

.stats-row {
  display: flex;
  gap: 1.25rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
}
.stat {
  display: flex;
  flex-direction: column;
  gap: .1rem;
}
.stat-val { font-size: 1.25rem; font-weight: 700; color: var(--text); }
.stat-label { font-size: .7rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }

.action-row { display: flex; gap: .625rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

.share-section { margin-top: 1.25rem; }
.share-section label { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); display: block; margin-bottom: .35rem; }
.share-row { display: flex; gap: .5rem; }
.share-row input {
  flex: 1;
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .8rem;
  font-family: 'Courier New', monospace;
  color: var(--primary);
  background: #fff;
  outline: none;
}

.delete-zone {
  border-top: 1px solid var(--border);
  padding-top: 1rem;
  margin-top: 1rem;
}

/* ── Edit inline ───────────────────────────────────── */
.edit-input {
  font-size: inherit;
  font-weight: inherit;
  font-family: inherit;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  padding: .3rem .6rem;
  width: 100%;
  outline: none;
  color: var(--text);
}
.edit-textarea {
  font-size: inherit;
  font-family: inherit;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  padding: .35rem .6rem;
  width: 100%;
  outline: none;
  resize: vertical;
  color: var(--text);
  min-height: 60px;
}

/* ── Footer ────────────────────────────────────────── */
footer {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
  font-size: .8rem;
  border-top: 1px solid var(--border);
  margin-top: 1rem;
}
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Print ─────────────────────────────────────────── */
@media print {
  .site-header, .action-row, .share-section, .delete-zone,
  .api-teaser, footer, .btn, nav { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; padding: 0; }
  .view-grid { grid-template-columns: 1fr; }
  .bc-image-wrap { border: 1px solid #ccc; padding: 1rem; }
  main { padding: 0; }
}

/* ── Responsive ────────────────────────────────────── */
@media (max-width: 768px) {
  /* Header stacks logo above nav */
  .site-header {
    flex-direction: column;
    align-items: flex-start;
    padding: .875rem 1rem;
    gap: .75rem;
  }
  .site-header h1   { font-size: 1.35rem; }
  .site-tagline     { display: none; }
  .header-badge     { display: none; }

  /* Remove the pill/rounded-rectangle behind the nav */
  .site-nav {
    background: transparent;
    border-radius: 0;
    padding: 0;
    gap: 0;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .site-nav::-webkit-scrollbar { display: none; }
  .site-nav a {
    padding: .4rem .75rem;
    font-size: .78rem;
    border-radius: 6px;
    flex-shrink: 0;
  }

  /* Layout */
  .gen-grid      { grid-template-columns: 1fr; }
  .aamva-grid    { grid-template-columns: 1fr; }
  .customize-row { flex-direction: column; }
  .save-row      { flex-direction: column; }
  .view-grid     { grid-template-columns: 1fr; }
  main           { padding: 1rem; }
  .type-grid     { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .result-link-row { flex-wrap: wrap; }
  .result-link-input { min-width: 0; }
}

/* ── Expiry field ────────────────────────────────────── */
.expiry-row { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; }
.expiry-row input[type=date] {
  padding: .5rem .75rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  color: var(--text);
  background: #fff;
  outline: none;
}
.expiry-row input[type=date]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(59,130,246,.12); }
.expiry-badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .25rem .65rem; border-radius: 100px;
  font-size: .72rem; font-weight: 700;
}
.expiry-badge.active  { background: #fef3c7; color: #92400e; }
.expiry-badge.expired { background: #fee2e2; color: #991b1b; }

/* ── Logo upload (QR) ───────────────────────────────── */
.logo-drop {
  border: 2px dashed var(--border); border-radius: 8px;
  padding: .875rem; text-align: center; cursor: pointer;
  transition: all .15s; font-size: .825rem; color: var(--text-muted);
}
.logo-drop:hover, .logo-drop.over { border-color: var(--accent); background: #eff6ff; color: var(--accent); }
.logo-preview-wrap { display: flex; align-items: center; gap: .75rem; margin-top: .5rem; }
.logo-preview-wrap img { width: 48px; height: 48px; object-fit: contain; border-radius: 6px; border: 1px solid var(--border); }

/* ── Batch ──────────────────────────────────────────── */
.progress-bar-wrap {
  width: 100%; height: 8px; background: var(--border);
  border-radius: 100px; overflow: hidden; margin: .75rem 0;
}
.progress-bar { height: 100%; background: var(--accent); border-radius: 100px; transition: width .3s; width: 0; }
.batch-log {
  background: #020617; color: #94a3b8; border-radius: 8px;
  padding: .875rem 1rem; font-family: monospace; font-size: .78rem;
  max-height: 200px; overflow-y: auto; line-height: 1.6;
}
.batch-log .ok  { color: #86efac; }
.batch-log .err { color: #fca5a5; }

/* ── Decode ─────────────────────────────────────────── */
.drop-zone {
  border: 3px dashed var(--border); border-radius: 12px;
  padding: 3rem 1rem; text-align: center; cursor: pointer;
  transition: all .2s; color: var(--text-muted);
}
.drop-zone:hover, .drop-zone.over {
  border-color: var(--accent); background: #eff6ff; color: var(--accent);
}
.drop-zone .dz-icon { font-size: 2.5rem; opacity: .4; margin-bottom: .5rem; }
.decode-result {
  background: #f0fdf4; border: 1.5px solid #a7f3d0; border-radius: 10px; padding: 1.25rem;
}
.decode-result pre { white-space: pre-wrap; word-break: break-all; font-size: .875rem; }
.decode-img-preview {
  max-width: 100%; max-height: 300px; border-radius: 8px;
  border: 1px solid var(--border); display: block; margin: 0 auto;
}

/* ── Labels ─────────────────────────────────────────── */
.label-template-grid { display: flex; gap: .75rem; flex-wrap: wrap; }
.label-template-btn {
  border: 2px solid var(--border); border-radius: 10px; padding: .875rem 1.25rem;
  background: #fff; cursor: pointer; transition: all .15s; text-align: center;
}
.label-template-btn:hover { border-color: var(--accent); }
.label-template-btn.active { border-color: var(--primary); background: #eff6ff; }
.label-template-btn .tmpl-name { font-weight: 700; font-size: .9rem; }
.label-template-btn .tmpl-desc { font-size: .72rem; color: var(--text-muted); margin-top: .15rem; }

.label-sheet {
  background: white; border: 1px solid var(--border); border-radius: 8px;
  padding: 1cm; display: grid; gap: .25cm;
}
.label-cell {
  border: 1px solid #e5e7eb; border-radius: 4px; padding: .3cm;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: .2cm; overflow: hidden;
  page-break-inside: avoid;
}
.label-cell canvas { max-width: 100%; }
.label-cell .label-text { font-size: 7pt; text-align: center; word-break: break-all; }

@media print {
  .label-sheet { border: none; padding: 0; }
  .label-cell  { border: none; }
  .no-print    { display: none !important; }
  body         { background: white; }
  main         { padding: 0; }
}

/* ── My Barcodes ────────────────────────────────────── */
.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
}
.history-card {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: white; padding: 1rem; cursor: pointer;
  transition: all .15s; text-decoration: none; color: inherit;
  display: flex; flex-direction: column; gap: .5rem;
}
.history-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); border-color: var(--accent); }
.history-card img { width: 100%; max-height: 80px; object-fit: contain; }
.history-card .hc-name { font-weight: 700; font-size: .9rem; }
.history-card .hc-meta { font-size: .72rem; color: var(--text-muted); }
.history-card .hc-del {
  margin-top: auto; align-self: flex-end; background: none; border: none;
  color: var(--text-muted); cursor: pointer; font-size: .75rem; padding: .2rem .5rem;
  border-radius: 4px; transition: all .1s;
}
.history-card .hc-del:hover { background: #fee2e2; color: var(--danger); }

.collection-chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .25rem .65rem; border-radius: 100px;
  background: var(--bg); border: 1.5px solid var(--border);
  font-size: .75rem; font-weight: 600; cursor: pointer; transition: all .15s;
}
.collection-chip.active { background: #dbeafe; border-color: var(--accent); color: var(--primary); }
.collection-chip:hover  { border-color: var(--accent); }
