@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 400;
  src: url("fonts/cairo-400.ttf") format("truetype");
}
@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 600;
  src: url("fonts/cairo-600.ttf") format("truetype");
}
@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 700;
  src: url("fonts/cairo-700.ttf") format("truetype");
}
@font-face {
  font-family: "Cairo";
  font-style: normal;
  font-weight: 800;
  src: url("fonts/cairo-800.ttf") format("truetype");
}
@font-face {
  font-family: "Amiri";
  font-style: normal;
  font-weight: 700;
  src: url("fonts/amiri-700.ttf") format("truetype");
}

:root {
  --green-900: #0b2418;
  --green-800: #123326;
  --green-700: #1a4a36;
  --green-600: #1f5c42;
  --gold-500: #c9a227;
  --gold-300: #e4c76a;
  --cream: #f6f1e4;
  --paper: #fffdf8;
  --ink: #142018;
  --muted: #5d6b62;
  --line: #d7c9a3;
  --danger: #9b2c2c;
  --shadow: 0 18px 40px rgba(11, 36, 24, 0.18);
  --card-w: 40mm;
  --card-h: 90mm;
}

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

html, body {
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 80% -10%, #1f5c42 0%, transparent 55%),
    linear-gradient(180deg, #0b2418 0%, #123326 40%, #0e1c16 100%);
  color: var(--ink);
  font-family: "Cairo", "Tahoma", sans-serif;
}

.app { max-width: 1480px; margin: 0 auto; padding: 18px 18px 40px; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  background: linear-gradient(135deg, rgba(246,241,228,.96), rgba(255,255,255,.9));
  border: 1px solid rgba(201,162,39,.35);
  border-radius: 18px;
  padding: 14px 18px;
  box-shadow: var(--shadow);
}

.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { font-size: 22px; color: var(--green-800); line-height: 1.2; }
.brand p { color: var(--muted); font-size: 13px; font-weight: 600; }
.crest { flex: none; }

.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  appearance: none;
  border: 0;
  background: linear-gradient(180deg, #1f5c42, #143d2a);
  color: #fff;
  font-family: inherit;
  font-weight: 700;
  font-size: 14px;
  padding: 10px 16px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(20, 61, 42, .28);
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost {
  background: transparent;
  color: var(--green-800);
  border: 1px solid var(--line);
  box-shadow: none;
}
.btn.secondary { background: linear-gradient(180deg, #c9a227, #9b7a16); color: #1a1608; }
.btn.danger { color: var(--danger); border-color: #e8b4b4; }
.full-btn { width: 100%; margin-top: 8px; }

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  margin-top: 16px;
}

.panel {
  background: var(--paper);
  border-radius: 18px;
  padding: 18px;
  border: 1px solid rgba(201,162,39,.28);
  box-shadow: var(--shadow);
  height: fit-content;
}

.panel h2 {
  font-size: 15px;
  color: var(--green-800);
  margin: 16px 0 8px;
  padding-bottom: 6px;
  border-bottom: 2px solid var(--gold-300);
}
.panel h2:first-child { margin-top: 0; }

.hint { font-size: 13px; color: var(--muted); line-height: 1.7; margin-bottom: 12px; }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border: 2px dashed #c9a227;
  background: linear-gradient(180deg, #fff8e8, #f6f1e4);
  border-radius: 14px;
  padding: 22px 10px;
  cursor: pointer;
  text-align: center;
}
.dropzone.drag { background: #eef7f1; border-color: var(--green-600); }
.dz-icon {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--green-700); color: #fff;
  display: grid; place-items: center; font-size: 22px; font-weight: 800;
}
.dz-title { font-weight: 700; color: var(--green-800); font-size: 14px; }
.dz-sub { font-size: 12px; color: var(--muted); }
.file-name { font-size: 12px; color: var(--green-700); min-height: 18px; margin-top: 6px; }

.fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
label, .full {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; font-weight: 700; color: var(--green-800); margin-top: 8px;
}
input, select {
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid #c9a22755; border-color: var(--gold-500); }

.preview-wrap { min-width: 0; }
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}
.stat {
  background: rgba(246,241,228,.94);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
  border: 1px solid rgba(201,162,39,.25);
}
.stat span { display: block; font-size: 22px; font-weight: 800; color: var(--green-800); }
.stat small { color: var(--muted); font-weight: 700; }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--cream);
  font-size: 13px;
  margin-bottom: 8px;
}
.zoom-lab { display: flex; align-items: center; gap: 8px; }

#print-root {
  position: absolute;
  left: -12000px;
  top: 0;
  width: 210mm;
  pointer-events: none;
}

body.is-printing .app {
  display: none !important;
}
body.is-printing #print-root {
  position: static;
  left: auto;
  pointer-events: auto;
}

.stage {
  background: #1a241d;
  border-radius: 16px;
  padding: 18px;
  overflow: auto;
  max-height: calc(100vh - 210px);
  border: 1px solid #2a3d32;
}

.empty {
  color: #c9d4cc;
  text-align: center;
  padding: 80px 16px;
  font-weight: 600;
}

.sheets { display: flex; flex-direction: column; align-items: center; gap: 22px; }

.sheet {
  width: 210mm;
  height: 297mm;
  background: white;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
  padding: 10mm 20.5mm;
  display: grid;
  grid-template-columns: repeat(4, 40mm);
  grid-template-rows: repeat(3, 90mm);
  column-gap: 3mm;
  row-gap: 3.5mm;
  transform-origin: top center;
}

