/* ==========================================================================
   Barcode Studio Pro - Modern Glassmorphism & High-Precision Design System
   ========================================================================== */

:root {
  /* Color Palette */
  --bg-main: #0b0f19;
  --bg-card: rgba(22, 30, 46, 0.75);
  --bg-card-solid: #161e2e;
  --bg-input: rgba(15, 23, 42, 0.65);
  --border-color: rgba(255, 255, 255, 0.08);
  --border-hover: rgba(99, 102, 241, 0.4);
  
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-glow: rgba(99, 102, 241, 0.25);
  
  --accent: #8b5cf6;
  --accent-pink: #ec4899;
  --accent-cyan: #06b6d4;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;

  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-xl: 24px;

  --shadow-sm: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(99, 102, 241, 0.25);

  --font-sans: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
}

/* Light Theme Variables */
[data-theme="light"] {
  --bg-main: #f1f5f9;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-solid: #ffffff;
  --bg-input: rgba(248, 250, 252, 0.9);
  --border-color: rgba(0, 0, 0, 0.08);
  --border-hover: rgba(99, 102, 241, 0.5);

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #64748b;

  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 16px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 16px 24px rgba(0, 0, 0, 0.08);
  --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.15);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
  position: relative;
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(139, 92, 246, 0.1) 0px, transparent 50%),
    radial-gradient(at 50% 50%, rgba(6, 182, 212, 0.05) 0px, transparent 60%);
  background-attachment: fixed;
}

/* App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
}

.brand-container {
  display: flex;
  align-items: center;
  gap: 0.85rem;
}

.brand-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 12px var(--primary-glow);
}

.brand-info h1 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #a5b4fc, #c084fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.brand-badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.15);
  color: #818cf8;
  border: 1px solid rgba(99, 102, 241, 0.3);
  margin-left: 0.4rem;
}

.brand-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.btn-icon {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  width: 40px;
  height: 40px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-icon:hover {
  border-color: var(--border-hover);
  background: rgba(99, 102, 241, 0.1);
  transform: translateY(-2px);
}

/* Main Layout */
.main-container {
  max-width: 860px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (max-width: 768px) {
  .main-container {
    padding: 0.5rem 0.65rem 2rem !important;
    gap: 0.65rem !important;
  }
  .app-header {
    padding: 0.5rem 0.85rem !important;
  }
  .brand-logo {
    width: 32px !important;
    height: 32px !important;
  }
  .brand-info h1 {
    font-size: 1.05rem !important;
  }
  .brand-desc {
    display: none !important; /* 모바일에서 불필요한 설명 숨겨서 공간 확보 */
  }

  /* 바코드 카드 극단적 상하 여백 축소 & 일정하고 안정적인 높이 고정 */
  .preview-card {
    min-height: 0 !important;
    padding: 0.35rem 0.5rem !important;
    border-radius: var(--radius-md) !important;
  }
  .preview-toolbar {
    top: 0.35rem !important;
    right: 0.35rem !important;
  }
  .preview-toolbar .btn-icon {
    width: 28px !important;
    height: 28px !important;
  }
  .preview-canvas-container {
    height: 140px !important;
    min-height: 140px !important;
    max-height: 140px !important;
    padding: 0.35rem 0.5rem !important;
    border-radius: var(--radius-sm) !important;
    width: 100% !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    overflow: hidden !important;
  }
  #barcodeSvg {
    max-width: 95% !important;
    max-height: 95% !important;
    width: auto !important;
    height: auto !important;
    margin: 0 auto !important;
    display: block !important;
  }

  /* 입력 카드 슬림화 */
  .direct-input-card {
    padding: 0.65rem 0.75rem !important;
    gap: 0.4rem !important;
    border-radius: var(--radius-md) !important;
  }
  .form-input, .form-select {
    padding: 0.5rem 0.7rem !important;
    font-size: 0.88rem !important;
  }
  .pill-btn {
    padding: 0.15rem 0.45rem !important;
    font-size: 0.7rem !important;
  }

  /* 상세 디자인 옵션 슬림화 (첫 화면에 쏙 들어가도록) */
  .settings-panel {
    padding: 0.65rem 0.75rem !important;
    border-radius: var(--radius-md) !important;
  }
  .settings-panel .panel-title {
    font-size: 0.95rem !important;
    margin-bottom: 0.35rem !important;
  }
  .options-tabs {
    margin-bottom: 0.45rem !important;
  }
  .tab-btn {
    padding: 0.3rem 0.65rem !important;
    font-size: 0.78rem !important;
  }
  .option-row {
    gap: 0.6rem !important;
    margin-bottom: 0.4rem !important;
  }
  .slider-header {
    font-size: 0.75rem !important;
    margin-bottom: 0.2rem !important;
  }
}

.preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 0.6rem 1rem !important;
  min-height: auto !important;
}

.preview-canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  height: 160px;
  min-height: 160px;
  max-height: 160px;
  padding: 0.5rem 0.85rem !important;
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.18);
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

#barcodeSvg {
  max-width: 95% !important;
  max-height: 95% !important;
  width: auto !important;
  height: auto !important;
  display: block;
  margin: 0 auto;
}

.direct-input-card {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  padding: 1rem 1.25rem !important;
  background: var(--bg-card);
  border-radius: var(--radius-xl);
}

.direct-input-card .form-group {
  margin-bottom: 0;
}

/* Glass Card */
.glass-panel {
  background: var(--bg-card);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  box-shadow: var(--shadow-lg);
  transition: border-color 0.3s ease;
}

.glass-panel:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

/* Panel Header */
.panel-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  color: var(--text-main);
}

.panel-title svg {
  color: var(--primary);
}

/* Form Styles */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.4rem;
}

.form-input, .form-select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 0.95rem;
  font-family: inherit;
  transition: all 0.2s ease;
  outline: none;
}

.form-input:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-with-actions {
  display: flex;
  gap: 0.5rem;
}

.input-with-actions .form-input {
  flex: 1;
  font-family: var(--font-mono);
  font-weight: 500;
}

.btn-secondary-sm {
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: #a5b4fc;
  border-radius: var(--radius-md);
  padding: 0 0.85rem;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s ease;
}

.btn-secondary-sm:hover {
  background: rgba(99, 102, 241, 0.2);
  border-color: var(--primary);
}

.input-feedback {
  font-size: 0.78rem;
  margin-top: 0.35rem;
  min-height: 1.2rem;
  color: var(--text-dim);
}

.input-feedback.error {
  color: var(--danger);
}

.input-feedback.success {
  color: var(--success);
}

/* Quick Format Pills */
.format-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.5rem;
}

.pill-btn {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.75rem;
  font-weight: 500;
  padding: 0.25rem 0.65rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.pill-btn:hover, .pill-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
  box-shadow: 0 2px 8px var(--primary-glow);
}

/* Accordion Options Section */
.options-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.tab-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  padding: 0.5rem 1rem;
  cursor: pointer;
  position: relative;
  transition: color 0.2s ease;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: -1px;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--primary);
  border-radius: 2px 2px 0 0;
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* Option Grid Controls */
.option-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
  margin-bottom: 0.85rem;
}

.slider-group {
  display: flex;
  flex-direction: column;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.slider-value {
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--primary);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
  height: 6px;
  background: var(--bg-input);
  border-radius: 4px;
}

.color-input-wrapper {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--bg-input);
  padding: 0.4rem 0.6rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.color-input-wrapper input[type="color"] {
  border: none;
  background: none;
  width: 28px;
  height: 28px;
  cursor: pointer;
  border-radius: 4px;
}

.color-hex {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-main);
}

/* Switch Toggle */
.switch-group {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0;
}

.switch-label {
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-main);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background-color: var(--bg-input);
  border: 1px solid var(--border-color);
  transition: .3s;
  border-radius: 24px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 16px;
  width: 16px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-muted);
  transition: .3s;
  border-radius: 50%;
}

