* {
  box-sizing: border-box
}

html {
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, 'Helvetica Neue', sans-serif;
  margin: 0;
  color: #f5f5f5;
  background: #000;
  overflow-x: hidden;
  max-width: 100vw;
}

header {
  padding: 24px 16px;
  background: #050505;
  border-bottom: 1px solid #222
}

h1 {
  margin: 0 0 8px 0;
  font-size: 20px
}

h2 {
  margin: 0 0 12px 0;
  font-size: 16px
}

main {
  max-width: 900px;
  margin: 24px auto;
  padding: 0 16px;
  display: grid;
  gap: 16px;
  overflow-x: hidden;
}

.card {
  background: #111;
  border: 1px solid #222;
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04)
}

.file-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600
}

.status {
  margin: 8px 0 4px 0;
  color: #aaa;
  font-size: 14px
}

.mini {
  font-size: 12px;
  color: #999;
  margin-top: 6px;
  white-space: pre-wrap
}

.row {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 16px
}

.block {
  border: 1px dashed #333;
  border-radius: 10px;
  padding: 12px;
  background: #181818
}

button {
  background: #111;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 10px 14px;
  font-weight: 600;
  cursor: pointer
}

button:disabled {
  opacity: .5;
  cursor: not-allowed
}

button.ghost {
  background: transparent;
  color: #f5f5f5;
  border: 1px solid #555
}

button.primary {
  background: #E87722;
  /* Agrovia Orange */
  color: #fff;
  border: none;
}

button.primary:hover {
  background: #d66b1c;
}

textarea {
  width: 100%;
  min-height: 140px;
  border: 1px solid #ddd;
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace
}

/* File Input Styling */
input[type="file"] {
  font-family: inherit;
  font-size: 13px;
  color: #aaa;
}

input[type="file"]::file-selector-button {
  background: #E87722;
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  margin-right: 12px;
  transition: background 0.2s;
}

input[type="file"]::file-selector-button:hover {
  background: #d66b1c;
}

footer {
  padding: 16px;
  color: #777;
  text-align: center
}

header.hero {
  padding: 32px 16px 16px 16px;
  background: #000;
  border-bottom: 1px solid #222
}

.hero-inner {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
  justify-content: flex-start
}

.hero-inner img.logo {
  width: 140px;
  height: auto;
  flex-shrink: 0;
  filter: drop-shadow(0 0 10px rgba(255, 255, 255, 0.2))
}

.hero-text h1 {
  font-size: 22px;
  margin: 0 0 6px 0;
  color: #f5f5f5
}

.hero-text p {
  margin: 0;
  color: #c0c0c0;
  font-size: 13px
}

.editor-link {
  color: #E87722;
  text-decoration: none;
  font-weight: 600;
  padding: 10px 18px;
  border: 2px solid #E87722;
  border-radius: 10px;
  transition: all 0.2s ease;
  margin-left: auto;
  white-space: nowrap;
}

.editor-link:hover {
  background: #E87722;
  color: #fff;
}

main {
  max-width: 1100px;
  margin: 24px auto 32px auto;
  padding: 0 16px;
  display: grid;
  gap: 16px
}

/* Datasheet Preview Styles */
#datasheetContainer {
  background: white;
  color: #000;
  width: 210mm;
  min-height: 297mm;
  padding: 10mm 15mm;
  margin: 20px auto;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  display: none;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
  position: relative;
}

#datasheetContainer.visible {
  display: block;
}

/* Two-column grid layout */
.ds-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  min-height: calc(297mm - 60mm);
  /* Leave room for footer */
}

/* Left Column */
.left-col {
  display: flex;
  flex-direction: column;
}

.left-col .logo-area {
  margin-bottom: 10px;
}

.left-col .logo-area img {
  max-width: 60px;
  max-height: 60px;
  object-fit: contain;
}

/* Product Info Table */
.ds-info-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 20px;
  font-size: 11px;
}

