:root {
  --bg: #f5f6f7;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --line: #d9dee5;
  --text: #20242a;
  --muted: #667085;
  --primary: #176b5b;
  --primary-strong: #0d4f43;
  --danger: #b42318;
  --warning: #8a5a00;
  --focus: #2d7dd2;
  --shadow: 0 10px 30px rgba(30, 40, 55, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  height: 38px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
}

button:hover {
  border-color: #aeb7c3;
}

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

button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

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

button.saved,
button.saved:hover {
  background: #0f766e;
  border-color: #0f766e;
  color: white;
}

button.ghost {
  background: transparent;
}

button.wide {
  width: 100%;
}

input,
select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--text);
  padding: 0 10px;
}

input:focus,
select:focus,
button:focus {
  outline: 2px solid rgba(45, 125, 210, 0.25);
  outline-offset: 1px;
  border-color: var(--focus);
}

label span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.field-hint {
  display: block;
  margin-top: 6px;
  min-height: 16px;
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
  line-height: 1.35;
}

.required::after {
  content: " *";
  color: var(--danger);
  font-weight: 700;
}

.hidden {
  display: none !important;
}

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

.login-panel {
  width: min(380px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 16px;
}

.login-panel h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

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

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 232px minmax(0, 1fr);
}

.sidebar {
  background: #ffffff;
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: grid;
  gap: 6px;
  padding: 4px 6px 12px;
  border-bottom: 1px solid var(--line);
}

.brand strong {
  font-size: 18px;
}

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

nav {
  display: grid;
  gap: 6px;
  align-content: start;
}

nav button {
  text-align: left;
  background: transparent;
  border-color: transparent;
  justify-content: flex-start;
}

nav button.active {
  background: #e8f3ef;
  border-color: #c9e4da;
  color: var(--primary-strong);
  font-weight: 650;
}

.content {
  padding: 26px;
  min-width: 0;
}

.tab-page {
  display: none;
  max-width: 1180px;
}

.tab-page.active {
  display: block;
}

.page-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-title h2 {
  margin: 0 0 6px;
  font-size: 24px;
}

.page-title p {
  margin: 0;
  color: var(--muted);
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 160px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.sub-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 14px;
  border-bottom: 1px solid var(--line);
}

.sub-tabs button {
  height: 36px;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 12px;
}

.sub-tabs button.active {
  color: var(--primary-strong);
  border-bottom-color: var(--primary);
  font-weight: 650;
}

.operation-page,
.config-page {
  display: none;
}

.operation-page.active,
.config-page.active {
  display: block;
}

.sub-page-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}

.sub-page-title h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.sub-page-title p {
  margin: 0;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
}

.flow-form {
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 10px 12px;
  padding: 12px;
}

.flow-form input,
.flow-form select,
.flow-form button {
  height: 34px;
}

.flow-form label span {
  margin-bottom: 4px;
}

.compact-operation-form {
  padding: 12px;
  gap: 10px 12px;
}

.compact-operation-form input,
.compact-operation-form select,
.compact-operation-form button {
  height: 34px;
}

.span-2 {
  grid-column: span 2;
}

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

.candidate-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 30px;
}

.candidate-list button {
  height: auto;
  min-height: 34px;
  background: var(--surface-2);
  white-space: normal;
  text-align: left;
}

.packaging-form {
  grid-template-columns: minmax(220px, 320px) minmax(0, 1fr);
}

.batch-rows {
  display: grid;
  gap: 12px;
}

