/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --app-bg: #f0f2f8;
  --app-primary: #5c6bc0;
  --app-primary-dark: #3949ab;
  --app-text: #333;
  --app-text-light: #888;
  --app-white: #fff;
  --app-shadow: 0 2px 12px rgba(0,0,0,0.08);
  --app-radius: 12px;
  --app-border: #e0e4ef;

  /* Label design — controlled by JS */
  --label-header-bg: #1a1a2e;
  --label-header-text: #ffffff;
  --label-card-bg: #ffffff;
  --label-body-text: #333333;
  --label-accent-bg: #f3f0f8;
  --label-accent-text: #5c6bc0;
  --label-border: #e8e8e8;
  --label-font: 'Noto Sans KR', sans-serif;
  --label-font-size: 14px;
  --label-columns: 3;
}

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

body {
  font-family: 'Noto Sans KR', -apple-system, sans-serif;
  background: var(--app-bg);
  color: var(--app-text);
  min-height: 100vh;
}

/* ─── Toast ──────────────────────────────────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px; right: 20px;
  padding: 12px 20px;
  border-radius: 8px;
  background: #333;
  color: #fff;
  font-size: 14px;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s;
  z-index: 9999;
  pointer-events: none;
  max-width: 320px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #4caf50; }
.toast.error { background: #f44336; }
.toast.info { background: #2196f3; }

/* ─── Header ─────────────────────────────────────────────────────────────────── */
.app-header {
  background: var(--app-white);
  border-bottom: 1px solid var(--app-border);
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.header-inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}
.app-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--app-primary);
  white-space: nowrap;
}

