:root {
  --ink: #141414;
  --muted: #6b6b6b;
  --line: #e4e0d4;
  --paper: #fffdf8;
  --page: #ece8df;
  --black: #0c0c0c;
  --gold: #c9a34a;
  --gold-2: #e8d48a;
  --radius: 18px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: Montserrat, system-ui, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(900px 420px at 0% 0%, #f4e7c0 0%, transparent 50%),
    var(--page);
}

.app {
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: #0c0c0c;
  color: var(--gold);
  font-family: Cinzel, serif;
  font-weight: 800;
  font-size: 1.15rem;
}

.topbar h1 {
  margin: 0;
  font-size: 1.28rem;
}

.topbar p,
.panel-lead,
.preview-head p,
.field-hint {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.topbar-actions,
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 390px) 1fr;
  gap: 18px;
  align-items: start;
}

.panel {
  background: var(--paper);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(20, 16, 8, 0.08);
}

.form-panel,
.preview-panel {
  padding: 22px;
}

.panel h2 {
  margin: 0;
  font-size: 1.02rem;
}

fieldset {
  border: 0;
  margin: 20px 0 0;
  padding: 0;
}

legend {
  margin-bottom: 10px;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #8a6d28;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 11px;
  font-size: 0.8rem;
  font-weight: 600;
}

input,
select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0 12px;
  font: 500 0.92rem/1 Montserrat, system-ui, sans-serif;
  background: #fff;
}

input:focus,
select:focus {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.color-row {
  display: grid;
  grid-template-columns: 48px 1fr;
  gap: 8px;
  align-items: center;
}

input[type="color"] {
  padding: 3px;
  height: 42px;
  cursor: pointer;
  background: #fff;
}

.file-field input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.check-field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 0 8px;
  font-size: 0.82rem;
  font-weight: 600;
}

.check-field input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.cnh-hint {
  margin: -4px 0 10px;
}

.back-data .split.is-single {
  display: flex;
}

.file-fake {
  display: grid;
  place-items: center;
  height: 46px;
  border: 1px dashed #c9b57a;
  border-radius: 10px;
  background: #faf6ea;
  cursor: pointer;
}

.themes {
  display: flex;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.theme-dot {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--swatch);
  box-shadow: 0 0 0 1px #c5d0dc;
  cursor: pointer;
  padding: 0;
}

.theme-dot.is-active {
  box-shadow: 0 0 0 2px var(--swatch);
}

.theme-dot[data-theme="gold"] {
  background:
    linear-gradient(135deg, #0c0c0c 50%, #c9a34a 50%);
}

.btn {
  height: 42px;
  padding: 0 14px;
  border-radius: 11px;
  border: 1px solid #ddd4bf;
  background: #fff;
  font: 700 0.84rem/1 Montserrat, system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(201, 163, 74, 0.25);
}

.btn.primary {
  background: #0c0c0c;
  border-color: #0c0c0c;
  color: var(--gold-2);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.7);
}

.btn:disabled {
  opacity: 0.65;
  cursor: wait;
}

.preview-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.preview-actions {
  margin-top: 16px;
}

.badge-stage {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 24px;
  margin-top: 16px;
  padding: 24px 8px;
  border: 1px dashed #d9ccae;
  border-radius: 16px;
  background: #f3eee3;
}

.badge {
  --badge-bg: #0c0c0c;
  --badge-accent: #c9a34a;
  --badge-accent-2: #e8d48a;
  --badge-text: #f4f0e6;
  --badge-muted: #d8d2c4;
  width: 74mm;
  height: 105mm;
  position: relative;
  overflow: hidden;
  border-radius: 10px;
  background:
    radial-gradient(120% 70% at 50% 38%, rgba(201, 163, 74, 0.14), transparent 52%),
    var(--badge-bg);
  color: var(--badge-text);
  display: flex;
  flex-direction: column;
  padding: 5mm 5.5mm 4mm;
  border: 1.2px solid var(--badge-accent);
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.28);
}

.badge-deco {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.stroke {
  position: absolute;
  height: 1.15px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--badge-accent) 18%,
    var(--badge-accent-2) 50%,
    var(--badge-accent) 82%,
    transparent
  );
  opacity: 0.55;
}

.stroke-a {
  width: 140%;
  left: -20%;
  top: 36%;
  transform: rotate(-22deg);
}

.stroke-b {
  width: 120%;
  left: -10%;
  top: 48%;
  transform: rotate(-22deg);
  opacity: 0.28;
}