.ds-info-table th {
  background: #fff;
  color: #000;
  padding: 4px 8px;
  text-align: left;
  font-weight: bold;
  border: 1px solid #000;
}

.ds-info-table td {
  border: 1px solid #000;
  padding: 4px 8px;
  font-size: 11px;
}

.ds-info-table tr td:first-child {
  width: 40%;
}

.ds-info-table tr td:last-child {
  text-align: right;
}

/* Chart */
.ds-chart-wrapper {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 15px;
}

.ds-chart-img {
  width: 100%;
  max-width: 200px;
  height: auto;
}

/* Parameters table */
.ds-nutri-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.ds-nutri-table td {
  padding: 4px 0;
  border-bottom: 1px solid #ccc;
}

.ds-nutri-table tr:last-child td {
  border-bottom: none;
}

/* Salmonella note */
.salmonella-note {
  margin-top: 15px;
  font-size: 11px;
}

/* Right Column */
.right-col {
  display: flex;
  flex-direction: column;
}

/* Animal image */
.animal-img-container {
  text-align: right;
  margin-bottom: 10px;
}

.animal-img {
  width: 100%;
  height: auto;
  object-fit: contain;
}

/* Title in right column */
.ds-title {
  font-size: 18px;
  font-weight: bold;
  margin: 0 0 20px 0;
  color: #000;
}

/* Section styling */
.ds-section {
  margin-bottom: 12px;
}

.ds-section h3 {
  background: #000;
  color: #fff;
  padding: 3px 6px;
  margin: 0 0 6px 0;
  font-size: 11px;
  font-weight: bold;
}

.ds-section p {
  font-size: 11px;
  line-height: 1.4;
  margin: 0;
  padding: 4px;
  border: 1px solid #000;
  min-height: 30px;
}

/* Footer */
.ds-footer {
  position: absolute;
  bottom: 8mm;
  left: 15mm;
  right: 15mm;
  text-align: center;
  font-size: 9px;
  color: #333;
  border-top: 1px solid #999;
  padding-top: 6px;
  white-space: nowrap;
}

/* ========== Row Selector Panel ========== */
.row-selector {
  margin-bottom: 20px;
}

.row-selector.hidden {
  display: none;
}

.row-selector-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.row-selector-header h2 {
  margin: 0;
  font-size: 18px;
}

.selector-actions {
  display: flex;
  gap: 8px;
}

.thumbnail-strip {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
  padding: 12px 4px;
  margin-bottom: 16px;
  max-width: 100%;
}

.thumbnail-card {
  background: #1a1a1a;
  border: 2px solid #333;
  border-radius: 10px;
  padding: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
}

.thumbnail-card:hover {
  border-color: #555;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.thumbnail-card.active {
  border-color: #E87722;
  box-shadow: 0 0 0 3px rgba(232, 119, 34, 0.3);
}

.thumbnail-card .card-checkbox {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 20px;
  height: 20px;
  accent-color: #E87722;
  cursor: pointer;
}

.thumbnail-card .card-index {
  font-size: 11px;
  color: #666;
  margin-bottom: 6px;
}

