/* ══ AI NameTag · 명찰 렌더링 + 인쇄 시트 ══
   화면 미리보기와 실제 인쇄가 같은 CSS 를 쓴다. 모든 치수는 mm 로 두고
   미리보기에서만 transform: scale() 로 축소한다. 이러면 화면에서 본 그대로 인쇄된다. */

.badge {
  --w: 90mm; --h: 60mm;
  --bg: #ffffff; --accent: #1d4ed8; --ink: #111827; --sub: #6b7280;
  --pad: 5mm; --radius: 3mm; --bg-op: .15;

  position: relative; overflow: hidden;
  width: var(--w); height: var(--h);
  background: var(--bg); color: var(--ink);
  border-radius: var(--radius);
  display: flex; flex-direction: column;
  font-family: var(--badge-font, 'Pretendard', 'Apple SD Gothic Neo', 'Malgun Gothic', system-ui, sans-serif);
  -webkit-print-color-adjust: exact; print-color-adjust: exact;
}
.badge.bordered { box-shadow: inset 0 0 0 .3mm rgba(0, 0, 0, .18); }

.badge .bd-bgimg {
  position: absolute; inset: 0; background-size: cover; background-position: center;
  opacity: var(--bg-op); pointer-events: none;
}

.badge .bd-head {
  flex: none; padding: var(--pad) var(--pad) 0;
  font-size: var(--event-size, 3.6mm); font-weight: 800; letter-spacing: -.01em;
  color: var(--accent); text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge .bd-sub-head {
  flex: none; text-align: center; font-size: calc(var(--event-size, 3.6mm) * .78);
  color: var(--sub); font-weight: 600; margin-top: .6mm;
}

.badge .bd-main {
  flex: 1; min-height: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 1.2mm;
  padding: 1mm var(--pad); text-align: center;
}
.badge .bd-name {
  font-size: var(--name-size, 12mm); font-weight: 800; line-height: 1.08;
  letter-spacing: -.02em; word-break: keep-all;
}
.badge .bd-org {
  font-size: var(--org-size, 4.6mm); font-weight: 700; color: var(--accent); word-break: keep-all;
}
.badge .bd-title { font-size: var(--title-size, 4.2mm); font-weight: 600; color: var(--sub); }

.badge .bd-foot {
  flex: none; padding: 0 var(--pad) var(--pad);
  display: flex; justify-content: center; gap: 3mm;
  font-size: var(--foot-size, 2.9mm); color: var(--sub); font-weight: 600;
  white-space: nowrap; overflow: hidden;
}

/* 로고 — 명찰 9분할 위치. 기본은 좌상단. */
.badge .bd-logo {
  position: absolute; left: var(--pad); top: var(--pad);
  height: var(--logo-h, 7mm); max-width: 40mm; object-fit: contain;
  opacity: var(--logo-op, 1);
}
/* ── 이미지별 위치(로고 여러 개) — --lg-dx/--lg-dy 로 드래그 이동을 얹는다 ── */
.badge .bd-logo.logo-p-tl { top: calc(var(--pad) + var(--lg-dy, 0mm)); left: calc(var(--pad) + var(--lg-dx, 0mm)); right: auto; bottom: auto; transform: none; }
.badge .bd-logo.logo-p-tc { top: calc(var(--pad) + var(--lg-dy, 0mm)); left: 50%; right: auto; bottom: auto; transform: translateX(calc(-50% + var(--lg-dx, 0mm))); }
.badge .bd-logo.logo-p-tr { top: calc(var(--pad) + var(--lg-dy, 0mm)); right: calc(var(--pad) - var(--lg-dx, 0mm)); left: auto; bottom: auto; transform: none; }
.badge .bd-logo.logo-p-ml { top: 50%; left: calc(var(--pad) + var(--lg-dx, 0mm)); right: auto; bottom: auto; transform: translateY(calc(-50% + var(--lg-dy, 0mm))); }
.badge .bd-logo.logo-p-cc { top: 50%; left: 50%; right: auto; bottom: auto; transform: translate(calc(-50% + var(--lg-dx, 0mm)), calc(-50% + var(--lg-dy, 0mm))); }
.badge .bd-logo.logo-p-mr { top: 50%; right: calc(var(--pad) - var(--lg-dx, 0mm)); left: auto; bottom: auto; transform: translateY(calc(-50% + var(--lg-dy, 0mm))); }
.badge .bd-logo.logo-p-bl { bottom: calc(var(--pad) - var(--lg-dy, 0mm)); left: calc(var(--pad) + var(--lg-dx, 0mm)); right: auto; top: auto; transform: none; }
.badge .bd-logo.logo-p-bc { bottom: calc(var(--pad) - var(--lg-dy, 0mm)); left: 50%; right: auto; top: auto; transform: translateX(calc(-50% + var(--lg-dx, 0mm))); }
.badge .bd-logo.logo-p-br { bottom: calc(var(--pad) - var(--lg-dy, 0mm)); right: calc(var(--pad) - var(--lg-dx, 0mm)); left: auto; top: auto; transform: none; }
/* 하단 밴드가 있으면 아래쪽 로고는 밴드 위로 비켜난다 */
.badge.has-botband .bd-logo.logo-p-bl,
.badge.has-botband .bd-logo.logo-p-bc,
.badge.has-botband .bd-logo.logo-p-br { bottom: calc(var(--bot-h, 0mm) + var(--pad) - var(--lg-dy, 0mm)); }

.badge .bd-qr {
  position: absolute; right: var(--pad); bottom: var(--pad);
  width: 12mm; height: 12mm;
}
.badge .bd-qr img { width: 100%; height: auto; max-height: 130%; display: block; }  /* 라벨 띠가 붙으면 세로로 길어진다 */

/* 펀치 홀 가이드 */
.badge .bd-punch {
  position: absolute; top: 3mm; left: 50%; transform: translateX(-50%);
  width: 10mm; height: 3mm; border-radius: 999px;
  box-shadow: inset 0 0 0 .25mm rgba(0, 0, 0, .35);
}

/* 투명 배경 — 화면에서는 체크무늬로 투명함을 보여 주고, 인쇄에서는 정말 비운다 */
.badge.bg-clear { background: transparent !important; }
@media screen {
  .badge.bg-clear {
    background-image:
      linear-gradient(45deg, #eceff3 25%, transparent 25%, transparent 75%, #eceff3 75%),
      linear-gradient(45deg, #eceff3 25%, transparent 25%, transparent 75%, #eceff3 75%) !important;
    background-size: 4mm 4mm !important;
    background-position: 0 0, 2mm 2mm !important;
  }
}

/* ── 밴드 ──
   상·하단이 서로 독립이라 같은 클래스를 쓰고, 색·두께·글자 크기는
   렌더러가 요소에 직접 지정한다(밴드마다 값이 다르다). */
.badge .bd-band {
  flex: none; width: 100%;
  display: flex; align-items: center; justify-content: center;
  padding: 1mm var(--pad);
  font-weight: 800; letter-spacing: -.01em; text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.badge .bd-band-top { margin-bottom: 1mm; }
.badge .bd-band-bot { margin-top: 1mm; }

/* 밴드 모양 — 라운드·알약은 둥근 모서리, 나머지는 clip-path 로 자른다 */
.badge .bd-band.band-round { border-radius: 1.8mm; }
.badge .bd-band.band-pill { border-radius: 999px; }
.badge .bd-band-top.band-slant { clip-path: polygon(0 0, 100% 0, 94% 100%, 6% 100%); }
.badge .bd-band-bot.band-slant { clip-path: polygon(6% 0, 94% 0, 100% 100%, 0 100%); }
.badge .bd-band-top.band-arch { border-radius: 0 0 50% 50% / 0 0 46% 46%; }
.badge .bd-band-bot.band-arch { border-radius: 50% 50% 0 0 / 46% 46% 0 0; }
.badge .bd-band.band-ribbon {
  clip-path: polygon(0 0, 100% 0, calc(100% - 3mm) 50%, 100% 100%, 0 100%, 3mm 50%);
  padding-left: calc(var(--pad) + 3mm); padding-right: calc(var(--pad) + 3mm);
}

/* 하단 밴드가 있으면 QR 은 밴드 위로 올라간다 */
.badge.has-botband .bd-qr { bottom: calc(var(--bot-h, 0mm) + var(--pad)); }

/* ── 장식 ──
   포스터풍 명찰을 위한 프레임·모서리 각·웨이브.
   모서리·웨이브는 렌더러가 넣는 SVG 가 명찰 전체를 덮는다. */
.badge .bd-deco { position: absolute; inset: 0; pointer-events: none; z-index: 0; }
.badge .bd-deco .deco-svg { width: 100%; height: 100%; display: block; }

/* 배경·장식은 맨 뒤, 글자는 그 위, 로고·QR 은 맨 앞.
   (절대 위치 요소가 기본적으로 본문보다 위에 그려지므로 순서를 명시한다) */
.badge .bd-bgimg { z-index: 0; }
/* 가운데 블록은 투명한 빈 영역까지 마우스를 가로채 아래 요소를 못 잡게 한다
   — 상자만 통과시키고 글자들(자식)은 그대로 잡히게 한다 */
.badge .bd-main { pointer-events: none; }
.badge .bd-main > * { pointer-events: auto; }
.badge .bd-head, .badge .bd-sub-head, .badge .bd-main,
.badge .bd-foot, .badge .bd-band { position: relative; z-index: 1; }
.badge .bd-logo, .badge .bd-qr, .badge .bd-punch { z-index: 2; }

/* 프레임 — 바깥은 강조색, 안쪽에 흰 카드, 카드 밖 아래 띠에 주최·주관 */
.badge.deco-frame {
  background: var(--accent);
  padding: var(--frame-pad, 4mm) var(--frame-pad, 4mm) var(--frame-foot, 11mm);
}
.badge.deco-frame .bd-deco {
  inset: var(--frame-pad, 4mm) var(--frame-pad, 4mm) var(--frame-foot, 11mm);
  background: var(--bg);
  border-radius: 2mm;      /* 시안처럼 흰 카드 모서리를 둥글게 */
}
.badge.deco-frame .bd-head { padding-top: calc(var(--pad) * .7); }
.badge.deco-frame .bd-foot {
  position: absolute; left: 0; right: 0; bottom: 2mm;
  color: #fff; padding: 0 var(--pad); justify-content: center;
}
.badge.deco-frame.has-botband .bd-qr,
.badge.deco-frame .bd-qr { bottom: calc(var(--frame-foot, 11mm) + 2mm); }

/* ── 레이아웃 변형 ── */

.badge.l-side { padding-left: 4mm; }
.badge.l-side::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4mm; background: var(--accent);
}
.badge.l-side .bd-head, .badge.l-side .bd-main, .badge.l-side .bd-foot { text-align: left; align-items: flex-start; }
.badge.l-side .bd-foot { justify-content: flex-start; }

.badge.l-minimal .bd-head { display: none; }
.badge.l-minimal .bd-main { justify-content: center; }
.badge.l-minimal .bd-foot { border-top: .25mm solid rgba(0, 0, 0, .12); padding-top: 1.6mm; }

.badge .bd-rule {
  width: 14mm; height: .6mm; background: var(--accent); border-radius: 999px; margin-top: .8mm;
  flex: none;
}

/* ── 크기 조절 — 요소를 감싸는 선택 상자 + 우하단 손잡이(미리보기 전용) ── */
.badge .rs-frame {
  position: absolute; z-index: 9; pointer-events: none; display: none;
  border: 1px solid #2563eb; border-radius: 2px; box-sizing: border-box;
}
.badge .rs-handle {
  position: absolute; z-index: 10; width: 12px; height: 12px; display: none;
  background: #2563eb; border: 1.5px solid #fff; border-radius: 2px;
  cursor: nwse-resize; box-sizing: border-box;
}
@media print { .badge .rs-handle, .badge .rs-frame { display: none !important; } }

/* ── 드래그 정렬 가이드(미리보기 전용) — 인쇄에는 나가지 않는다 ── */
.badge .drag-guide { position: absolute; z-index: 9; pointer-events: none; background: #f43f5e; }
.badge .drag-guide.gv { top: 0; bottom: 0; width: 0.5px; }
.badge .drag-guide.gh { left: 0; right: 0; height: 0.5px; }
@media print { .badge .drag-guide { display: none !important; } }

/* ── 인쇄 시트 ── */
.sheet {
  position: relative; background: #fff; overflow: hidden;
  width: var(--page-w, 210mm); height: var(--page-h, 297mm);
  padding: var(--mt, 10mm) var(--mr, 10mm) var(--mb, 10mm) var(--ml, 10mm);
  display: grid;
  grid-template-columns: repeat(var(--cols, 2), var(--w, 90mm));
  grid-auto-rows: var(--h, 60mm);
  gap: var(--gap-y, 4mm) var(--gap-x, 4mm);
  justify-content: start; align-content: start;
}
.sheet .cell { position: relative; }
.sheet.cutlines .cell { outline: .2mm dashed rgba(0, 0, 0, .35); outline-offset: 0; }
.sheet.cropmarks .cell::before,
.sheet.cropmarks .cell::after {
  content: ''; position: absolute; background: rgba(0, 0, 0, .55);
}
.sheet.cropmarks .cell::before { left: -2.5mm; top: 0; width: 2mm; height: .2mm; }
.sheet.cropmarks .cell::after { left: 0; top: -2.5mm; width: .2mm; height: 2mm; }

/* ── 화면: 인쇄 영역 숨김 / 인쇄: 앱 숨김 ── */
#printRoot { display: none; }

@media print {
  html, body { background: #fff !important; height: auto !important; }
  .app, .toast-wrap, .gate { display: none !important; }
  #printRoot { display: block !important; }
  .sheet { page-break-after: always; break-after: page; box-shadow: none; border: 0; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
}
