:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --panel: #ffffff;
  --text: #1d252c;
  --muted: #66717c;
  --line: #dce2e7;
  --primary: #176b58;
  --primary-strong: #0e5143;
  --danger: #b33939;
  --warning: #9c6b12;
  --shadow: 0 10px 30px rgba(18, 36, 47, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { max-width: 100%; overflow-x: hidden; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: rgba(255,255,255,.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  flex: 0 0 auto;
  font-weight: 800;
  color: var(--primary);
}

.nav {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  white-space: nowrap;
  scrollbar-width: none;
}

.nav a {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 14px;
}

.mobile-menu {
  display: none;
}

.userbar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.userbar a {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font-weight: 700;
}

.page {
  width: min(980px, 100%);
  margin: 0 auto;
  padding: 16px;
}

.site-footer {
  padding: 10px 16px 20px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.site-footer a {
  color: var(--muted);
}

.login-footer {
  margin-top: -18px;
}

.section {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.section + .section { margin-top: 16px; }
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1 {
  margin: 0 0 14px;
  font-size: 25px;
  line-height: 1.2;
}

h2 {
  margin: 24px 0 10px;
  font-size: 18px;
}

.muted, small { color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 22px; }

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

.mobile-dashboard {
  display: none;
}

.stats div, .detail-grid div {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.stats span, .detail-grid strong {
  display: block;
  font-size: 22px;
  font-weight: 800;
}

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

.big-action, .button, button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.big-action {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 10px;
  text-align: center;
}

.button, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 14px;
}

.primary, .big-action.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.primary:hover { background: var(--primary-strong); }
.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.full { width: 100%; }

.danger-zone {
  border-color: #d9b1b1;
}

.form, .search, .scan-box {
  display: grid;
  gap: 12px;
  margin: 14px 0;
}

.compact { padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: #fbfcfd; }

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

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

.segmented label {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segmented input {
  width: auto;
  min-height: 0;
  margin-right: 8px;
}

.checkbox-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-line input {
  width: auto;
  min-height: 0;
}

label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

input, textarea, select {
  width: 100%;
  min-height: 46px;
  border: 1px solid #cfd8df;
  border-radius: 8px;
  padding: 10px 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
  font-weight: 500;
}

textarea { min-height: 86px; resize: vertical; }

.search {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  align-items: end;
}

.search select { min-width: 132px; }

.inline-form {
  display: inline-flex;
  margin: 2px;
}

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

.list-row {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.list-row span { color: var(--muted); font-size: 14px; }

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

.qr-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
  margin: 18px 0;
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.qr-wrap img {
  width: 180px;
  height: 180px;
  image-rendering: pixelated;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  background: #fff;
}

th, td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th { background: #eef3f2; white-space: nowrap; }

.lookup-card {
  min-height: 54px;
  padding: 12px;
  border: 1px dashed #b9c7cf;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
}

.lookup-card strong { color: var(--text); }
.lookup-card.success { border-color: #5aa98b; background: #eefaf5; color: #11694f; }
.lookup-card.warning { border-color: #d5a33b; background: #fff9e9; color: var(--warning); }
.lookup-card.error { border-color: #d78282; background: #fff1f1; color: var(--danger); }

.arrival-items,
.arrival-order-batches {
  display: grid;
  gap: 12px;
}

.arrival-item,
.arrival-batch-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.arrival-item-head,
.arrival-batch-row,
.arrival-batch-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.arrival-item-head h2,
.arrival-batch-row h2,
.arrival-batch-row p {
  margin: 0;
}

.arrival-batch-row > div:first-child {
  display: grid;
  gap: 5px;
}

@media (max-width: 720px) {
  .arrival-batch-row,
  .arrival-batch-actions {
    align-items: stretch;
    flex-direction: column;
  }
}

.scan-sound-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  width: fit-content;
  min-height: 42px;
}

.scan-sound-toggle input {
  width: 22px;
  min-height: 22px;
  margin: 0;
}

.scanner-help {
  margin: 14px 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
}

.scanner-help summary { cursor: pointer; font-weight: 800; }
.scanner-help p { margin: 8px 0 0; color: var(--muted); }

.notice {
  margin: 10px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-weight: 700;
}

.notice.warning {
  border-color: #d5a33b;
  background: #fff9e9;
  color: var(--warning);
}

.cart-list {
  display: grid;
  gap: 10px;
  min-height: 42px;
}

.cart-row {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.cart-row .cart-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
}

.cart-row button {
  min-height: 34px;
  padding: 4px 9px;
  border-color: #e0b6b6;
  color: var(--danger);
}

.totals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
}

.messages {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
}

.message {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #fff;
  font-weight: 700;
}

.message.success { border-color: #7bb99e; background: #edf8f2; color: #13543e; }
.message.error { border-color: #d78282; background: #fff1f1; color: var(--danger); }

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 18px;
}

.login-shell {
  width: min(420px, 100%);
}

.login-card {
  width: 100%;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f6faf8;
  font-size: 13px;
  font-weight: 700;
}

.tabbar {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 10px 0 16px;
  padding-bottom: 4px;
}

.tab {
  flex: 0 0 auto;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 800;
}

.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.mobile-task input,
.mobile-task textarea,
.mobile-task select,
.mobile-task button {
  font-size: 17px;
}

.scan-camera {
  display: grid;
  gap: 10px;
  margin: 12px 0;
}

.scan-camera video {
  width: 100%;
  max-height: 320px;
  border-radius: 8px;
  background: #101820;
}

#html5QrReader {
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.scan-status {
  padding: 10px 12px;
  border: 1px solid #b9c7cf;
  border-radius: 8px;
  background: #fbfcfd;
  color: var(--muted);
  font-weight: 700;
}

.scan-status.error {
  border-color: #d78282;
  background: #fff1f1;
  color: var(--danger);
}

.print-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, 40mm);
  gap: 8px;
  align-items: start;
}

.label-pair {
  display: grid;
  gap: 6px;
  width: 40mm;
}

.label-pair .check,
.label-pair .print-meta {
  width: 40mm;
}

.print-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.print-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.batch-print-sheet {
  display: block;
  margin-top: 16px;
}

.product-label {
  display: block;
  position: relative;
  width: 40mm;
  height: 50mm;
  margin: 0;
  padding: 0;
  border: 0;
  overflow: hidden;
  border-radius: 0;
  background: #fff;
  color: #111;
  box-sizing: border-box;
  break-inside: avoid;
  page-break-inside: avoid;
  print-color-adjust: exact;
  -webkit-print-color-adjust: exact;
}

.label-landscape {
  position: absolute;
  left: 2mm;
  top: 46mm;
  display: grid;
  grid-template-rows: 6mm 1fr;
  gap: 1.4mm;
  width: 43mm;
  height: 34mm;
  padding: 1.5mm 1.7mm;
  overflow: hidden;
  border: 0;
  background: #fff;
  box-sizing: border-box;
  transform: rotate(-90deg);
  transform-box: border-box;
  transform-origin: top left;
}

.label-title {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  color: #111;
  font-size: 9pt;
  font-weight: 900;
  line-height: 6mm;
}

.label-body {
  display: grid;
  grid-template-columns: 17.5mm 1fr;
  gap: 1.9mm;
  min-width: 0;
  align-items: start;
}

.label-qr {
  display: grid;
  gap: .9mm;
  justify-items: center;
  min-width: 0;
}

.label-qr img {
  width: 16.8mm;
  height: 16.8mm;
  image-rendering: pixelated;
}

.label-code {
  width: 17.5mm;
  overflow-wrap: anywhere;
  text-align: center;
  color: #111;
  font-size: 4.9pt;
  font-weight: 800;
  line-height: 1.05;
}

.label-info {
  display: grid;
  gap: .9mm;
  min-width: 0;
  color: #111;
  font-size: 7pt;
  font-weight: 800;
  line-height: 1.08;
}

.label-info div {
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.label-price {
  width: 100%;
  overflow: visible !important;
  white-space: nowrap;
  text-overflow: clip !important;
  color: #000;
  font-size: 9.4pt;
  font-weight: 1000;
  line-height: 1.05;
}

.label-location {
  padding: .8mm 1.2mm;
  border: .25mm solid #111;
  border-radius: 1px;
  color: #000;
  font-size: 10pt;
  font-weight: 1000;
  line-height: 1.05;
}

.label-spec,
.label-billing {
  font-size: 7pt;
  font-weight: 900;
}

.test-label {
  position: relative;
  display: block;
  font-weight: 900;
}

.test-edge,
.test-center-text {
  position: absolute;
  z-index: 2;
  color: #000;
  font-size: 6pt;
  line-height: 1.1;
  text-align: center;
  background: rgba(255,255,255,.8);
}

.test-top { top: 2mm; left: 50%; transform: translateX(-50%); }
.test-bottom { bottom: 2mm; left: 50%; transform: translateX(-50%); }
.test-left { left: 2mm; top: 50%; transform: translateY(-50%) rotate(-90deg); transform-origin: center; }
.test-right { right: 2mm; top: 50%; transform: translateY(-50%) rotate(90deg); transform-origin: center; }

.test-center-line {
  position: absolute;
  z-index: 1;
  background: #000;
}

.test-center-v {
  top: 2mm;
  bottom: 2mm;
  left: 50%;
  width: .2mm;
}

.test-center-h {
  left: 2mm;
  right: 2mm;
  top: 50%;
  height: .2mm;
}

.test-center-text {
  left: 50%;
  top: 50%;
  padding: 1mm;
  border: .2mm solid #000;
  transform: translate(-50%, -50%);
  font-size: 7pt;
}

@media print {
  @page {
    size: 40mm 50mm;
    margin: 0;
  }
  html, body {
    width: 40mm;
    margin: 0 !important;
    padding: 0 !important;
    overflow: visible;
    background: #fff;
  }
  .topbar, .site-footer, .no-print, .messages { display: none !important; }
  .page,
  .section,
  .print-sheet,
  .batch-print-sheet {
    display: block;
    width: 40mm;
    margin: 0 !important;
    padding: 0 !important;
    border: 0;
    box-shadow: none;
  }
  .batch-print-sheet {
    font-size: 0;
    line-height: 0;
  }
  .label-pair { break-inside: avoid; page-break-inside: avoid; width: 40mm; margin: 0; padding: 0; }
  .product-label {
    display: block;
    position: relative;
    float: none;
    width: 40mm;
    height: 50mm;
    margin: 0 !important;
    padding: 0 !important;
    border: 0;
    border-radius: 0;
    overflow: hidden;
    box-sizing: border-box;
    break-inside: avoid;
    page-break-inside: avoid;
    break-after: auto;
    page-break-after: auto;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: center;
    flex-direction: row;
    padding: 10px 12px;
  }

  .brand {
    font-size: 18px;
  }

  .desktop-nav,
  .desktop-userbar {
    display: none;
  }

  .mobile-menu {
    position: relative;
    display: block;
    margin-left: auto;
  }

  .mobile-menu summary {
    min-height: 44px;
    padding: 9px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    font-weight: 800;
    list-style: none;
    cursor: pointer;
  }

  .mobile-menu summary::-webkit-details-marker {
    display: none;
  }

  .mobile-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 40;
    display: grid;
    gap: 8px;
    width: min(320px, calc(100vw - 24px));
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow);
  }

  .mobile-menu-panel a {
    min-height: 46px;
    display: flex;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    font-weight: 800;
  }

  .mobile-user {
    padding: 6px 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
  }

  .page {
    width: 100%;
    padding: 10px 0;
  }

  .section {
    width: 100%;
    padding: 14px 12px;
    border-left: 0;
    border-right: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .desktop-dashboard {
    display: none;
  }

  .mobile-dashboard {
    display: block;
  }

  .mobile-dashboard h2 {
    margin-top: 18px;
  }

  .two, .detail-grid, .totals { grid-template-columns: 1fr; }
  .stats, .action-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .more-grid { grid-template-columns: 1fr; }
  .search { grid-template-columns: 1fr; }
  .section-head {
    align-items: stretch;
    flex-direction: column;
  }
  .print-tools {
    display: grid;
    grid-template-columns: 1fr;
  }
  .table-wrap {
    width: 100%;
    max-width: 100%;
  }
  table {
    min-width: 620px;
  }
  input, textarea, select, .button, button, .big-action {
    min-height: 48px;
  }
  .big-action {
    padding: 16px 8px;
  }
  .mobile-task input,
  .mobile-task textarea,
  .mobile-task select,
  .mobile-task button {
    font-size: 17px;
  }
  h1 { font-size: 22px; }
  .stats span, .detail-grid strong { font-size: 20px; }
}