.stroke-c {
  width: 90%;
  right: -18%;
  bottom: 22%;
  left: auto;
  transform: rotate(18deg);
  opacity: 0.32;
}

.badge > :not(.badge-deco) {
  position: relative;
  z-index: 1;
}

.watermark {
  position: absolute;
  left: 50%;
  top: 46%;
  transform: translate(-50%, -50%);
  font-family: Cinzel, serif;
  font-size: 92px;
  font-weight: 800;
  color: var(--badge-accent);
  opacity: 0.06;
  line-height: 1;
}

.crest {
  width: 8mm;
  height: 8mm;
  margin: 0 auto 1.8mm;
  border: 1px solid var(--badge-accent);
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-family: Cinzel, serif;
  font-size: 9px;
  font-weight: 800;
  color: var(--badge-accent);
  box-shadow: 0 0 0 1.6px var(--badge-bg), 0 0 0 2.3px var(--badge-accent);
  background: radial-gradient(circle at 40% 30%, rgba(232, 212, 138, 0.25), transparent 60%);
  flex: none;
}

.badge-hole {
  width: 13mm;
  height: 3mm;
  margin: 0 auto 2.4mm;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 1px var(--badge-accent);
  flex: none;
}

.badge-hole.light {
  background: #1a1a1a;
}

.front-brand,
.front-id {
  text-align: center;
}

.logo-word {
  display: block;
  width: 58mm;
  height: 9mm;
  margin: 0 auto;
  line-height: 0;
}

.logo-word.small {
  width: 42mm;
  height: 6.4mm;
}

.logo-word svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.logo-sub {
  margin: 0.35mm 0 0;
  font-size: 6.6px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--badge-muted);
  text-align: center;
}

.brand-rule {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2mm;
  margin: 1.8mm auto 0;
  width: 42mm;
}

.brand-rule::before,
.brand-rule::after {
  content: "";
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--badge-accent));
}

.brand-rule::after {
  background: linear-gradient(90deg, var(--badge-accent), transparent);
}

.brand-rule span {
  width: 2.1mm;
  height: 2.1mm;
  transform: rotate(45deg);
  background: var(--badge-accent);
  flex: none;
}

.photo-stage {
  width: 44mm;
  height: 44mm;
  margin: 3.6mm auto 3.2mm;
  position: relative;
  flex: none;
}

.photo-stage::before,
.photo-stage::after {
  content: none;
}

.photo-ring,
.badge-photo,
.badge-photo img,
.badge-photo svg {
  border-radius: 50%;
}

.photo-ring {
  width: 100%;
  height: 100%;
  padding: 1.35mm;
  overflow: hidden;
  background: linear-gradient(160deg, var(--badge-accent-2), var(--badge-accent) 48%, #8a6a22);
  box-shadow: none;
}

.badge-photo {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #1a1a1a;
}

.badge-photo img,
.badge-photo svg {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.front-name {
  margin: 0 auto;
  color: #fff;
  font-family: Cinzel, serif;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-width: 64mm;
  padding: 0 2mm;
  line-height: 1.2;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: none;
}

.front-name::before,
.front-name::after {
  content: none;
}

.front-role {
  margin: 1.6mm 0 0;
  color: var(--badge-accent);
  font-size: 9.2px;
  font-weight: 800;
  letter-spacing: 0.18em;
  line-height: 1.3;
  padding: 0 2mm;
}

.front-foot {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2.2mm;
  margin-top: auto;
  padding-top: 3mm;
}

.front-foot span {
  width: 18mm;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--badge-accent), transparent);
}

.front-foot i {
  width: 2.4mm;
  height: 2.4mm;
  border: 1px solid var(--badge-accent);
  transform: rotate(45deg);
  display: block;
}

.badge-back {
  background: var(--badge-bg);
  padding-bottom: 3.2mm;
}

.back-kicker {
  margin: 0 0 0.4mm;
  text-align: center;
  font-size: 7px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--badge-accent);
}

.back-data {
  margin: 1.8mm 0 0;
  display: grid;
  gap: 1.1mm;
}

.back-data > div:not(.split) {
  display: grid;
  gap: 0.25mm;
  padding-bottom: 0.85mm;
  border-bottom: 1px solid var(--badge-accent);
}

.back-data dt {
  font-size: 6px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--badge-accent);
}

.back-data dd {
  margin: 0;
  font-size: 9px;
  font-weight: 700;
  color: #f3eee2;
  overflow-wrap: anywhere;
}

.back-data a,
.back-data a[href^="tel:"],
.back-data a[x-apple-data-detectors] {
  color: inherit !important;
  text-decoration: none !important;
  background: none !important;
  border: 0 !important;
  pointer-events: none;
}