.thumbnail-card .card-code {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumbnail-card .card-material {
  font-size: 11px;
  color: #999;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thumbnail-card.checked {
  background: #1a2a3a;
}

.generation-buttons {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.generation-buttons button {
  flex: 1;
  min-width: 200px;
  padding: 12px 20px;
  font-size: 14px;
}

button.secondary {
  background: #333;
  color: #fff;
  border: 1px solid #555;
}

button.secondary:hover {
  background: #444;
}

/* ========== Row Edit Panel ========== */
.row-edit-panel {
  margin-bottom: 20px;
}

.row-edit-panel.hidden {
  display: none;
}

.edit-panel-header h2 {
  margin: 0 0 16px 0;
  font-size: 16px;
}

.edit-panel-header h2 span {
  color: #E87722;
}

.edit-row {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
}

.edit-field {
  display: flex;
  align-items: center;
  gap: 12px;
}

.edit-field label {
  font-weight: 600;
  color: #ccc;
}

.edit-field select {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid #444;
  background: #222;
  color: #fff;
  font-size: 14px;
  min-width: 200px;
  cursor: pointer;
}

.edit-field select:focus {
  outline: none;
  border-color: #E87722;
}

.edit-preview {
  display: flex;
  align-items: center;
  padding: 8px;
  background: #1a1a1a;
  border-radius: 8px;
  min-width: 80px;
  min-height: 60px;
  justify-content: center;
}

.edit-preview img {
  max-height: 50px;
  max-width: 70px;
  object-fit: contain;
}

/* ========== OCR Import Section ========== */
.ocr-section h2 {
  margin-bottom: 8px;
}

.ocr-row {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 24px;
  margin-top: 16px;
}

.ocr-upload-area {
  padding: 16px;
  background: #1a1a1a;
  border-radius: 10px;
  border: 1px dashed #444;
}

.ocr-progress {
  margin-top: 12px;
}

.ocr-progress.hidden {
  display: none;
}

.progress-bar {
  height: 8px;
  background: #333;
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 6px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #E87722, #F5A623);
  width: 0%;
  transition: width 0.3s ease;
}

.ocr-fields h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #ccc;
}

.field-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  align-items: center;
}

.field-grid label {
  font-size: 12px;
  color: #999;
}

.field-grid input {
  padding: 8px 10px;
  border: 1px solid #444;
  border-radius: 6px;
  background: #222;
  color: #fff;
  font-size: 13px;
}

.field-grid input:focus {
  outline: none;
  border-color: #E87722;
}

.ocr-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
  flex-wrap: wrap;
}

.ocr-actions button {
  flex: 1;
  min-width: 120px;
}

.ocr-extracted-rows {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid #333;
}

.ocr-extracted-rows.hidden {
  display: none;
}

.ocr-extracted-rows h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
}

.ocr-extracted-rows table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.ocr-extracted-rows th,
.ocr-extracted-rows td {
  padding: 8px;
  text-align: left;
  border-bottom: 1px solid #333;
}

.ocr-extracted-rows th {
  color: #999;
  font-weight: 600;
}

.ocr-extracted-rows button.remove-row {
  padding: 4px 8px;
  font-size: 11px;
  background: #c0392b;
}

/* OCR Debug Raw Text */
.ocr-debug {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed #333;
}

.ocr-raw-text {
  margin-top: 10px;
}

.ocr-raw-text.hidden {
  display: none;
}

.ocr-raw-text textarea {
  width: 100%;
  height: 150px;
  background: #0a0a0a;
  color: #0f0;
  font-family: monospace;
  font-size: 11px;
  padding: 10px;
  border: 1px solid #333;
  border-radius: 6px;
  resize: vertical;
}

/* ========== Technical Page Toggle ========== */
.tech-page-toggle {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px dashed #444;
}

.tech-page-toggle label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: #ccc;
}

.tech-page-toggle input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: #E87722;
  cursor: pointer;
}

/* ========== Technical Page 2 Styles ========== */
#technicalPageContainer {
  position: relative;
  background: white;
  color: #000;
  width: 210mm;
  min-height: 297mm;
  padding: 15mm;
  padding-bottom: 25mm;
  /* Extra space for footer */
  margin: 20px auto;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 12px;
}

#technicalPageContainer.hidden {
  display: none;
}

.tech-page {
  min-height: calc(297mm - 30mm);
  display: flex;
  flex-direction: column;
}

/* Header */
.tech-header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding-bottom: 15px;
  border-bottom: 2px solid #000;
  margin-bottom: 20px;
}

.tech-logo {
  width: 60px;
  height: 60px;
  object-fit: contain;
}

