:root {
  color-scheme: light;
  --bg: #f3f5f8;
  --panel: #ffffff;
  --panel-border: #d8deea;
  --text: #162033;
  --muted: #5f6b80;
  --primary: #0057b8;
  --primary-hover: #004391;
  --danger: #b42318;
  --shadow: 0 12px 30px rgba(18, 38, 63, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button, input, textarea, select { font: inherit; }

.app-shell {
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #0d1b2a;
  color: #fff;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand h1, .panel h2, .panel h3, .panel h4, .topbar h2 { margin: 0; }

.brand p, .topbar p, .preview-header span {
  margin: 4px 0 0;
  color: var(--muted);
}

.sidebar .brand p { color: rgba(255,255,255,.72); }

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.sidebar .panel {
  background: rgba(255,255,255,.06);
  border-color: rgba(255,255,255,.12);
  box-shadow: none;
  padding: 14px;
}

.panel-header, .topbar, .preview-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.catalog-actions {
  margin-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.search-field {
  margin-top: 12px;
  color: rgba(255,255,255,.85);
}

.search-field span { font-size: 12px; }

.sidebar-search input {
  margin-top: 6px;
  background: rgba(255,255,255,.95);
}

.catalog-tree,
.template-list {
  margin-top: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow: auto;
}

.catalog-family {
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 12px;
  padding: 8px;
  background: rgba(255,255,255,.04);
}

.catalog-family.is-active {
  border-color: #8dc1ff;
  background: rgba(141,193,255,.08);
}

.catalog-family-header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}

.catalog-family-title {
  font-size: 13px;
  font-weight: 700;
  color: #fff;
}

.catalog-family-count {
  font-size: 11px;
  color: rgba(255,255,255,.7);
}

.catalog-model-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.list-item {
  width: 100%;
  text-align: left;
  background: rgba(255,255,255,.1);
  color: #fff;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 10px 12px;
  cursor: pointer;
}

.list-item.active {
  border-color: #8dc1ff;
  background: rgba(141,193,255,.18);
}

.list-item .folder-meta {
  display: block;
  margin-top: 4px;
  color: rgba(255,255,255,.88);
  font-size: 12px;
}

.list-item small {
  display: block;
  margin-top: 4px;
  color: rgba(255,255,255,.72);
}

.main-content { padding: 24px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; }

.workspace {
  margin-top: 20px;
  display: grid;
  grid-template-columns: minmax(440px, 650px) 1fr;
  gap: 20px;
}

.editor, .preview-area { padding: 20px; }

.size-info {
  margin-top: 14px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.size-chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: #0b3d91;
  font-size: 12px;
}

.size-chip.muted {
  background: #f3f4f6;
  color: #5b6577;
}

.toggle-panel {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid #dfe6f0;
  border-radius: 12px;
  background: #f8fbff;
}

.toggle-grid {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  min-height: 42px;
}

.toggle-item {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid #d8deea;
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
}

.toggle-item span {
  color: var(--text);
  font-size: 13px;
  line-height: 1.2;
}

.toggle-item input[type="checkbox"] {
  width: 16px;
  min-width: 16px;
  height: 16px;
  margin: 0;
  padding: 0;
  border: 1px solid #9aa9bf;
  border-radius: 4px;
  background: #fff;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-grid {
  margin-top: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--muted);
  font-size: 14px;
}

input:not([type="checkbox"]), textarea, select {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #c8d1df;
  background: #fff;
  color: var(--text);
}

textarea { resize: vertical; min-height: 100px; }
.full-width { margin-top: 14px; }

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

.print-panel {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #e1e8f1;
}

.print-queue-actions {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.print-queue-summary {
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.print-queue-list {
  margin-top: 10px;
  display: grid;
  gap: 10px;
}

.print-queue-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 110px 90px auto;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #d8deea;
  border-radius: 12px;
  background: #f9fbfe;
}

.print-queue-meta {
  min-width: 0;
}

.print-queue-title {
  font-size: 14px;
  color: var(--text);
}

.print-queue-subtitle {
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.print-queue-type {
  display: inline-flex;
  justify-content: center;
  padding: 7px 10px;
  border-radius: 999px;
  background: #eef4ff;
  color: #0b3d91;
  font-size: 12px;
}

.print-queue-qty {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.print-queue-qty span {
  font-size: 11px;
  color: var(--muted);
}

.print-queue-qty input {
  padding: 8px 10px;
}

button, .file-input {
  border: 0;
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}

.primary { background: var(--primary); color: #fff; }
.primary:hover { background: var(--primary-hover); }
.secondary { background: #e7edf7; color: var(--text); }
.danger { background: #fee4e2; color: var(--danger); }

.file-input {
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
}

.file-input input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.preview-stack {
  margin-top: 16px;
  display: grid;
  gap: 18px;
}

#printSheets {
  display: none;
}

.preview-variant { display: grid; gap: 8px; }
.variant-title { font-size: 13px; color: var(--muted); }

.label-preview-wrapper {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 20px;
  overflow: auto;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px) 0 0 / 20px 20px,
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px) 0 0 / 20px 20px,
    #f8fafc;
  border-radius: 16px;
}

.label-card {
  background: #fff;
  color: #111;
  border: 1px solid #111;
  width: 150mm;
  min-width: 150mm;
  height: 70mm;
  min-height: 70mm;
  padding: 4.8mm 5.2mm 4.3mm;
  flex: 0 0 auto;
}

.shape-square { aspect-ratio: 1 / 1; }
.shape-rect { aspect-ratio: auto; }

.label-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 38.5mm;
  gap: 5.4mm;
  height: 100%;
}

.label-left, .label-right {
  display: grid;
  align-content: start;
}

.label-left {
  grid-template-rows: auto auto auto auto 1fr;
}

.label-right {
  grid-template-rows: auto 1fr auto auto;
  justify-items: end;
}

.brand-logo {
  display: block;
  width: 50.5mm;
  margin-bottom: 2.6mm;
}

.brand-logo-img {
  display: block;
  width: 100%;
  height: auto;
}

.label-top {
  display: grid;
  gap: 1.1mm;
}

.family {
  font-size: 18.2pt;
  font-weight: 400;
  line-height: 1.02;
  letter-spacing: -0.03em;
}

.spec-line {
  font-size: 10.8pt;
  line-height: 1.08;
  min-height: 12pt;
}

.meta-line {
  margin-top: 1.8mm;
  font-size: 9.9pt;
  line-height: 1.08;
  min-height: 10pt;
}

.badge-pills {
  margin-top: 8mm;
  display: flex;
  flex-wrap: wrap;
  gap: 2.8mm;
  min-height: 0;
  align-self: start;
}

.badge-pill {
  min-width: 18.2mm;
  padding: 1.45mm 2.4mm;
  border: 0.22mm solid #d2d8df;
  border-radius: 1.15mm;
  background: #fff;
  text-align: center;
  font-size: 7.7pt;
  line-height: 1.05;
}

.company-block {
  margin-top: 3.8mm;
  align-self: end;
  white-space: pre-line;
  font-size: 6.75pt;
  line-height: 1.18;
}

.qr-box {
  width: 35.8mm;
  height: 35.8mm;
}

.qr-code {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.qr-code svg {
  width: 100%;
  height: 100%;
  display: block;
}

.compliance-box {
  align-self: end;
  width: 100%;
  margin-top: 2.2mm;
  border: 0.22mm solid #c4c4c4;
  border-radius: 2.1mm;
  padding: 1.5mm 1.8mm;
}

.png-icons {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.8mm;
}

.icon-png {
  display: block;
  width: auto;
  height: auto;
}

.icon-ce-png { width: 11.2mm; }
.icon-bin-png { width: 6.5mm; }
.icon-rohs-png { width: 7.8mm; }

.production-line {
  align-self: end;
  margin-top: 2.4mm;
  font-size: 6.6pt;
  line-height: 1.12;
  text-align: right;
  margin-bottom: 0.1mm;
}

.inner-wrapper { justify-content: flex-start; }

.inner-label-card {
  width: 470px;
  min-width: 470px;
  min-height: 166px;
  border: 1px solid #111;
  background: #fff;
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 12px;
  align-items: start;
}

.inner-qr-box {
  width: 156px;
  height: 156px;
  border: 1px solid #111;
  padding: 6px;
  background: #fff;
}

.inner-content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  align-self: stretch;
}

.inner-brand-logo {
  width: 108px;
  margin: 0 0 8px auto;
}

.inner-family {
  font-size: 19px;
  line-height: 1.05;
}

.inner-spec-line {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.15;
}

.inner-meta-line {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.15;
}

.inner-bottom {
  margin-top: 8px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.inner-badge-pills {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.inner-badge-pills .badge-pill,
.small-badge {
  min-width: 48px;
  padding: 3px 7px;
  font-size: 10px;
}

.inner-icon-ce { width: 26px; }
.inner-icon-bin { width: 16px; }
.inner-icon-rohs { width: 18px; }

.inner-production-line {
  margin-top: auto;
  font-size: 10px;
  line-height: 1.1;
}

.print-sheet {
  break-after: page;
  page-break-after: always;
}

.print-sheet:last-child {
  break-after: auto;
  page-break-after: auto;
}

.print-sheet--outer {
  display: grid;
  grid-template-columns: repeat(2, 142.5mm);
  grid-auto-rows: 66.5mm;
  gap: 0;
  justify-content: center;
  align-content: start;
}

.print-sheet--inner {
  display: grid;
  grid-template-columns: repeat(2, 105mm);
  grid-auto-rows: 55mm;
  width: 210mm;
  height: 297mm;
  margin: 0 auto;
  gap: 0;
  justify-content: center;
  align-content: center;
}

.print-slot {
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
  overflow: visible;
}

.print-slot--outer {
  width: 142.5mm;
  height: 66.5mm;
}

.print-slot--inner {
  width: 105mm;
  height: 55mm;
  align-items: center;
  justify-content: center;
}

.print-slot--outer .label-card {
  margin: 0;
  transform: scale(0.95);
  transform-origin: top left;
}

.print-slot--inner .inner-label-card {
  width: 95mm;
  min-width: 95mm;
  min-height: 45mm;
  height: 45mm;
  padding: 2.6mm 3mm;
  grid-template-columns: 31mm 1fr;
  gap: 2.6mm;
  align-items: stretch;
  transform: none;
  border: 0;
  margin: 0;
}

.print-slot--inner .inner-qr-box {
  width: 31mm;
  height: 31mm;
  padding: 0;
  border: 0;
}

.print-slot--inner .inner-content {
  min-width: 0;
}

.print-slot--inner .inner-brand-logo {
  width: 22mm;
  margin: 0 0 1.4mm auto;
}

.print-slot--inner .inner-family {
  font-size: 5.3mm;
  line-height: 1.02;
}

.print-slot--inner .inner-spec-line,
.print-slot--inner .inner-meta-line {
  margin-top: 0.8mm;
  font-size: 2.2mm;
  line-height: 1.14;
}

.print-slot--inner .inner-bottom {
  margin-top: 1.4mm;
  gap: 1.3mm;
  align-items: center;
}

.print-slot--inner .inner-badge-pills {
  gap: 1.2mm;
}

.print-slot--inner .inner-badge-pills .badge-pill,
.print-slot--inner .small-badge {
  min-width: 9.6mm;
  padding: 0.65mm 1.4mm;
  font-size: 1.8mm;
  border-radius: 0.9mm;
}

.print-slot--inner .inner-icon-ce { width: 6.8mm; }
.print-slot--inner .inner-icon-bin { width: 3.7mm; }
.print-slot--inner .inner-icon-rohs { width: 4.2mm; }

.print-slot--inner .inner-production-line {
  margin-top: auto;
  font-size: 1.75mm;
  line-height: 1.08;
}

.is-hidden { display: none !important; }

@media (max-width: 1100px) {
  .app-shell { grid-template-columns: 1fr; }
  .workspace { grid-template-columns: 1fr; }
  .toggle-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .print-queue-item { grid-template-columns: 1fr; }
}

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

  body.print-mode .app-shell {
    display: none !important;
  }

  body.print-mode #printSheets {
    display: block;
  }

  #printSheets {
    display: none;
  }

  .print-sheet {
    padding: 0;
    margin: 0;
    background: #fff;
    box-shadow: none;
  }

  .print-slot--outer .label-card,
  .print-slot--inner .inner-label-card {
    box-shadow: none;
  }
}
