/* === CSS 변수 === */
:root {
  --bg: #ffffff;
  --surface: #f8f9fa;
  --surface-2: #e9ecef;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --error: #dc2626;
  --success: #16a34a;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08);
  --shadow-md: 0 4px 6px rgba(0, 0, 0, .07), 0 2px 4px rgba(0, 0, 0, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", "Malgun Gothic", sans-serif;
  --transition: .15s ease;
}

[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #273548;
  --border: #334155;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --error: #f87171;
  --success: #4ade80;
}

/* === 리셋 === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font-family: inherit; }
img, svg { max-width: 100%; display: block; }

/* === 레이아웃 === */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
}

/* === 헤더 === */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 56px;
}
.logo {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--primary);
  flex-shrink: 0;
  letter-spacing: -.3px;
}
.logo:hover { text-decoration: none; opacity: .85; }
.site-nav {
  display: flex;
  gap: 4px;
  margin-left: auto;
}
.site-nav a {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: .875rem;
  transition: background var(--transition), color var(--transition);
}
.site-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 1rem;
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition);
  min-width: 40px;
  min-height: 36px;
}
.theme-toggle:hover { background: var(--surface-2); }

/* === 탭 === */
.tab-nav {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}
.tab-btn {
  padding: 12px 24px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* === 패널 그리드 === */
.panel-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
  align-items: start;
}
@media (min-width: 768px) {
  .panel-grid { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 1024px) {
  .panel-grid { grid-template-columns: 440px 1fr; }
}

/* === 입력 패널 === */
.input-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* === 폼 그룹 === */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
label {
  font-size: .875rem;
  font-weight: 500;
  color: var(--text);
}
input[type="text"],
input[type="url"],
input[type="email"],
input[type="tel"],
input[type="number"],
input[type="password"],
select,
textarea {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}
input.error { border-color: var(--error); }
textarea { resize: vertical; min-height: 80px; }
input[type="color"] {
  padding: 3px;
  height: 42px;
  cursor: pointer;
}
input[type="file"] {
  padding: 8px 12px;
  font-size: .875rem;
}

.checkbox-group label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 400;
  padding: 8px 0;
}
.checkbox-group input[type="checkbox"] {
  width: 18px;
  height: 18px;
  cursor: pointer;
  accent-color: var(--primary);
  flex-shrink: 0;
}

.input-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 18px;
}
.char-count { font-size: .8rem; color: var(--text-muted); }
.validation-msg { font-size: .8rem; }
.validation-msg.error { color: var(--error); }
.validation-msg.success { color: var(--success); }
.help-text { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

/* === 옵션 섹션 === */
.options-section {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 16px;
}
.options-title {
  font-size: .75rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
}
.options-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* === 고급 옵션 (details/summary) === */
.options-advanced {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.options-advanced > summary {
  padding: 12px 16px;
  cursor: pointer;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
  transition: background var(--transition);
}
.options-advanced > summary::-webkit-details-marker { display: none; }
.options-advanced > summary::before {
  content: "▶";
  font-size: .65rem;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.options-advanced[open] > summary::before { transform: rotate(90deg); }
.options-advanced[open] > summary { background: var(--surface-2); }
.advanced-inner { padding: 16px; }

/* === 버튼 === */
.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  font-size: .875rem;
  font-weight: 500;
  border: none;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  min-height: 44px;
  white-space: nowrap;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-icon {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 14px;
}
.btn-icon:hover:not(:disabled) { background: var(--border); }

/* === 미리보기 패널 === */
.preview-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.preview-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 280px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.preview-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .6px;
  align-self: flex-start;
  margin-bottom: 16px;
}
.preview-content {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
}
.preview-content svg { max-width: 100%; height: auto; }
.preview-content canvas { max-width: 100%; height: auto !important; }
.preview-empty {
  color: var(--text-muted);
  font-size: .9rem;
  text-align: center;
  padding: 32px 0;
}

/* === 광고 슬롯 === */
.ad-slot {
  background: var(--surface-2);
  border: 1px dashed var(--border);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}
.ad-slot::after { content: "AD"; font-size: .75rem; letter-spacing: 2px; color: var(--text-muted); opacity: .4; }
.ad-top { height: 90px; margin: 8px 0; }
.ad-bottom { height: 90px; margin: 16px auto; }
.ad-side { height: 250px; width: 100%; }

/* === 토스트 === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}
.toast {
  background: #1e293b;
  color: #f1f5f9;
  padding: 12px 20px;
  border-radius: var(--radius);
  font-size: .875rem;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in .2s ease;
  max-width: 320px;
}
[data-theme="dark"] .toast { background: #f1f5f9; color: #1e293b; }
.toast.error { background: var(--error); color: #fff; }
.toast.success { background: var(--success); color: #fff; }
@keyframes toast-in {
  from { transform: translateY(8px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* === 유틸리티 === */
.hidden { display: none !important; }
.qr-form.hidden { display: none !important; }

/* === 메인 / 푸터 === */
.main-layout {
  padding-top: 24px;
  padding-bottom: 40px;
  flex: 1;
}
.site-footer {
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 0;
  font-size: .8rem;
  color: var(--text-muted);
}
.site-footer .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}
.site-footer nav { display: flex; gap: 12px; }
.site-footer a { color: var(--text-muted); }
.site-footer a:hover { color: var(--text); }

/* === 대량 생성 페이지 === */
.bulk-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 24px;
  align-items: start;
}
@media (max-width: 900px) {
  .bulk-layout { grid-template-columns: 1fr; }
}

