:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #dbe2ea;
  --brand: #1769aa;
  --brand-dark: #0f4f83;
  --danger: #b42318;
  --success: #087443;
}

* {
  box-sizing: border-box;
}

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

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

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 14px;
  color: var(--text);
  background: #fff;
  cursor: pointer;
}

button:hover {
  border-color: var(--brand);
}

button.primary {
  border-color: var(--brand);
  color: #fff;
  background: var(--brand);
}

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

button.danger-button {
  margin-left: 8px;
  border-color: #fecaca;
  color: var(--danger);
  background: #fff5f5;
}

button.danger-button:hover {
  border-color: var(--danger);
  background: #fee2e2;
}

button.mini-button {
  min-width: 76px;
  padding: 6px 10px;
  font-size: 13px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fff;
}

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

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

.hidden {
  display: none !important;
}

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

.login-panel {
  width: min(420px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  background: var(--panel);
  box-shadow: 0 12px 36px rgba(31, 41, 55, 0.08);
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.login-panel p {
  margin: 0 0 24px;
  color: var(--muted);
}

.login-panel label {
  margin-bottom: 14px;
}

.login-panel button {
  width: 100%;
}

.hint {
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 18px 14px;
  background: #102a43;
}

.brand {
  margin: 4px 8px 18px;
  color: #fff;
  font-size: 20px;
  font-weight: 700;
}

.nav {
  margin-bottom: 6px;
  border: 0;
  color: #d9e2ec;
  background: transparent;
  text-align: left;
}

.nav.active,
.nav:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.12);
}

.user-box {
  margin-top: auto;
  padding: 12px 8px;
  color: #d9e2ec;
  font-size: 14px;
}

.user-box button {
  width: 100%;
  margin-top: 10px;
}

.content {
  position: relative;
  padding: 28px;
}

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

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

.stats.compact strong {
  font-size: 24px;
}

.stats div,
.panel,
.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.stats div {
  padding: 18px;
}

.stats strong {
  display: block;
  margin-bottom: 6px;
  color: var(--brand);
  font-size: 28px;
}

.stats span {
  color: var(--muted);
}

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

.section-head h3 {
  margin: 0;
  font-size: 18px;
}

.section-head .actions {
  flex: 1;
  justify-content: flex-end;
}

.section-head input {
  max-width: 380px;
}

.notice {
  margin-top: 18px;
  padding: 16px;
  color: var(--muted);
}

.masters-shell {
  align-items: start;
}

.company-list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.company-item {
  display: grid;
  gap: 4px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbff;
  text-align: left;
}

.company-item strong {
  font-size: 15px;
}

.company-item span {
  color: var(--muted);
  font-size: 13px;
}

.company-item.active {
  border-color: var(--brand);
  background: #eaf4ff;
}

.company-overview-panel {
  margin-top: 18px;
  padding: 18px;
}

.company-overview-stats {
  margin-bottom: 18px;
}

.company-overview-grid {
  margin-top: 16px;
}

.print-station {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--panel);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 15px;
}

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

#autoPrintStatus {
  color: var(--muted);
  font-size: 13px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.panel {
  padding: 18px;
}

.panel h3 {
  margin: 0 0 14px;
}

.panel label,
.stack-form input {
  margin-bottom: 12px;
}

.actions,
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar input {
  max-width: 420px;
}

.inline-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.wide {
  grid-column: span 2;
}

.stack-form {
  display: grid;
  gap: 8px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.table-wrap.ledger {
  max-height: calc(100vh - 260px);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 860px;
}

.ledger table {
  min-width: 1980px;
}

#logs table {
  min-width: 1280px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 10px 12px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #f8fafc;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: 0;
}

