:root {
  --background-color: #f4f7fa;
  --card-background-color: #ffffff;
  --header-background-color: #111827;
  --text-color-primary: #1f2937;
  --text-color-secondary: #6b7280;
  --text-color-light: #f9fafb;
  --primary-color: #4f46e5;
  --primary-color-hover: #4338ca;
  --success-color: #22c55e;
  --success-color-hover: #16a34a;
  --checked-color: #3b82f6;
  --border-color: #e5e7eb;
  --input-background: #374151;
  --button-disabled-background: #9ca3af;
  --danger-color: #ef4444;
  --shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --border-radius: 0.5rem;
}

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

body {
  font-family: 'Inter', sans-serif;
  background-color: var(--background-color);
  color: var(--text-color-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#root {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

header {
  background-color: var(--header-background-color);
  color: var(--text-color-light);
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 1.25rem;
  font-weight: 600;
}

main {
  flex-grow: 1;
  padding: 2rem;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.main-header {
  margin-bottom: 2rem;
}

.main-header h1 {
  font-size: 2.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.main-header p {
  color: var(--text-color-secondary);
  font-size: 1.125rem;
}

.card {
  background-color: var(--card-background-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  margin-bottom: 2rem;
}

.card h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1.5rem;
}

.form-container {
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
}

.form-container input {
  flex: 1;
  min-width: 200px;
  padding: 0.75rem 1rem;
  background-color: var(--input-background);
  color: var(--text-color-light);
  border: 1px solid transparent;
  border-radius: var(--border-radius);
  font-size: 1rem;
  outline: none;
  transition: border-color 0.2s;
}

.form-container input::placeholder {
  color: #9ca3af;
}

.form-container input:focus {
  border-color: var(--primary-color);
}

.btn {
  padding: 0.75rem 1.5rem;
  border: none;
  border-radius: var(--border-radius);
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s, opacity 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  height: 44px;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}

.btn-primary:hover {
  background-color: var(--primary-color-hover);
}

.btn-success {
    background-color: var(--success-color);
    color: white;
}
.btn-success:hover {
    background-color: var(--success-color-hover);
}

.btn:disabled {
  background-color: var(--button-disabled-background);
  cursor: not-allowed;
  opacity: 0.7;
}

.saved-barcodes-header {
  margin-bottom: 2rem;
}

.saved-barcodes-header h2 {
  font-size: 1.875rem;
  font-weight: 600;
}

.controls-container {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.selection-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--text-color-secondary);
  cursor: pointer;
  user-select: none;
}

.checkbox-icon {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-color);
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
  flex-shrink: 0;
}

.checkbox-icon.checked {
  background-color: var(--checked-color);
  border-color: var(--checked-color);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--input-background);
  padding: 0.5rem 1rem;
  border-radius: var(--border-radius);
  color: #9ca3af;
  min-width: 250px;
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-color-light);
  width: 100%;
  font-size: 1rem;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-end;
}

.icon-btn {
  background-color: var(--card-background-color);
  border: 1px solid var(--border-color);
  color: var(--text-color-secondary);
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: var(--border-radius);
  cursor: pointer;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: all 0.2s;
}
.icon-btn:hover {
  background-color: #f9fafb;
  border-color: #d1d5db;
}
.icon-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

.barcode-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
}

.barcode-card {
  background-color: var(--card-background-color);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
}

.barcode-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
  color: var(--text-color-secondary);
}

.barcode-card-header .timestamp {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
}

.delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-color-secondary);
  padding: 0.25rem;
  border-radius: 50%;
  transition: color 0.2s, background-color 0.2s;
}

.delete-btn:hover {
  color: var(--danger-color);
  background-color: #fee2e2;
}

.barcode-image {
  flex-grow: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-top: auto;
  min-height: 50px;
}

.barcode-image svg {
  max-width: 100%;
  height: auto;
}

.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--text-color-secondary);
  border: 2px dashed var(--border-color);
  border-radius: var(--border-radius);
}

.empty-state p {
  font-size: 1.125rem;
}

/* Print Preview Styles */
.print-preview-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.7);
  z-index: 1000;
  display: flex;
  justify-content: center;
  align-items: center;
}

.print-preview-container {
  background-color: var(--background-color);
  width: 95%;
  height: 95%;
  max-width: 1200px;
  border-radius: var(--border-radius);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.print-preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.5rem;
  background-color: var(--header-background-color);
  color: var(--text-color-light);
  flex-shrink: 0;
  gap: 1rem;
}

.print-preview-title-area {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  flex-shrink: 0;
}

.print-preview-title-area h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 0;
  white-space: nowrap;
}

.print-format-selector {
  display: flex;
  background-color: var(--input-background);
  border-radius: var(--border-radius);
  padding: 4px;
}

.format-select-btn {
  background: transparent;
  border: none;
  color: var(--text-color-light);
  padding: 0.5rem 1rem;
  cursor: pointer;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  white-space: nowrap;
  transition: all 0.2s;
}

.format-select-btn.active {
  background-color: var(--primary-color);
  color: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.format-select-btn:not(.active):hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.print-preview-header-info {
  color: var(--text-color-secondary);
  font-size: 0.875rem;
  text-align: center;
  flex-grow: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.print-preview-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.close-preview-btn {
  background: none;
  border: none;
  color: var(--text-color-light);
  cursor: pointer;
  padding: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.close-preview-btn:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.print-preview-content {
  flex-grow: 1;
  overflow: auto;
  padding: 2rem;
  background-color: var(--text-color-secondary);
}

.a4-page-preview {
    background-color: white;
    width: 100%;
    max-width: 21cm;
    height: auto;
    aspect-ratio: 210 / 297;
    margin: 2rem auto;
    box-shadow: var(--shadow);
}

.print-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(9, 1fr);
  row-gap: 0;
  column-gap: 0;
  padding: 0.25cm;
  height: 100%;
  box-sizing: border-box;
  position: relative;
  left: -3mm;
}

.print-grid-item {
  padding: 0.25cm;
  display: flex;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow: hidden;
}

.print-grid-item svg {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

/* On-screen Label Preview Styles */
.label-preview-scroll-container {
    display: flex;
    justify-content: center;
}
.label-preview-scroll-container > div {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 2rem;
}


.label-print-page {
    background-color: white;
    width: 200px;
    height: 300px;
    box-shadow: var(--shadow);
    padding: 10px; /* Represents 0.5cm */
    box-sizing: border-box;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
    flex-shrink: 0;
}

.label-print-content {
    width: 280px; /* Represents 14cm */
    height: 180px; /* Represents 9cm */
    transform: rotate(90deg);
    transform-origin: center;
    display: flex;
    justify-content: center;
    align-items: center;
}


@media (max-width: 900px) {
    .controls-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    .selection-info {
        grid-row: 2;
    }
    .search-bar {
        grid-row: 1;
        max-width: none;
    }
    .action-buttons {
        grid-row: 3;
        justify-content: flex-start;
    }
    .print-preview-header {
      flex-wrap: wrap;
    }
    .print-preview-header-info {
      order: 3;
      width: 100%;
      flex-basis: 100%;
    }
}


@media (max-width: 768px) {
  main {
    padding: 1rem;
  }
  
  .main-header h1 {
    font-size: 1.875rem;
  }

  .form-container {
    flex-direction: column;
    align-items: stretch;
  }
}