#pv-cnh,
#pv-cpf,
#pv-rg,
#pv-matricula-back,
#pv-validade {
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
  text-decoration: none;
  -webkit-text-decoration: none;
}

.back-data .split {
  display: flex;
  align-items: flex-end;
  gap: 3mm;
  padding-bottom: 0.85mm;
  border-bottom: 1px solid var(--badge-accent);
}

.back-data .split > div {
  flex: 1;
  min-width: 0;
}

.back-data .split.is-single > div {
  flex: 1;
}

.qr-panel {
  display: grid;
  justify-items: center;
  gap: 1mm;
  margin-top: auto;
  padding: 1.4mm 0 0;
  text-align: center;
}

#qrcode {
  width: 24mm;
  height: 24mm;
  padding: 1mm;
  background: #fff;
  border-radius: 2.2mm;
  display: grid;
  place-items: center;
  box-shadow: 0 0 0 1.4px var(--badge-accent);
}

#qrcode img,
#qrcode canvas,
#qrcode table {
  width: 100% !important;
  height: 100% !important;
}

.qr-copy {
  display: grid;
  gap: 1mm;
  justify-items: center;
}

.qr-copy strong {
  font-size: 7.4px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.qr-copy a {
  color: var(--badge-accent);
  font-size: 11px;
  font-weight: 800;
  text-decoration: none;
  letter-spacing: 0.04em;
}

body[data-theme="navy"] .badge {
  --badge-bg: #0b1f4d;
  --badge-accent: #c9a227;
  --badge-accent-2: #ead48a;
}

body[data-theme="green"] .badge {
  --badge-bg: #14532d;
  --badge-accent: #d4b45a;
  --badge-accent-2: #f0e0a0;
}

body[data-theme="red"] .badge {
  --badge-bg: #7f1d1d;
  --badge-accent: #e2c36b;
  --badge-accent-2: #f5e4a8;
}

body[data-theme="slate"] .badge {
  --badge-bg: #1e293b;
  --badge-accent: #cbd5e1;
  --badge-accent-2: #f1f5f9;
}

body[data-theme="amber"] .badge {
  --badge-bg: #9a3412;
  --badge-accent: #fde68a;
  --badge-accent-2: #fff7c2;
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }

  .preview-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .preview-actions .btn {
    width: 100%;
    min-height: 48px;
    height: auto;
    padding: 14px 16px;
  }

  .db-toolbar {
    grid-template-columns: 1fr;
  }
}

.save-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(12, 12, 12, 0.72);
}

.save-overlay[hidden] {
  display: none !important;
}

.save-sheet {
  width: min(420px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: #fffdf8;
  border-radius: 16px;
  padding: 16px;
  text-align: center;
}

.save-sheet p {
  margin: 0 0 12px;
  font-size: 0.92rem;
  font-weight: 600;
}

.save-sheet img {
  width: 74mm;
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto 14px;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.2);
}

.save-sheet .btn {
  width: 100%;
}

.db-panel {
  margin-top: 28px;
  padding-top: 22px;
  border-top: 1px solid var(--line);
}

.db-toolbar {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: end;
  margin: 12px 0 8px;
}

.db-search {
  margin-bottom: 0;
}

.db-lista {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.db-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.db-item strong {
  display: block;
  font-size: 0.9rem;
}

.db-item span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.db-item-actions {
  display: flex;
  gap: 6px;
}

.db-item .btn {
  height: 36px;
  padding: 0 10px;
  font-size: 0.75rem;
}

.btn.danger {
  border-color: #c4a0a0;
  color: #7f1d1d;
}

#print-shots {
  display: none;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 12mm;
  }

  html,
  body,
  .badge,
  #print-shots img {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    color-adjust: exact !important;
  }

  body {
    background: #fff;
  }

  .topbar,
  .form-panel,
  .preview-head,
  .preview-actions {
    display: none !important;
  }

  .app,
  .preview-panel,
  .badge-stage {
    margin: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
    background: #fff;
  }

  .badge-stage {
    display: flex;
    gap: 10mm;
    justify-content: flex-start;
  }

  .badge {
    box-shadow: none;
    break-inside: avoid;
  }

  body.is-printing-shots .app {
    display: none !important;
  }

  body.is-printing-shots #print-shots {
    display: flex !important;
    gap: 10mm;
    background: #fff;
  }

  body.is-printing-shots #print-shots img {
    width: 74mm;
    height: 105mm;
    display: block;
  }
}