.number {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.strong {
  color: var(--brand);
  font-weight: 700;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
}

.badge.ok {
  color: #087443;
  background: #e7f6ee;
}

.badge.danger {
  color: #b42318;
  background: #fde7e4;
}

.badge.pending {
  color: #8a4b08;
  background: #fff3d6;
}

.report-grid {
  margin-top: 16px;
}

.billing-formula {
  margin-bottom: 14px;
  padding: 14px 16px;
  color: #334e68;
}

.billing-stats {
  margin: 14px 0;
}

.billing-table table {
  min-width: 1420px;
}

.table-input {
  width: 110px;
  min-height: 34px;
  text-align: right;
}

.billing-actions {
  display: flex;
  gap: 6px;
}

.location-planning {
  margin-bottom: 16px;
}

.receipt-steps {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.receipt-steps div {
  display: flex;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fff;
}

.receipt-steps strong {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--brand);
}

.receipt-steps span {
  font-weight: 700;
}

.receipt-panel {
  margin-bottom: 16px;
}

.receipt-form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

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

.receipt-lines-head {
  margin-top: 16px;
}

.receipt-lines-wrap input,
.receipt-lines-wrap select {
  min-width: 110px;
}

.receipt-lines-wrap td {
  vertical-align: top;
}

.receipt-pack-inputs {
  display: flex;
  gap: 6px;
  min-width: 210px;
}

.receipt-pack-inputs input {
  min-width: 62px;
}

.receipt-review {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 14px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #f8fafc;
}

.receipt-review span {
  color: var(--muted);
}

.receipt-review.danger {
  border-color: #f0b8b1;
  background: #fff5f4;
}

.receipt-action-hint {
  margin: 0 0 12px;
  border-left: 4px solid var(--brand);
  padding: 10px 12px;
  color: #334155;
  background: #f0f7fc;
}

.receipt-action-hint.danger {
  border-left-color: var(--danger);
  color: #7a271a;
  background: #fff5f4;
}

.scan-backup summary {
  cursor: pointer;
  font-weight: 700;
}

.scan-backup .scan-input {
  margin-top: 12px;
}

.scan-console {
  margin-bottom: 16px;
}

.scan-console h3 {
  margin-top: 0;
}

.scan-input {
  min-height: 54px;
  border: 2px solid var(--brand);
  font-size: 18px;
}

.scan-input:focus {
  outline: 3px solid rgba(23, 105, 170, 0.18);
}

.scan-status-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.scan-status-grid div {
  display: grid;
  gap: 5px;
  min-height: 72px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px;
  background: #f8fafc;
}

.scan-status-grid span {
  color: var(--muted);
  font-size: 13px;
}

.scan-command-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.scan-command-cards div {
  display: grid;
  justify-items: center;
  gap: 5px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px;
  background: #fff;
  font-weight: 700;
}

.scan-command-cards img {
  width: 86px;
  height: 86px;
}

.location-plan-table {
  max-height: 360px;
}

.location-plan-table table {
  min-width: 720px;
}

.location-toolbar select {
  max-width: 320px;
}

.mini-table {
  max-height: 320px;
}

.mini-table table {
  min-width: 620px;
}

.muted-small {
  color: var(--muted);
  font-size: 12px;
}

.codes-cell {
  min-width: 180px;
  white-space: normal;
}

.code-chip {
  display: inline-block;
  margin: 2px 4px 2px 0;
  border-radius: 999px;
  padding: 3px 8px;
  color: #334e68;
  background: #edf2f7;
  font-size: 12px;
  font-family: Consolas, "Microsoft YaHei", monospace;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  width: min(760px, 100%);
  max-height: 90vh;
  overflow: auto;
  border-radius: 8px;
  padding: 20px;
  background: #fff;
}

.modal-box h3,
.modal-box .actions {
  grid-column: 1 / -1;
}

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

.product-stock-adjust {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 6px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

.product-stock-adjust h4,
.product-stock-adjust .stock-adjust-current,
.product-stock-adjust button {
  grid-column: 1 / -1;
}

.product-stock-adjust h4 {
  margin: 0;
  font-size: 16px;
}

.stock-adjust-current {
  color: var(--muted);
}

.label-modal-box {
  width: min(620px, 100%);
}

.pallet-label {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 14px;
  border: 2px solid #111827;
  padding: 16px;
  color: #111827;
  background: #fff;
}

.label-title {
  grid-column: 1 / -1;
  border-bottom: 1px solid #111827;
  padding-bottom: 8px;
  font-size: 22px;
  font-weight: 800;
  text-align: center;
}

.label-qr {
  width: 160px;
  height: 160px;
  border: 1px solid var(--line);
  background: #fff;
}

.label-info {
  display: grid;
  align-content: start;
  gap: 7px;
  font-size: 14px;
  line-height: 1.4;
}

.qr {
  width: 76px;
  height: 76px;
  border: 1px solid var(--line);
  background: #fff;
}

.list {
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.list li {
  border-top: 1px solid var(--line);
  padding: 10px 0;
}

.toast {
  position: fixed;
  right: 24px;
  top: 18px;
  z-index: 5;
  max-width: 360px;
  border-radius: 8px;
  padding: 12px 14px;
  color: #fff;
  background: var(--success);
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.16);
}

.toast.error {
  background: var(--danger);
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  .grid.two,
  .stats,
  .receipt-steps,
  .receipt-form-grid,
  .inline-form {
    grid-template-columns: 1fr;
  }

  .section-head,
  .actions,
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .section-head input,
  .toolbar input {
    max-width: none;
  }

  .scan-status-grid,
  .scan-command-cards {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

@media print {
  body * {
    visibility: hidden;
  }

  #labelPrintArea,
  #labelPrintArea * {
    visibility: visible;
  }

  #labelPrintArea {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    max-width: 100%;
  }

  .no-print {
    display: none !important;
  }
}
