:root {
  --blue: #1d4ed8;
  --blue-dark: #1e40af;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --danger: #dc2626;
  --ok: #16a34a;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Pretendard", "Malgun Gothic", "맑은 고딕", system-ui, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
}

/* ---------- 상단 바 ---------- */
.topbar {
  background: linear-gradient(135deg, #1e3a8a, #1d4ed8);
  color: #fff; padding: 14px 24px 0;
  display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 12px; padding-bottom: 14px; }
.brand-mark {
  font-weight: 900; font-size: 26px; letter-spacing: 2px;
  background: rgba(255,255,255,.15); border-radius: 10px; padding: 6px 12px;
}
.brand h1 { font-size: 19px; font-weight: 700; }
.brand p { font-size: 12px; opacity: .8; }
.tabs { display: flex; gap: 4px; }
.tab {
  border: none; background: rgba(255,255,255,.12); color: #dbeafe;
  padding: 10px 22px; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: 10px 10px 0 0;
}
.tab:hover { background: rgba(255,255,255,.22); }
.tab.active { background: var(--bg); color: var(--blue-dark); }

main { max-width: 1280px; margin: 0 auto; padding: 20px 16px 40px; }
.page { display: none; }
.page.active { display: block; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 960px) { .grid-2 { grid-template-columns: 1fr; } }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; box-shadow: 0 1px 3px rgba(15,23,42,.06); margin-bottom: 16px;
}
.card h2 { font-size: 16px; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 2px solid var(--blue); display: inline-block; }
.card h3 { font-size: 14px; margin: 18px 0 8px; }

/* ---------- 폼 ---------- */
label { font-size: 12px; font-weight: 600; color: var(--muted); display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--blue); }
textarea { font-family: Consolas, monospace; font-size: 12px; }
.form-row { margin-bottom: 12px; display: flex; gap: 10px; align-items: end; flex-wrap: wrap; }
.form-row > label { flex: 0 0 100%; margin-bottom: 0; }
.form-row > input, .form-row > select { flex: 1; }
.form-row.three { display: grid; grid-template-columns: 1fr 1fr 1fr; align-items: end; }
.form-row.four { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; align-items: end; }
.badge {
  background: var(--blue); color: #fff; font-weight: 800; font-size: 18px;
  padding: 8px 16px; border-radius: 8px; letter-spacing: 2px; font-family: Consolas, monospace;
}