input:checked + .slider {
  background-color: var(--primary);
  border-color: var(--primary);
}

input:checked + .slider:before {
  transform: translateX(20px);
  background-color: #ffffff;
}

/* Right Section: Preview & Actions */
.preview-column {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  padding: 2.5rem 1.5rem;
  min-height: 380px;
}

.preview-toolbar {
  position: absolute;
  top: 1rem;
  right: 1rem;
  display: flex;
  gap: 0.5rem;
  z-index: 10;
}

.preview-canvas-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  padding: 1.5rem;
  border-radius: var(--radius-lg);
  background: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  transition: all 0.3s ease;
  position: relative;
}

.preview-canvas-container.transparent-bg {
  background: repeating-conic-gradient(#e2e8f0 0% 25%, #ffffff 0% 50%) 50% / 16px 16px;
}

#barcodeSvg {
  max-width: 100%;
  height: auto;
  display: block;
}

/* Laser Scanline Effect */
.scanline {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, #ef4444, transparent);
  box-shadow: 0 0 10px #ef4444;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.scanline.active {
  opacity: 1;
  animation: scanAnim 2.5s infinite alternate ease-in-out;
}

@keyframes scanAnim {
  0% { top: 10%; }
  100% { top: 90%; }
}

/* Main Action Button Bar */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;
  width: 100%;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #ffffff;
  box-shadow: 0 4px 15px var(--primary-glow);
}

.btn-primary:hover {
  box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
  transform: translateY(-2px);
}

.btn-glass {
  background: var(--bg-card);
  border-color: var(--border-color);
  color: var(--text-main);
}

.btn-glass:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-hover);
  transform: translateY(-2px);
}

/* History Section */
.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 0.3rem;
}

.history-card {
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.history-card:hover {
  border-color: var(--border-hover);
  background: rgba(99, 102, 241, 0.08);
  transform: translateY(-2px);
}

.history-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.history-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  padding: 0.15rem 0.45rem;
  border-radius: 4px;
}

.history-text {
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  color: #ffffff;
  padding: 0.85rem 1.25rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  transform: translateY(20px);
  opacity: 0;
  animation: toastIn 0.3s forwards ease;
  pointer-events: auto;
}

.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.info { border-left: 4px solid var(--primary); }

@keyframes toastIn {
  to { transform: translateY(0); opacity: 1; }
}

/* Label Print Modal */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 1.5rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-card {
  background: var(--bg-card-solid);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 800px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.85rem;
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border-color);
}

/* Print Sheet Grid inside Modal & Print */
.print-sheet-preview {
  background: #ffffff;
  color: #000000;
  padding: 1rem;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  margin-top: 1rem;
  display: grid;
  gap: 10px;
  max-height: 380px;
  overflow-y: auto;
}

.print-sheet-preview.layout-single {
  grid-template-columns: 1fr;
  text-align: center;
}

.print-sheet-preview.layout-2x7 {
  grid-template-columns: repeat(2, 1fr);
}

.print-sheet-preview.layout-3x8 {
  grid-template-columns: repeat(3, 1fr);
}

.print-sheet-preview.layout-4x10 {
  grid-template-columns: repeat(4, 1fr);
}

.print-label-item {
  border: 1px dashed #cbd5e1;
  border-radius: 4px;
  padding: 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #ffffff;
}

.print-label-item svg {
  max-width: 100%;
  height: auto;
}

/* ==========================================================================
   Print Media Query (CRITICAL for Label Printing)
   ========================================================================== */
@media print {
  body * {
    visibility: hidden;
  }

  #printSection, #printSection * {
    visibility: visible;
  }

  #printSection {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
    background: #ffffff;
    color: #000000;
  }

  .print-sheet-preview {
    max-height: none !important;
    overflow: visible !important;
    box-shadow: none !important;
    padding: 0 !important;
  }

  .print-label-item {
    border: none !important;
    page-break-inside: avoid;
  }
}
