:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #18212f;
  --muted: #657184;
  --line: #dce2ea;
  --brand: #166b57;
  --brand-dark: #0d4639;
  --accent: #b83b4b;
  --soft: #edf6f3;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
}

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

button {
  border: 0;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  cursor: pointer;
  padding: 10px 16px;
  min-height: 40px;
}

button:hover {
  background: var(--brand-dark);
}

.ghost {
  background: #eef2f5;
  color: var(--ink);
}

.ghost:hover {
  background: #e0e7ed;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 32px 18px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 2;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 20px;
}

h3 {
  font-size: 16px;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  margin-bottom: 5px;
}

.tabs {
  display: flex;
  gap: 8px;
  padding: 4px;
  background: #eef2f5;
  border-radius: 8px;
}

.tab {
  background: transparent;
  color: var(--muted);
  min-width: 76px;
}

.tab.active {
  background: #fff;
  color: var(--brand-dark);
  box-shadow: 0 1px 3px rgba(21, 34, 49, 0.12);
}

main {
  padding: 28px 32px 48px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.query-panel,
.form-panel,
.list-panel,
.label-toolbar,
.result {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.query-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  padding: 24px;
}

.searchbar {
  display: flex;
  gap: 10px;
  width: min(520px, 100%);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

.searchbar input {
  flex: 1;
}

.result {
  margin-top: 18px;
  padding: 24px;
}

.result.empty {
  color: var(--muted);
}

.trace-head {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 18px;
  margin-bottom: 18px;
}

.status {
  background: var(--soft);
  color: var(--brand-dark);
  border-radius: 999px;
  padding: 6px 10px;
  height: fit-content;
  font-weight: 700;
  white-space: nowrap;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  border: 1px solid var(--line);
}

.info-item {
  display: grid;
  grid-template-columns: 150px 1fr;
  min-height: 44px;
  border-bottom: 1px solid var(--line);
}

.info-item:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.info-item span {
  background: #f0f3f6;
  color: #3d4858;
  font-weight: 700;
  padding: 12px;
  border-right: 1px solid var(--line);
}

.info-item strong {
  padding: 12px;
  font-weight: 500;
  word-break: break-word;
}

.split {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
  gap: 18px;
}

.form-panel,
.list-panel {
  padding: 20px;
}

.form-head,
.label-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.form-head.compact {
  margin-bottom: 12px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label {
  color: #334052;
  display: grid;
  gap: 7px;
  font-size: 14px;
  font-weight: 700;
}

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

.primary {
  width: 100%;
  margin-top: 16px;
}

.product-list {
  display: grid;
  gap: 10px;
}

.import-panel {
  display: grid;
  gap: 10px;
  padding: 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.import-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.import-status {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.import-status strong {
  color: var(--brand-dark);
}

.product-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.product-row small {
  color: var(--muted);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.row-actions button {
  padding: 8px 10px;
  min-height: 34px;
}

.danger {
  background: #b42335;
}

.danger:hover {
  background: #8f1827;
}

.label-toolbar {
  padding: 20px;
}

.label-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

.label-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  text-align: center;
  padding: 14px;
}

.label-card .code-line {
  background: #223447;
  color: #fff;
  margin: -14px -14px 12px;
  padding: 11px;
  font-weight: 700;
}

.label-card img {
  width: 170px;
  height: 170px;
  image-rendering: pixelated;
}

.label-card h3 {
  margin: 8px 0 0;
  color: var(--accent);
  font-size: 20px;
}

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

@media (max-width: 820px) {
  .topbar,
  .query-panel,
  .trace-head {
    align-items: stretch;
    flex-direction: column;
  }

  main,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .tabs,
  .searchbar {
    width: 100%;
  }

  .tab {
    flex: 1;
  }

  .split,
  .grid,
  .info-grid {
    grid-template-columns: 1fr;
  }

  .info-item,
  .info-item:nth-last-child(-n + 2) {
    grid-template-columns: 118px 1fr;
    border-bottom: 1px solid var(--line);
  }
}

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

  .topbar,
  .label-toolbar {
    display: none;
  }

  main {
    padding: 0;
  }

  .view {
    display: none !important;
  }

  #labelsView {
    display: block !important;
  }

  .label-grid {
    grid-template-columns: repeat(3, 1fr);
    gap: 10mm;
  }

  .label-card {
    break-inside: avoid;
  }
}