.batch-row {
  display: grid;
  grid-template-columns: 34px minmax(180px, 1.2fr) minmax(120px, 0.8fr) minmax(180px, 1fr) 120px minmax(150px, 0.9fr) auto;
  gap: 10px;
  align-items: end;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.batch-counter {
  padding: 4px 0;
}

.shipment-ticket {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.shipment-ticket-head,
.shipment-box-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.shipment-ticket-head h3 {
  margin: 0 0 4px;
}

.shipment-box-list,
.shipment-sku-list {
  display: grid;
  gap: 10px;
}

.shipment-box {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.shipment-box-head {
  display: grid;
  grid-template-columns: 44px minmax(180px, 1fr) minmax(160px, 0.8fr) auto;
  align-items: end;
}

.shipment-sku-row {
  display: grid;
  grid-template-columns: 58px minmax(180px, 1fr) minmax(130px, 0.8fr) 100px auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.row-index {
  height: 38px;
  min-width: 34px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: white;
}

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

.span-all {
  grid-column: 2 / -1;
}

.no-margin {
  margin-top: 0;
  align-self: end;
}

.result-area,
.draft-area {
  margin-top: 14px;
}

.overview-grid {
  display: grid;
  gap: 14px;
}

.settings-grid {
  display: grid;
  gap: 14px;
}

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

.section-head h3 {
  margin: 0;
}

.section-head span {
  color: var(--muted);
  font-size: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 14px;
  overflow: auto;
}

.panel h3 {
  margin: 0 0 12px;
  font-size: 17px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  min-width: 720px;
}

.compact-table {
  min-width: 0;
}

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

.table th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  background: var(--surface-2);
}

.interactive-table th {
  padding: 6px 8px;
}

.inventory-table-scroll {
  max-height: min(62vh, 680px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.inventory-table-scroll .table {
  border-collapse: separate;
  border-spacing: 0;
  min-width: 980px;
}

.inventory-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 1px 0 var(--line);
}

.inventory-table-scroll tbody tr:last-child td {
  border-bottom: 0;
}

.sortable-head {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.sort-icon {
  width: 20px;
  height: 22px;
  min-height: 0;
  padding: 0;
  display: inline-grid;
  place-items: center;
  gap: 1px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: white;
}

.sort-icon:hover {
  border-color: var(--accent);
}

.sort-up,
.sort-down {
  width: 0;
  height: 0;
  opacity: 0.42;
}

.sort-up {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-bottom: 5px solid var(--muted);
}

.sort-down {
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}

.sort-icon.is-asc .sort-up {
  opacity: 1;
  border-bottom-color: var(--accent);
}

.sort-icon.is-desc .sort-down {
  opacity: 1;
  border-top-color: var(--accent);
}

.table-meta {
  margin: 0 0 8px;
  font-size: 12px;
}

.table-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin: 0 0 10px;
}

.table-controls label {
  min-width: 180px;
}

.table-controls input,
.table-controls select {
  height: 34px;
  font-size: 13px;
}

.table-input {
  width: 110px;
  min-width: 88px;
}

.wide-input {
  width: 180px;
}

.cell-actions {
  white-space: nowrap;
}

.bom-group {
  overflow: visible;
}

.bom-add-area {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.bom-draft-rows {
  display: grid;
  gap: 10px;
}

.bom-draft-row {
  display: grid;
  grid-template-columns: 34px minmax(260px, 1.4fr) minmax(160px, 1fr) 120px minmax(150px, 1fr) auto;
  gap: 10px;
  align-items: end;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.table tr.needs-replenishment td {
  background: #fff1f1;
}

.table td.alert-number {
  color: var(--danger);
  font-weight: 700;
}

.kv {
  display: grid;
  grid-template-columns: 170px minmax(0, 1fr);
  border-top: 1px solid var(--line);
}

.kv div {
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.kv div:nth-child(odd) {
  color: var(--muted);
}

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

.compact-toolbar {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0 0 12px;
}

.error {
  color: var(--danger);
  min-height: 18px;
}

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

.warn {
  color: var(--warning);
}

.toast {
  position: fixed;
  right: 24px;
  top: 18px;
  z-index: 20;
  background: #17221f;
  color: #fff;
  border-radius: 8px;
  padding: 12px 14px;
  max-width: 460px;
  box-shadow: var(--shadow);
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #111827;
  color: #f9fafb;
  padding: 14px;
  border-radius: 8px;
  overflow: auto;
}

.collapsible-panel summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  font-weight: 650;
  list-style: none;
}

.collapsible-panel summary::-webkit-details-marker {
  display: none;
}

.collapsible-panel summary::before {
  content: ">";
  color: var(--muted);
  font-family: monospace;
}

.collapsible-panel[open] summary::before {
  content: "v";
}

.collapsible-panel[open] summary .muted {
  font-size: 0;
}

.collapsible-panel[open] summary .muted::after {
  content: "点击收起";
  font-size: 12px;
}

.collapsible-panel pre {
  margin-top: 12px;
}

.inspection-summary {
  min-width: 420px;
}

.inspection-summary summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  cursor: pointer;
  list-style: none;
}

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

.inspection-summary summary .muted {
  white-space: nowrap;
}

.inspection-detail {
  display: grid;
  gap: 10px;
  margin-top: 12px;
  color: var(--text);
}

.inspection-detail-row {
  display: grid;
  grid-template-columns: 110px minmax(0, 1fr);
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.inspection-detail-row strong {
  font-size: 12px;
  color: var(--muted);
}

.inspection-detail-row ul {
  margin: 0;
  padding-left: 18px;
}

.inspection-detail-row li + li {
  margin-top: 4px;
}

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

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

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

  .content {
    padding: 18px;
  }

  .toolbar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .flow-form {
    grid-template-columns: 1fr;
  }

  .span-2 {
    grid-column: span 1;
  }

  .packaging-form,
  .batch-row,
  .bom-draft-row,
  .shipment-box-head,
  .shipment-sku-row {
    grid-template-columns: 1fr;
  }

  .span-all {
    grid-column: span 1;
  }
}