.slot {
  position: relative;
  width: 40mm;
  height: 90mm;
}

.cut {
  position: absolute;
  width: 2.4mm;
  height: 2.4mm;
  pointer-events: none;
  z-index: 4;
}
.cut-tl { top: -1.7mm; right: -1.7mm; border-top: 0.25mm solid #666; border-right: 0.25mm solid #666; }
.cut-tr { top: -1.7mm; left: -1.7mm; border-top: 0.25mm solid #666; border-left: 0.25mm solid #666; }
.cut-bl { bottom: -1.7mm; right: -1.7mm; border-bottom: 0.25mm solid #666; border-right: 0.25mm solid #666; }
.cut-br { bottom: -1.7mm; left: -1.7mm; border-bottom: 0.25mm solid #666; border-left: 0.25mm solid #666; }

.guide {
  position: absolute;
  pointer-events: none;
  z-index: 3;
}
.guide-x {
  left: 0;
  right: 0;
  bottom: -1.85mm;
  height: 0;
  border-bottom: 0.18mm dashed #9aa3a0;
}
.guide-y {
  top: 0;
  bottom: 0;
  left: -1.6mm;
  width: 0;
  border-left: 0.18mm dashed #9aa3a0;
}

.card {
  width: 40mm;
  height: 90mm;
  position: relative;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  border: 0.35mm solid #1a4a36;
  display: flex;
  flex-direction: column;
  font-family: "Cairo", "Tahoma", sans-serif;
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

.card-frame {
  position: absolute;
  inset: 1.4mm;
  border: 0.3mm solid #c9a227;
  pointer-events: none;
  z-index: 2;
}
.card-frame::before,
.card-frame::after {
  content: "";
  position: absolute;
  width: 3.2mm;
  height: 3.2mm;
  border: 0.45mm solid #1a4a36;
}
.card-frame::before { top: -0.6mm; right: -0.6mm; border-left: 0; border-bottom: 0; }
.card-frame::after { bottom: -0.6mm; left: -0.6mm; border-right: 0; border-top: 0; }

.card-head {
  background: linear-gradient(180deg, #1a4a36 0%, #123326 100%);
  color: #fff;
  padding: 3.2mm 2.2mm 2.6mm;
  text-align: center;
  position: relative;
  z-index: 1;
}
.card-head::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1.1mm;
  height: 2.2mm;
  background: repeating-linear-gradient(
    90deg,
    #c9a227 0 2.2mm,
    #1a4a36 2.2mm 4.4mm
  );
}
.ornament {
  font-size: 7pt;
  color: #e4c76a;
  letter-spacing: 1px;
  line-height: 1;
  margin-bottom: 0.8mm;
}
.card-title {
  font-family: "Amiri", "Cairo", serif;
  font-size: 8.2pt;
  font-weight: 700;
  line-height: 1.35;
  margin: 0;
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4.2mm 2.4mm 2mm;
  gap: 1.5mm;
  position: relative;
  z-index: 1;
}

.field {
  width: 100%;
  border: 0.22mm solid #d7c9a3;
  background: #fffdf8;
  border-radius: 0.8mm;
  padding: 1.1mm 1.6mm 1.3mm;
}
.field .k {
  display: block;
  font-size: 6pt;
  color: #6a5a2a;
  font-weight: 700;
}
.field .v {
  display: block;
  font-size: 8.4pt;
  font-weight: 800;
  color: #123326;
  line-height: 1.25;
  word-break: break-word;
}

.qr-box {
  width: 28mm;
  height: 28mm;
  border: 0.35mm solid #c9a227;
  padding: 1.1mm;
  background: #fff;
  display: grid;
  place-items: center;
  margin-top: 0.6mm;
}
.qr-box canvas,
.qr-box img,
.qr-box table {
  width: 25.4mm !important;
  height: 25.4mm !important;
  display: block;
}
.qr-box table { border-collapse: collapse; }
.qr-box td { padding: 0; }

.card-foot {
  background: linear-gradient(180deg, #c9a227, #b08a1c);
  color: #1a1608;
  text-align: center;
  padding: 2.1mm 1.6mm 2.4mm;
  z-index: 1;
}
.card-foot .org {
  font-size: 6.3pt;
  font-weight: 800;
  line-height: 1.25;
}
.card-foot .months {
  font-size: 7.2pt;
  font-weight: 800;
  margin-top: 0.5mm;
}

@media (max-width: 1100px) {
  .layout { grid-template-columns: 1fr; }
  .stage { max-height: none; }
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  html, body {
    background: white !important;
    margin: 0 !important;
    padding: 0 !important;
    height: auto !important;
    overflow: visible !important;
  }
  .app,
  .no-print {
    display: none !important;
  }
  #print-root {
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: auto !important;
    pointer-events: auto !important;
  }
  .print-sheet {
    width: 210mm;
    height: 297mm;
    background: white;
    padding: 10mm 20.5mm;
    display: grid;
    grid-template-columns: repeat(4, 40mm);
    grid-template-rows: repeat(3, 90mm);
    column-gap: 3mm;
    row-gap: 3.5mm;
    box-sizing: border-box;
    page-break-after: always;
    break-after: page;
    overflow: hidden;
  }
  .print-sheet:last-child {
    page-break-after: auto;
    break-after: auto;
  }
  @page {
    size: A4 portrait;
    margin: 0;
  }
}
