:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #18202a;
  --muted: #657083;
  --line: #d9dee7;
  --primary: #146c5f;
  --primary-dark: #0e554a;
  --danger: #b42318;
  --success: #147a3f;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 15px;
}

a {
  color: var(--primary);
  text-decoration: none;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 0 28px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.brand {
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.nav {
  display: flex;
  gap: 16px;
  flex: 1;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  white-space: nowrap;
}

.lang-switch a {
  color: var(--muted);
}

.lang-switch a.active {
  color: var(--primary);
  font-weight: 700;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  color: var(--muted);
}

.container {
  width: min(1120px, calc(100% - 40px));
  margin: 28px auto;
}

.narrow {
  width: min(680px, calc(100% - 40px));
}

.page-title {
  margin-bottom: 20px;
}

.page-title h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.page-title p,
.muted,
.hint {
  color: var(--muted);
  margin: 0;
}

.row-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.panel,
.login-panel,
.table-wrap,
.notice {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
}

.login-lang {
  justify-content: flex-end;
  margin-bottom: 14px;
}

.login-panel h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.form {
  display: grid;
  gap: 16px;
}

label {
  display: grid;
  gap: 7px;
  font-weight: 600;
}

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 10px;
}

.checkbox-label input {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  font: inherit;
  background: #ffffff;
}

textarea {
  resize: vertical;
}

.button {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 9px 14px;
  font: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
}

.primary {
  background: var(--primary);
  color: #ffffff;
}

.primary:hover {
  background: var(--primary-dark);
}

.secondary {
  background: #ffffff;
  color: var(--text);
  border-color: var(--line);
}

.danger {
  background: var(--danger);
  color: #ffffff;
}

.form-actions {
  display: flex;
  gap: 10px;
}

.flash {
  border-radius: 6px;
  padding: 11px 13px;
  margin-bottom: 16px;
  border: 1px solid;
}

.flash.error {
  color: var(--danger);
  background: #fff3f0;
  border-color: #ffd2cc;
}

.flash.success {
  color: var(--success);
  background: #eefbf3;
  border-color: #c7efd5;
}

.flash.warning {
  color: #8a5a00;
  background: #fff7df;
  border-color: #ffe3a3;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.stats-grid div {
  display: grid;
  gap: 4px;
  padding: 14px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats-grid strong {
  font-size: 22px;
}

.stats-grid span {
  color: var(--muted);
}

.action-card {
  display: grid;
  gap: 8px;
  min-height: 110px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--text);
}

.action-card span {
  color: var(--muted);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-weight: 700;
  background: #fafbfc;
}

.empty {
  text-align: center;
  color: var(--muted);
}

.mono {
  font-family: Consolas, "Courier New", monospace;
}

.inline-form {
  display: inline;
}

.inline-block-form {
  display: inline-block;
  margin-bottom: 14px;
}

.row-actions {
  display: flex;
  gap: 12px;
}

.link-button {
  border: 0;
  background: transparent;
  padding: 0;
  color: var(--primary);
  cursor: pointer;
  font: inherit;
}

.danger-link {
  color: var(--danger);
}

.error-detail {
  padding: 12px;
  overflow: auto;
  background: #f1f3f5;
  border-radius: 6px;
}

.shipment-block {
  margin-bottom: 16px;
}

.shipment-block h2,
.panel h2 {
  margin: 0 0 10px;
  font-size: 20px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 150px 1fr;
  gap: 10px 16px;
  margin: 14px 0;
}

.detail-grid dt {
  color: var(--muted);
  font-weight: 700;
}

.detail-grid dd {
  margin: 0;
}

.plain-pre {
  margin: 0;
  white-space: pre-wrap;
  font: inherit;
}

.compact-table {
  padding: 0;
}

.danger-text {
  color: var(--danger);
  margin: 0;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 22px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  border: 1px solid transparent;
}

.status-badge.pending,
.status-badge.parsed,
.status-badge.success,
.status-badge.scanned,
.status-badge.ready_for_print,
.status-badge.shipped {
  color: var(--success);
  background: #eefbf3;
  border-color: #c7efd5;
}

.status-badge.picking,
.status-badge.duplicate,
.status-badge.warning,
.status-badge.printed,
.status-badge.info {
  color: #8a5a00;
  background: #fff7df;
  border-color: #ffe3a3;
}

.status-badge.exception,
.status-badge.partial_exception,
.status-badge.failed,
.status-badge.error,
.status-badge.not_found,
.status-badge.locked_by_other,
.status-badge.shipment_exception,
.status-badge.item_exception,
.status-badge.already_shipped {
  color: var(--danger);
  background: #fff3f0;
  border-color: #ffd2cc;
}

.scan-form {
  display: grid;
  grid-template-columns: minmax(150px, 220px) 1fr auto;
  align-items: end;
  gap: 14px;
  margin-bottom: 18px;
}

.scan-input {
  min-height: 54px;
  font-size: 26px;
  font-family: Consolas, "Courier New", monospace;
}

.scan-result {
  margin-bottom: 18px;
}

.scan-result.success {
  border-color: #c7efd5;
}

.staging-notice {
  margin: 14px 0 0;
}

.staging-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}

.staging-cell {
  display: grid;
  gap: 10px;
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.staging-cell.occupied {
  border-color: #ffe3a3;
  background: #fffaf0;
}

.staging-no {
  font-size: 28px;
  font-weight: 700;
}

.staging-cell dl {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr);
  gap: 6px 8px;
  margin: 0;
}

.staging-cell dt {
  color: var(--muted);
  font-weight: 700;
}

.staging-cell dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.scan-result.warning {
  border-color: #ffe3a3;
}

.scan-result.error {
  border-color: #ffd2cc;
}

.scan-print-button {
  min-height: 52px;
  padding: 12px 22px;
  font-size: 18px;
  font-weight: 700;
}

.ship-button {
  min-height: 48px;
  font-weight: 700;
}

.print-toolbar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
}

.print-toolbar div {
  display: flex;
  gap: 14px;
  align-items: baseline;
}

.print-toolbar span {
  color: var(--muted);
}

.label-sheet {
  display: grid;
  grid-template-columns: repeat(auto-fill, 60mm);
  gap: 4mm;
  justify-content: start;
  padding: 6mm;
}

.barcode-label {
  width: 60mm;
  height: 30mm;
  display: grid;
  grid-template-rows: 19mm 6mm;
  align-content: center;
  padding: 3mm 4mm;
  border: 1px dashed #9aa4b2;
  background: #ffffff;
  break-inside: avoid;
  page-break-after: always;
}

.label-header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
  margin-bottom: 8px;
}

.barcode {
  width: 100%;
  height: 18mm;
  align-self: center;
  justify-self: center;
}

.scan-code {
  text-align: center;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12pt;
  font-weight: 700;
  line-height: 6mm;
}

@media (max-width: 720px) {
  .topbar,
  .row-title,
  .logout-form {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    padding: 14px 18px;
    gap: 12px;
  }

  .nav {
    flex-wrap: wrap;
  }

  .table-wrap {
    overflow-x: auto;
  }
}

@media print {
  @page {
    size: 60mm 30mm;
    margin: 0;
  }

  body {
    background: #ffffff;
  }

  .print-toolbar {
    display: none;
  }

  .label-sheet {
    padding: 0;
    display: block;
    gap: 0;
  }

  .barcode-label {
    border: 0;
    margin: 0;
    page-break-inside: avoid;
    break-after: page;
    page-break-after: always;
  }
}