/* Steps */
.steps { display: flex; align-items: center; gap: 6px; }
.step {
  display: flex; align-items: center; gap: 6px;
  opacity: 0.35;
  transition: opacity 0.3s;
}
.step.active { opacity: 1; }
.step.done { opacity: 0.65; }
.step-num {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--app-border);
  color: var(--app-text-light);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  transition: all 0.3s;
}
.step.active .step-num { background: var(--app-primary); color: #fff; }
.step.done .step-num { background: #4caf50; color: #fff; }
.step-label { font-size: 13px; font-weight: 500; }
.step-divider { width: 28px; height: 1px; background: var(--app-border); }

/* ─── Main ───────────────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}

/* ─── Sections ───────────────────────────────────────────────────────────────── */
.section { display: none; }
.section.active { display: block; animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
.section-header { margin-bottom: 28px; }
.section-header h2 { font-size: 22px; font-weight: 700; margin-bottom: 6px; }
.section-desc { color: var(--app-text-light); font-size: 14px; }

/* ─── Upload Grid ────────────────────────────────────────────────────────────── */
.upload-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
}
.upload-card {
  background: var(--app-white);
  border: 2px dashed var(--app-border);
  border-radius: var(--app-radius);
  padding: 32px 24px;
  text-align: center;
  position: relative;
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
}
.upload-card:hover {
  border-color: var(--app-primary);
  box-shadow: var(--app-shadow);
  transform: translateY(-2px);
}
.upload-badge {
  position: absolute; top: 12px; right: 12px;
  background: var(--app-primary);
  color: #fff;
  font-size: 11px; font-weight: 700;
  padding: 3px 10px;
  border-radius: 20px;
}
.upload-icon { font-size: 42px; margin-bottom: 14px; }
.upload-card h3 { font-size: 15px; font-weight: 700; margin-bottom: 6px; }
.upload-hint { font-size: 12px; color: var(--app-text-light); margin-bottom: 18px; font-family: monospace; }
.file-btn {
  display: inline-block;
  padding: 9px 22px;
  background: var(--app-primary);
  color: #fff;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px; font-weight: 500;
  transition: background 0.2s;
  user-select: none;
}
.file-btn:hover { background: var(--app-primary-dark); }
.file-name {
  margin-top: 12px;
  font-size: 12px;
  color: var(--app-text-light);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  min-height: 18px;
}
.file-name.has-file { color: #4caf50; font-weight: 600; }

/* 비밀번호 안내 */
.pw-notice {
  margin-top: 10px;
  font-size: 11px;
  color: #e65100;
  background: #fff3e0;
  border-radius: 6px;
  padding: 5px 8px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  padding: 10px 20px;
  border: none; border-radius: 8px;
  cursor: pointer;
  font-size: 14px; font-weight: 500;
  font-family: inherit;
  transition: all 0.2s;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--app-primary); color: #fff; }
.btn-primary:not(:disabled):hover {
  background: var(--app-primary-dark);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(92,107,192,0.4);
}
.btn-ghost {
  background: transparent;
  color: var(--app-text-light);
  border: 1px solid var(--app-border);
}
.btn-ghost:hover { background: var(--app-bg); color: var(--app-text); }
.btn-download {
  background: #fff;
  color: var(--app-primary);
  border: 2px solid var(--app-primary);
  width: 100%; justify-content: center;
  padding: 14px; font-size: 14px;
}
.btn-download:not(:disabled):hover { background: var(--app-primary); color: #fff; }
.btn-lg { padding: 14px 32px; font-size: 16px; }

/* ─── Action Bar ─────────────────────────────────────────────────────────────── */
.action-bar {
  display: flex; justify-content: flex-end; align-items: center; gap: 12px;
  margin-top: 28px; padding-top: 24px;
  border-top: 1px solid var(--app-border);
}

/* ─── Stats ──────────────────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 20px;
  margin-bottom: 20px;
}
.stat-card {
  background: #fff;
  border-radius: var(--app-radius);
  padding: 24px 20px;
  text-align: center;
  box-shadow: var(--app-shadow);
}
.stat-icon { font-size: 32px; margin-bottom: 8px; }
.stat-label { font-size: 13px; color: var(--app-text-light); margin-bottom: 6px; }
.stat-value { font-size: 30px; font-weight: 700; color: var(--app-primary); }

/* Match detail notice */
.match-detail {
  background: #fff8e1;
  border: 1px solid #ffe082;
  border-radius: 8px;
  padding: 12px 16px;
  font-size: 13px;
  color: #795548;
  margin-bottom: 20px;
  display: none;
  line-height: 1.6;
}
.match-detail.visible { display: block; }

/* ─── Download Grid ──────────────────────────────────────────────────────────── */
.download-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 8px;
}

/* ─── Label Section ──────────────────────────────────────────────────────────── */
.label-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0; margin-bottom: 20px;
  border-bottom: 1px solid var(--app-border);
  position: sticky; top: 64px;
  background: var(--app-bg);
  z-index: 50;
}
.toolbar-center { display: flex; align-items: center; gap: 12px; }
.label-count { font-size: 13px; color: var(--app-text-light); }

.label-workspace { display: flex; gap: 24px; align-items: flex-start; }
.labels-container { flex: 1; min-width: 0; }

.labels-grid {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 32px;
}

/* ─── Label Cards (A4, one per page) ────────────────────────────────────────── */
.label-card {
  width: 100%;
  max-width: 600px;
  min-height: 800px;
  background: #fff;
  font-family: var(--label-font);
  font-size: var(--label-font-size);
  color: var(--label-body-text, #1a1a1a);
  box-shadow: 0 4px 32px rgba(0,0,0,0.09), 0 1px 6px rgba(0,0,0,0.04);
  display: flex;
  flex-direction: column;
}

/* top double-line: thick bar + thin line */
.label-top-rule {
  flex-shrink: 0;
  height: 14px;
  background: linear-gradient(
    to bottom,
    var(--label-border, #1a1a1a) 0 5px,
    transparent 5px 13px,
    var(--label-border, #1a1a1a) 13px 14px
  );
}

.label-content {
  flex: 1;
  padding: 48px 60px 36px;
  display: flex;
  flex-direction: column;
}

/* Brand */
.label-brand {
  text-align: center;
  margin-bottom: 24px;
}
.label-brand-name {
  font-size: 1.5em;
  font-weight: 700;
  letter-spacing: 0.4em;
  text-indent: 0.4em;
  color: var(--label-body-text, #1a1a1a);
}

/* Divider with diamond */
.label-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  color: var(--label-border, #aaa);
  font-size: 0.55em;
}
.label-divider::before,
.label-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--label-border, #ccc);
  opacity: 0.5;
}

/* Customer name */
.label-customer {
  font-size: 2.2em;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--label-body-text, #1a1a1a);
  text-align: center;
  margin-bottom: 36px;
}

/* Options */
.label-options-label {
  font-size: 0.62em;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: #aaa;
  margin-bottom: 10px;
}
.label-options-list { margin-bottom: 4px; }

.opt-row {
  display: flex;
  align-items: baseline;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f0;
}
.opt-key {
  font-size: 0.82em;
  font-weight: 600;
  color: #666;
  min-width: 76px;
  flex-shrink: 0;
}
.opt-dots {
  flex: 1;
  height: 0;
  margin: 0 10px 4px;
  border-bottom: 1.5px dotted #d0d0d0;
  min-width: 24px;
  align-self: flex-end;
}
.opt-val {
  font-size: 0.9em;
  font-weight: 700;
  color: var(--label-body-text, #1a1a1a);
}
.opt-empty {
  font-size: 0.82em;
  color: #ccc;
  text-align: center;
  padding: 20px 0;
}

/* Extra meta */
.label-extra {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 5px;
}
.label-meta-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  font-size: 0.75em;
  color: #aaa;
  line-height: 1.5;
}

/* Tracking */
.label-tracking-no {
  margin-top: 18px;
  font-size: 0.72em;
  font-family: monospace;
  color: #c0c0c0;
  text-align: center;
  letter-spacing: 0.06em;
}

/* Push footer down */
.label-grow { flex: 1; min-height: 40px; }

/* Footer */
.label-footer { padding-top: 0; }
.label-footer-rule {
  height: 1px;
  background: var(--label-border, #ccc);
  opacity: 0.35;
  margin-bottom: 18px;
}
.label-thank {
  font-size: 0.82em;
  color: #aaa;
  font-style: italic;
  letter-spacing: 0.05em;
  text-align: center;
}

/* bottom double-line: thin line + thick bar */
.label-bottom-rule {
  flex-shrink: 0;
  height: 14px;
  background: linear-gradient(
    to bottom,
    var(--label-border, #1a1a1a) 0 1px,
    transparent 1px 9px,
    var(--label-border, #1a1a1a) 9px 14px
  );
}

/* ─── Design Panel ───────────────────────────────────────────────────────────── */
.design-panel {
  width: 272px; flex-shrink: 0;
  background: #fff;
  border-radius: var(--app-radius);
  box-shadow: var(--app-shadow);
  position: sticky; top: 128px;
  max-height: calc(100vh - 148px);
  overflow-y: auto;
  transition: all 0.3s;
}
.design-panel.hidden { display: none; }

.panel-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--app-border);
  position: sticky; top: 0;
  background: #fff; z-index: 1;
}
.panel-header h3 { font-size: 14px; font-weight: 700; }
.panel-body { padding: 16px; }

.panel-group { margin-bottom: 22px; }
.group-label {
  display: block;
  font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  color: var(--app-text-light);
  margin-bottom: 10px;
}

/* Presets */
.preset-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.preset-btn {
  padding: 8px 4px;
  border: 2px solid transparent; border-radius: 6px;
  cursor: pointer; font-size: 11px; font-weight: 700;
  font-family: inherit;
  background: var(--pc, #333); color: #fff;
  transition: all 0.2s;
}
.preset-btn:hover { opacity: 0.85; transform: scale(1.04); }

/* Field rows */
.field-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px;
}
.field-row label { font-size: 12px; color: var(--app-text-light); width: 76px; flex-shrink: 0; }
.text-input {
  flex: 1; padding: 6px 8px;
  border: 1px solid var(--app-border); border-radius: 6px;
  font-size: 13px; font-family: inherit;
  transition: border-color 0.2s;
}
.text-input:focus { outline: none; border-color: var(--app-primary); }
.select-input {
  flex: 1; padding: 6px 8px;
  border: 1px solid var(--app-border); border-radius: 6px;
  font-size: 12px; font-family: inherit; background: #fff;
}
.range-input { flex: 1; accent-color: var(--app-primary); cursor: pointer; }

/* Colors */
.color-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.color-field { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.color-field input[type="color"] {
  width: 36px; height: 36px;
  border: 1px solid var(--app-border); border-radius: 8px;
  cursor: pointer; padding: 2px; background: none;
}
.color-field span { font-size: 9px; color: var(--app-text-light); text-align: center; line-height: 1.2; }

/* Radio & Checkbox */
.radio-group, .check-group { display: flex; gap: 14px; flex-wrap: wrap; }
.radio-label, .check-label {
  display: flex; align-items: center; gap: 5px;
  font-size: 13px; cursor: pointer;
}

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  @page { size: A4; margin: 16mm 20mm; }

  .no-print,
  .app-header { display: none !important; }

  .app-main { padding: 0 !important; max-width: none !important; }

  .section { display: none !important; }
  #label-section { display: block !important; }

  .label-workspace { display: block !important; }
  .labels-container { width: 100% !important; }

  .labels-grid {
    display: block !important;
  }

  .label-card {
    width: 100% !important;
    max-width: none !important;
    min-height: 0 !important;
    height: calc(297mm - 32mm) !important;
    box-shadow: none !important;
    page-break-after: always !important;
    break-after: page !important;
  }

  .label-card:last-child {
    page-break-after: avoid !important;
    break-after: avoid !important;
  }
}

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .label-workspace { flex-direction: column; }
  .design-panel { width: 100%; position: static; max-height: none; }
  .color-grid { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 640px) {
  .header-inner { flex-direction: column; height: auto; padding: 12px 0; gap: 10px; }
  .stat-grid { grid-template-columns: 1fr; }
  .download-grid { grid-template-columns: 1fr; }
  .step-label { display: none; }
  .app-main { padding: 20px 16px; }
}