.bulk-settings {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.radio-group {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.radio-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-weight: 400;
  font-size: .9rem;
}
.radio-group input[type="radio"] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

.input-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  margin: 0 -20px;
  padding: 0 20px;
}
.input-tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), border-color var(--transition);
}
.input-tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.csv-drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius-sm);
  padding: 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.csv-drop-zone:hover, .csv-drop-zone.drag-over {
  border-color: var(--primary);
  background: rgba(37,99,235,.04);
}
.csv-drop-zone input[type="file"] { display: none; }
.csv-drop-zone p { font-size: .875rem; color: var(--text-muted); margin-top: 8px; }

/* 진행률 */
.progress-wrap {
  background: var(--surface-2);
  border-radius: 999px;
  height: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 999px;
  transition: width .2s ease;
  width: 0%;
}
.progress-text {
  font-size: .8rem;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
}

/* 결과 영역 */
.results-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.results-header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.results-stat {
  font-size: .9rem;
  color: var(--text-muted);
  margin-right: auto;
}
.results-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.result-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: box-shadow var(--transition);
}
.result-card:hover { box-shadow: var(--shadow-md); }
.result-card.has-error {
  border-color: var(--error);
  background: var(--error-bg, #fef2f2);
}
.result-img {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80px;
}
.result-img svg { max-width: 100%; height: auto; }
.result-img img { max-width: 100%; height: auto; display: block; }
.result-value {
  font-size: .7rem;
  color: var(--text-muted);
  text-align: center;
  word-break: break-all;
  max-height: 2.4em;
  overflow: hidden;
  width: 100%;
}
.result-error-msg {
  font-size: .7rem;
  color: var(--error);
  text-align: center;
  word-break: break-all;
}

/* 라벨 PDF 프리셋 */
.preset-btns {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset-btn {
  padding: 5px 12px;
  font-size: .8rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}
.preset-btn.active { border-color: var(--primary); color: var(--primary); background: rgba(37,99,235,.06); }
.preset-btn:hover:not(.active) { background: var(--border); }

.empty-results {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: .95rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* === 인쇄 === */
.print-only { display: none; }
@media print {
  .site-header, .tab-nav, .input-panel, .ad-slot,
  .toast-container, .action-buttons, .site-footer { display: none !important; }
  .print-only {
    display: flex !important;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
  }
  .print-only img, .print-only svg { max-width: 80mm; }
  body { background: white; color: black; }
}

/* === 슬라이드 UI === */
.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: 16px;
}
.slide-counter {
  font-size: .8rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
}
.slide-wrapper {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 8px;
}
.slide-nav {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 38px;
  height: 38px;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition), opacity var(--transition);
  padding: 0;
}
.slide-nav:hover:not(:disabled) { background: var(--border); }
.slide-nav:disabled { opacity: .25; cursor: not-allowed; }
.slide-dots {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-top: 12px;
  flex-wrap: wrap;
}
.slide-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  border: none;
  background: var(--border);
  cursor: pointer;
  padding: 0;
  transition: background var(--transition), transform var(--transition);
}
.slide-dot.active {
  background: var(--primary);
  transform: scale(1.35);
}
.label-hint {
  font-weight: 400;
  color: var(--text-muted);
  font-size: .8rem;
}

/* === 반응형 === */
@media (max-width: 767px) {
  .site-nav { display: none; }
  .tab-btn { padding: 10px 16px; font-size: .9rem; }
  .input-panel { padding: 16px; }
  .options-grid { grid-template-columns: 1fr; }
  .action-buttons .btn { flex: 1 1 calc(50% - 4px); }
}
@media (max-width: 420px) {
  .action-buttons .btn { flex: 1 1 100%; }
}
