:root {
  color-scheme: dark;
  --bg: #0f1115;
  --card: #161b24;
  --ink: #e7ebf2;
  --muted: #a1aab8;
  --accent: #4f8cff;
  --accent-dark: #2f5fba;
  --border: rgba(231, 235, 242, 0.14);
  --shadow: none;
  --radius: 18px;
  --sheet-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Space Grotesk", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

h1,
h2 {
  margin: 0;
  font-family: "Source Serif 4", serif;
  letter-spacing: -0.02em;
}

p {
  margin: 0;
}

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 32px;
  padding: 40px clamp(24px, 4vw, 60px) 24px;
}

.eyebrow {
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.2em;
  color: var(--muted);
  margin-bottom: 12px;
}

.subtitle {
  font-size: 1.1rem;
  color: var(--muted);
  max-width: 480px;
}

.app {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 28px;
  padding: 0 clamp(24px, 4vw, 60px) 60px;
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.panel {
  background: var(--card);
  border-radius: 12px;
  padding: 20px;
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 1.25rem;
  margin-bottom: 16px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.pill {
  background: rgba(79, 140, 255, 0.16);
  color: var(--accent);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.button {
  border: 1px solid var(--border);
  background: #1b2330;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s ease, border-color 0.2s ease;
  color: var(--ink);
}

.button.primary {
  background: var(--accent);
  border-color: var(--accent-dark);
  color: #081528;
}

.button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.button:not(:disabled):hover {
  background: #222b3a;
  border-color: rgba(231, 235, 242, 0.3);
}

.drop-zone {
  border: 2px dashed rgba(231, 235, 242, 0.2);
  border-radius: 12px;
  padding: 18px;
  text-align: center;
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.drop-zone.dragover {
  border-color: var(--accent-dark);
  background: rgba(79, 140, 255, 0.12);
  color: var(--ink);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field select,
.field input[type="text"],
.field input[type="number"] {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
  background: #141a24;
  color: var(--ink);
}

.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 10px;
}

.layout-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.layout-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
  color: inherit;
}

.layout-card.active {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.12);
}

.layout-icon {
  display: grid;
  gap: 3px;
  padding: 6px;
  border-radius: 6px;
  border: 1px solid rgba(231, 235, 242, 0.2);
  background: rgba(0, 0, 0, 0.2);
}

.layout-icon span {
  width: 6px;
  height: 6px;
  border-radius: 2px;
  background: rgba(231, 235, 242, 0.5);
}

.layout-3x10 {
  grid-template-columns: repeat(3, 6px);
}

.layout-5x5 {
  grid-template-columns: repeat(5, 6px);
}

.layout-2x5 {
  grid-template-columns: repeat(2, 6px);
}

.layout-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.85rem;
  color: var(--muted);
}

.layout-info strong {
  color: var(--ink);
  font-size: 0.95rem;
}

.padding-control,
.rotation-control {
  display: flex;
  align-items: center;
  gap: 8px;
}

.padding-control input {
  width: 72px;
  text-align: center;
}

.stepper {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #1b2330;
  color: var(--ink);
  font-weight: 600;
  cursor: pointer;
}

.unit {
  font-size: 0.85rem;
  color: var(--muted);
}

.rotation-value {
  font-weight: 600;
  color: var(--muted);
}

.items-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 360px;
  overflow: auto;
}

.item-card {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
}

.item-thumb {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: contain;
  background: #0c0f14;
  border: 1px solid rgba(231, 235, 242, 0.12);
}

.item-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.item-row select,
.item-row input {
  flex: 1 1 120px;
}

.item-remove {
  border: none;
  background: none;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  padding: 0;
}

.preview {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.preview-header {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.preview-meta {
  color: var(--muted);
  font-size: 0.9rem;
}

.preview-area {
  display: grid;
  gap: 24px;
  padding-bottom: 24px;
  overflow-x: auto;
}

.preview-area.template-on .label-cell {
  border: 1px solid rgba(31, 29, 26, 0.55);
}

.preview-area.template-on .cell-index {
  opacity: 0.85;
}

.preview-empty {
  background: rgba(255, 255, 255, 0.04);
  border-radius: 20px;
  padding: 40px;
  border: 1px dashed rgba(231, 235, 242, 0.2);
  text-align: center;
  color: var(--muted);
}

.sheet {
  position: relative;
  width: 8.5in;
  height: 11in;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--sheet-shadow);
  overflow: hidden;
}

.sheet-title {
  position: absolute;
  font-family: "Source Serif 4", serif;
  font-size: 0.18in;
  letter-spacing: 0.01em;
  color: #1b1b1b;
}

.sheet-grid-outline {
  position: absolute;
  border: 2px solid rgba(31, 29, 26, 0.8);
  pointer-events: none;
}

.label-cell {
  position: absolute;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  overflow: hidden;
}

.label-cell img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  display: block;
}

.cell-index {
  position: absolute;
  top: 6px;
  right: 8px;
  font-size: 0.6rem;
  color: rgba(31, 29, 26, 0.8);
  opacity: 0;
}

.calibration-sheet .label-cell {
  background:
    linear-gradient(rgba(31, 29, 26, 0.08), rgba(31, 29, 26, 0.08)),
    linear-gradient(to right, transparent calc(50% - 0.5px), rgba(31, 29, 26, 0.22) calc(50% - 0.5px), rgba(31, 29, 26, 0.22) calc(50% + 0.5px), transparent calc(50% + 0.5px)),
    linear-gradient(to bottom, transparent calc(50% - 0.5px), rgba(31, 29, 26, 0.22) calc(50% - 0.5px), rgba(31, 29, 26, 0.22) calc(50% + 0.5px), transparent calc(50% + 0.5px));
}

.actions {
  display: flex;
  gap: 12px;
}

@media (max-width: 1100px) {
  .app {
    grid-template-columns: 1fr;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app {
    display: block;
    padding: 0;
  }

  .preview {
    gap: 0;
  }

  .app-header,
  .controls,
  .preview-header {
    display: none !important;
  }

  .preview-area {
    gap: 0;
    padding-bottom: 0;
  }

  .sheet {
    box-shadow: none;
    border-radius: 0;
  }

  .sheet:not(:last-child) {
    break-after: page;
  }

  .sheet-grid-outline {
    border-color: #000;
  }

  .preview-area.template-on .label-cell {
    border-color: #000;
  }

  .cell-index {
    color: #000;
  }
}

@page {
  size: letter;
  margin: 0;
}

.product-search {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
  font-family: inherit;
  background: #141a24;
  color: var(--ink);
  margin-bottom: 10px;
}

.product-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 320px;
  overflow-y: auto;
  margin-bottom: 12px;
}

.product-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  text-align: left;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  cursor: pointer;
}

.product-item:hover {
  background: rgba(255, 255, 255, 0.04);
}

.product-item.active {
  border-color: var(--accent);
  background: rgba(79, 140, 255, 0.1);
}

.product-sku {
  font-weight: 600;
  font-size: 0.9rem;
}

.product-title {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: var(--muted);
}

.product-badge {
  font-size: 0.7rem;
  color: var(--accent);
  align-self: center;
}

.preset-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
}

.preset-status {
  font-size: 0.85rem;
  color: var(--muted);
}
