/* ---- Variables ---- */
:root {
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #1a1a1a;
  --text-muted: #5c5c5c;
  --border: #e0e0e0;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --secondary: #64748b;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --font: 'DM Sans', -apple-system, BlinkMacSystemFont, sans-serif;
}

/* ---- Reset & base ---- */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
}

/* ---- App layout ---- */
.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.header {
  text-align: center;
  margin-bottom: 2rem;
}

.header h1 {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text);
}

.subtitle {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.main {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 2rem;
  align-items: start;
}

@media (max-width: 900px) {
  .main {
    grid-template-columns: 1fr;
  }
}

/* ---- Controls ---- */
.controls {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.control-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.control-card h2 {
  margin: 0 0 1rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
}

.field {
  margin-bottom: 1rem;
}

.field:last-child {
  margin-bottom: 0;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 0.35rem;
}

.field input[type="file"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.field textarea {
  resize: vertical;
  min-height: 4rem;
}

.field input[type="file"]:focus,
.field input[type="text"]:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.2);
}

.hint {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.sample-link {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--primary);
  margin-top: 0.5rem;
  text-decoration: none;
}

.sample-link:hover {
  text-decoration: underline;
}

.orientation-field {
  margin-bottom: 0;
}

.radio-group {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.radio-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 400;
  cursor: pointer;
}

.radio-option input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.actions .btn {
  width: 100%;
  margin-bottom: 0.5rem;
}

.actions .btn:last-child {
  margin-bottom: 0;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--surface);
  color: var(--secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.8rem;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
}

.btn-danger:hover {
  background: #b91c1c;
}

.customer-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.75rem;
  flex-wrap: wrap;
}

.customer-config {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.customer-config .field {
  margin-bottom: 0.75rem;
}

.customer-config .field:last-of-type {
  margin-bottom: 0;
}

.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.checkbox-option {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  font-weight: 400;
  cursor: pointer;
}

.checkbox-option input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

/* ---- Preview area ---- */
.preview-area {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.preview-area h2 {
  margin: 0 0 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.label-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 320px;
  padding: 1rem;
  background: #e8e8e8;
  border-radius: 6px;
}

/* ---- Label: 6 x 4 inches (landscape) or 4 x 6 (portrait) ---- */
.label {
  width: 360px;
  height: 240px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.label-wrapper[data-orientation="portrait"] .label {
  width: 240px;
  height: 360px;
}

.label-top {
  flex: 0 0 auto;
  padding: 0.5rem 0.75rem 0.25rem;
  text-align: center;
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 72px;
  margin-bottom: 0.25rem;
}

.label-top img#label-logo {
  max-height: 68px;
  max-width: 200px;
  object-fit: contain;
}

.logo-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 140px;
  height: 68px;
  border: 1px dashed var(--border);
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.logo-placeholder[hidden] {
  display: none;
}

.company-name {
  margin: 0;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text);
}

.label-divider {
  height: 1px;
  background: var(--text);
  margin: 0.25rem 0.5rem;
}

.label-divider-top {
  flex-shrink: 0;
  margin-top: 0.2rem;
  margin-bottom: 0.25rem;
}

.label-divider-bottom {
  margin-top: 0.25rem;
  margin-bottom: 0.4rem;
}

.label-middle {
  flex: 0 0 auto;
  padding: 0.35rem 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
}

.barcode-container {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
}

.barcode-svg {
  max-width: 100%;
  height: auto;
  max-height: 44px;
}

.barcode-placeholder {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.label-bottom {
  flex: 1 1 auto;
  padding: 0.5rem 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.label-bottom-company {
  margin: 0;
  margin-top: 0.25rem;
  font-size: 0.65rem;
  font-weight: 600;
  color: var(--text);
  text-align: center;
  line-height: 1.25;
}

.label-bottom-line {
  display: block;
}

.bottom-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1rem;
  align-content: start;
  width: 100%;
  font-size: 0.8rem;
}

.bottom-labels {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-weight: 600;
  color: var(--text);
}

.bottom-values {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  color: var(--text);
}

/* ---- Multi-label print container (hidden on screen) ---- */
.print-labels-container {
  display: none;
}

/* ---- Print: exact 6" x 4" (single) or multiple labels ---- */
@media print {
  body * {
    visibility: hidden;
  }

  /* Multiple labels: hide app, show only print container */
  body.print-multiple .app {
    display: none !important;
  }

  body.print-multiple .print-labels-container,
  body.print-multiple .print-labels-container * {
    visibility: visible !important;
  }

  body.print-multiple .print-labels-container {
    display: block !important;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
  }

  .print-labels-container .label-print-page {
    page-break-after: always;
    width: 6in;
    height: 4in;
    overflow: hidden;
  }

  .print-labels-container .label-print-page[data-orientation="portrait"] {
    width: 4in;
    height: 6in;
  }

  .print-labels-container .label {
    width: 6in;
    height: 4in;
    border: none;
    border-radius: 0;
    box-shadow: none;
  }

  .print-labels-container .label-print-page[data-orientation="portrait"] .label {
    width: 4in;
    height: 6in;
  }

  /* Single label: existing layout */
  .app .header,
  .app .main .controls,
  .preview-area h2 {
    display: none !important;
  }

  .preview-area {
    padding: 0;
    border: none;
    box-shadow: none;
    background: transparent;
  }

  .label-wrapper,
  .label-wrapper * {
    visibility: visible;
  }

  .label-wrapper {
    position: absolute;
    left: 0;
    top: 0;
    width: 6in;
    height: 4in;
    margin: 0;
    padding: 0;
    background: transparent;
    min-height: 0;
  }

  .label-wrapper[data-orientation="portrait"] {
    width: 4in;
    height: 6in;
  }

  .label {
    width: 6in;
    height: 4in;
    border: none;
    border-radius: 0;
    box-shadow: none;
    page-break-after: always;
  }

  .label-wrapper[data-orientation="portrait"] .label {
    width: 4in;
    height: 6in;
  }

  .label-top {
    padding: 0.2in 0.15in 0.1in;
  }

  .logo-container {
    min-height: 0.75in;
  }

  .label-top img#label-logo {
    max-height: 0.7in;
    max-width: 2.5in;
  }

  .company-name {
    font-size: 8pt;
  }

  .label-divider {
    margin: 0.05in 0.15in;
  }

  .label-middle {
    padding: 0.1in 0.15in;
    min-height: 0.65in;
  }

  .barcode-svg {
    max-height: 0.55in;
  }

  .label-bottom {
    padding: 0.15in 0.15in 0.12in;
  }

  .label-bottom-company {
    font-size: 7pt;
  }

  .bottom-grid {
    font-size: 9pt;
  }

  @page {
    size: 6in 4in;
    margin: 0;
  }

  html, body {
    margin: 0;
    padding: 0;
    background: white;
    width: 6in;
    height: 4in;
    overflow: hidden;
  }

  }