.tech-header-text h1 {
  margin: 0;
  font-size: 18px;
  color: #000;
}

.tech-header-text p {
  margin: 4px 0 0 0;
  font-size: 14px;
  color: #333;
  font-weight: 600;
}

/* Grid Layout */
.tech-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  flex: 1;
}

.tech-section {
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 6px;
  overflow: hidden;
}

.tech-section-wide {
  grid-column: 1 / -1;
}

.tech-section h3 {
  background: #000;
  color: #fff;
  margin: 0;
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 600;
}

.tech-table {
  width: 100%;
  border-collapse: collapse;
}

.tech-table td {
  padding: 8px 12px;
  border-bottom: 1px solid #eee;
  font-size: 11px;
}

.tech-table tr:last-child td {
  border-bottom: none;
}

.tech-table td:first-child {
  color: #555;
  width: 60%;
}

.tech-table td:last-child {
  font-weight: 600;
  text-align: right;
  color: #000;
}

/* Footer - positioned as footnote at bottom of page */
.tech-footer {
  position: absolute;
  bottom: 8mm;
  left: 15mm;
  right: 15mm;
  text-align: center;
  font-size: 9px;
  color: #666;
  border-top: 1px solid #ccc;
  padding-top: 8px;
}

/* ========== Print Styles ========== */
@media print {
  body {
    background: white;
  }

  header,
  .hero,
  .card,
  .row-selector,
  .row-edit-panel,
  footer,
  #hiddenChart {
    display: none !important;
  }

  main {
    margin: 0;
    padding: 0;
    max-width: none;
  }

  #datasheetContainer {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    min-height: auto;
  }

  /* Page 2 print styles */
  #technicalPageContainer {
    display: block !important;
    width: 100%;
    margin: 0;
    padding: 0;
    box-shadow: none;
    min-height: auto;
    page-break-before: always;
  }

  #technicalPageContainer.hidden {
    display: none !important;
  }

  .tech-page {
    min-height: auto;
  }

  .tech-section {
    break-inside: avoid;
  }

  @page {
    size: A4;
    margin: 1.5cm;
  }
}

/* ========== Technical Data Input Section ========== */
.tech-data-section {
  margin-top: 16px;
  border: 1px solid #333;
  border-radius: 8px;
  background: #1a1a1a;
}

.tech-data-section summary {
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  color: #ccc;
  user-select: none;
}

.tech-data-section summary:hover {
  background: #222;
  border-radius: 8px;
}

.tech-data-section[open] summary {
  border-bottom: 1px solid #333;
  border-radius: 8px 8px 0 0;
}

.tech-data-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px;
}

.tech-fieldset {
  border: 1px solid #444;
  border-radius: 6px;
  padding: 12px;
  background: #222;
}

.tech-fieldset legend {
  color: #aaa;
  font-size: 12px;
  font-weight: 600;
  padding: 0 8px;
}

.tech-fieldset label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: #999;
  gap: 8px;
}

.tech-fieldset label:last-child {
  margin-bottom: 0;
}

.tech-fieldset input {
  flex: 1;
  max-width: 140px;
  padding: 6px 8px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1a1a1a;
  color: #fff;
  font-size: 12px;
}

.tech-fieldset input:focus {
  outline: none;
  border-color: #E87722;
}

.tech-fieldset-wide {
  grid-column: 1 / -1;
}

.tech-fieldset-wide label {
  display: inline-flex;
  width: calc(50% - 8px);
}

.tech-fieldset textarea {
  width: 100%;
  padding: 8px;
  border: 1px solid #444;
  border-radius: 4px;
  background: #1a1a1a;
  color: #fff;
  font-size: 12px;
  resize: vertical;
  font-family: inherit;
}

.tech-fieldset textarea:focus {
  outline: none;
  border-color: #E87722;
}