/* ---------- 테이블 ---------- */
.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.h200 { max-height: 200px; } .h240 { max-height: 240px; } .h480 { max-height: 480px; }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
  background: #f8fafc; text-align: left; padding: 8px 10px; position: sticky; top: 0;
  border-bottom: 1px solid var(--border); font-size: 12px; color: var(--muted); white-space: nowrap;
}
.table td { padding: 7px 10px; border-bottom: 1px solid #f1f5f9; white-space: nowrap; }
.table.hover tbody tr { cursor: pointer; }
.table.hover tbody tr:hover { background: #eff6ff; }
.table tbody tr.selected { background: #dbeafe; }
.table code { font-family: Consolas, monospace; font-size: 12px; }

/* ---------- 선택 품목 ---------- */
.selected-box {
  border: 2px dashed var(--border); border-radius: 10px; padding: 12px; margin: 12px 0;
  background: #f8fafc;
}
.selected-box.has { border-style: solid; border-color: var(--blue); background: #eff6ff; }
.sel-empty { color: var(--muted); text-align: center; padding: 8px; }
.sel-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sel-grid span { display: block; font-size: 11px; color: var(--muted); }
.sel-grid strong { font-size: 14px; font-family: Consolas, monospace; }

.lot-preview { margin: 12px 0; }
.lot-preview code {
  display: block; background: #0f172a; color: #4ade80; padding: 10px 12px;
  border-radius: 8px; font-size: 15px; letter-spacing: 1px; font-family: Consolas, monospace;
  overflow-x: auto;
}

/* ---------- 버튼 ---------- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 8px; font-size: 14px; font-weight: 600;
  cursor: pointer; font-family: inherit;
}
.btn:hover:not(:disabled) { background: #f1f5f9; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--blue-dark); }
.btn.danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover:not(:disabled) { background: #fef2f2; }
.btn.lg { width: 100%; padding: 13px; font-size: 16px; margin-top: 4px; }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0; }
.btn-row.right { justify-content: flex-end; }
.file-btn { display: inline-flex; align-items: center; margin-bottom: 0; color: var(--text); font-size: 14px; }
.spacer { flex: 1; }

.hint { font-size: 12px; color: var(--muted); margin: 8px 0; }
.hint.ok { color: var(--ok); font-weight: 600; }
.hint.err { color: var(--danger); font-weight: 600; }

/* ---------- 라벨 미리보기 ---------- */
.label-frame {
  border: 1px solid var(--border); border-radius: 10px; background: #f8fafc;
  min-height: 150px; display: flex; align-items: center; justify-content: center;
  padding: 14px; overflow-x: auto;
}
.label-placeholder { color: var(--muted); }
.label-sheet {
  background: #fff; border: 1px solid #cbd5e1; box-shadow: 0 2px 6px rgba(0,0,0,.12);
  width: 368px; height: 124px; /* 92x31mm 비율 */
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  padding: 8px;
}
.label-sheet svg { max-width: 100%; height: auto; }
.issued-info { font-size: 13px; margin: 10px 0; color: var(--muted); }

.zpl-box { margin: 10px 0; }
.zpl-box summary { cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

/* ---------- 필터 행 ---------- */
.filter-row { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row > div { min-width: 160px; }

/* ---------- 다이얼로그 ---------- */
dialog { border: none; border-radius: 14px; padding: 0; box-shadow: 0 10px 40px rgba(0,0,0,.25); width: 380px; max-width: 92vw; }
dialog::backdrop { background: rgba(15,23,42,.45); }
.dialog-form { padding: 22px; display: flex; flex-direction: column; gap: 12px; }
.dialog-form h3 { font-size: 16px; }
.dialog-form label { font-size: 13px; color: var(--text); }
.dialog-form input { margin-top: 4px; }

.stat-row { display: flex; gap: 16px; margin-top: 14px; }
.stat-row .stat { background: #f8fafc; border: 1px solid var(--border); border-radius: 10px; padding: 12px 18px; }
.stat-row .stat b { display: block; font-size: 20px; color: var(--blue-dark); }
.stat-row .stat span { font-size: 12px; color: var(--muted); }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 20px 0 30px; }

/* ---------- 인쇄 ---------- */
.print-area { display: none; }
@media print {
  body > *:not(.print-area) { display: none !important; }
  .print-area { display: block !important; }
  .print-label {
    width: 92mm; height: 31mm; page-break-after: always;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
  }
  .print-label svg { max-width: 86mm; max-height: 27mm; }
  @page { size: 92mm 31mm; margin: 0; }
}

/* ---------- QR 라벨 ---------- */
.label-sheet.qr { flex-direction: row; justify-content: flex-start; gap: 12px; padding: 10px 14px; }
.label-sheet.qr svg { height: 100px; width: 100px; flex: none; }
.qr-text { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.qr-text strong { font-size: 13px; font-family: Consolas, monospace; }
.qr-text code { font-size: 11px; font-family: Consolas, monospace; word-break: break-all; }
@media print {
  .print-label.qr { flex-direction: row; gap: 4mm; justify-content: flex-start; padding-left: 6mm; }
  .print-label.qr svg { max-height: 24mm; max-width: 24mm; width: auto; }
  .print-label.qr .qr-text strong { font-size: 9pt; }
  .print-label.qr .qr-text code { font-size: 8pt; }
}
/* ---------- 부서 선택 ---------- */
.dept-box { display: flex; align-items: center; gap: 8px; padding-bottom: 14px; }
.dept-box label { color: #dbeafe; margin: 0; font-size: 13px; font-weight: 600; }
.dept-box select { width: 130px; padding: 8px 10px; border-radius: 8px; border: none; font-weight: 600; font-size: 14px; }
.stat-row .dept-stat { max-width: 420px; }
/* ---------- 라벨 추적 ---------- */
.scan-card { border-radius: 12px; padding: 16px; margin-top: 12px; border: 2px solid; }
.scan-card.ok { border-color: var(--ok); background: #f0fdf4; }
.scan-card.bad { border-color: var(--danger); background: #fef2f2; }
.scan-card h4 { margin-bottom: 10px; font-size: 15px; }
.scan-card.ok h4 { color: var(--ok); }
.scan-card.bad h4 { color: var(--danger); }
.scan-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 8px; }
@media (max-width: 800px) { .scan-grid { grid-template-columns: repeat(2, 1fr); } }
.scan-grid span { display: block; font-size: 11px; color: var(--muted); }
.scan-grid strong { font-size: 14px; font-family: Consolas, monospace; word-break: break-all; }
#scanInput { font-size: 16px; font-family: Consolas, monospace; }
/* ---------- 발행형식 다이얼로그 ---------- */
.token-row { display: flex; flex-wrap: wrap; gap: 4px; }
.token-row button {
  border: 1px solid var(--border); background: #f8fafc; border-radius: 6px;
  padding: 3px 8px; font-size: 12px; cursor: pointer; font-family: Consolas, monospace;
}
.token-row button:hover { background: #eff6ff; border-color: var(--blue); }
.label-lines { display: flex; flex-direction: column; align-items: center; font-size: 12px; font-family: Consolas, monospace; line-height: 1.3; }
@media print { .print-label .label-lines { font-size: 8pt; } }