/* Tech Notes section on Page 2 */
.tech-notes {
  padding: 12px;
  font-size: 11px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  background: #fafafa;
  border: 1px solid #ddd;
  border-radius: 4px;
  min-height: 40px;
}

/* ========== Simple Page 2 Table Design ========== */
.tech-page-simple {
  padding: 20px;
  font-family: Arial, Helvetica, sans-serif;
}

.tech-simple-header {
  border-bottom: 2px solid #000;
  padding-bottom: 15px;
  margin-bottom: 20px;
}

.tech-simple-header h1 {
  margin: 0;
  font-size: 16px;
  color: #000;
}

.tech-simple-header p {
  margin: 5px 0 0 0;
  font-size: 12px;
  color: #666;
}

.tech-simple-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
}

.tech-simple-table thead {
  background: #000;
  color: #fff;
}

.tech-simple-table th {
  padding: 8px 12px;
  text-align: left;
  font-weight: 600;
}

.tech-simple-table th:nth-child(1) {
  width: 45%;
}

.tech-simple-table th:nth-child(2) {
  width: 30%;
}

.tech-simple-table th:nth-child(3) {
  width: 25%;
}

.tech-simple-table td {
  padding: 6px 12px;
  border-bottom: 1px solid #ddd;
  vertical-align: top;
}

.tech-simple-table tr:nth-child(even) {
  background: #f9f9f9;
}

.tech-simple-table tr:hover {
  background: #f0f0f0;
}

/* Print-specific styles for Page 2 table headers */
@media print {
  .tech-simple-table thead {
    background: #000 !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .tech-simple-table th {
    background: #000 !important;
    color: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .tech-simple-table tr:nth-child(even) {
    background: #f5f5f5 !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .tech-page-simple {
    page-break-before: always;
  }
}

/* ========== Two-Column Technical Page Layout ========== */
.tech-two-column-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 15px;
}

.tech-column {
  display: flex;
  flex-direction: column;
}

.tech-column-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
}

.tech-column-table thead {
  background: #000;
  color: #fff;
}

.tech-column-table th {
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 9px;
}

.tech-column-table th:first-child,
.tech-column-table td:first-child {
  width: 50%;
}

.tech-column-table th:last-child,
.tech-column-table td:last-child {
  width: 50%;
}

.tech-column-table td {
  padding: 4px 8px;
  border-bottom: 1px solid #ddd;
  vertical-align: top;
  font-size: 9px;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.tech-column-table tr:nth-child(even) {
  background: #f9f9f9;
}

.tech-column-table td:first-child {
  color: #333;
  font-weight: 500;
  width: 50%;
}

.tech-column-table td:last-child {
  text-align: right;
  color: #000;
}

/* Print styles for 2-column tech layout */
@media print {
  .tech-two-column-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
  }

  .tech-column-table thead {
    background: #000 !important;
    /* Agrovia Orange */
    color: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  .tech-column-table th {
    background: #000 !important;
    /* Agrovia Orange */
    color: #fff !important;
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

/* ========== Paste Data Section ========== */
.paste-data-section h2 {
  margin-bottom: 8px;
}

.paste-data-container {
  margin-top: 12px;
}

.paste-data-container textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid #444;
  border-radius: 8px;
  background: #1a1a1a;
  color: #fff;
  font-family: monospace;
  font-size: 12px;
  resize: vertical;
  min-height: 150px;
}

.paste-data-container textarea:focus {
  outline: none;
  border-color: #E87722;
}

.paste-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.paste-preview {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #333;
}

.paste-preview h3 {
  margin: 0 0 12px 0;
  font-size: 14px;
  color: #ccc;
}

.paste-preview table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.paste-preview th {
  background: #333;
  color: #fff;
  padding: 8px;
  text-align: left;
}

.paste-preview td {
  padding: 6px 8px;
  border-bottom: 1px solid #333;
  color: #ddd;
}

.paste-preview tr:nth-child(even) {
  background: #1a1a1a;
}