:root {
  --bg: #eef2f4;
  --panel: #ffffff;
  --text: #1c262d;
  --muted: #667782;
  --line: #d6e0e5;
  --sidebar: #22313a;
  --teal: #1f6f78;
  --teal-dark: #185862;
  --yellow: #fff200;
  --soft: #f7fafb;
  --danger: #c94842;
  --warn: #b7791f;
  --ok: #24724b;
}

* { box-sizing: border-box; }

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

button, input, select {
  font: inherit;
}

textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  min-height: 38px;
  padding: 0 14px;
  font-weight: 700;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: .62;
}

button[hidden],
[hidden] {
  display: none !important;
}

input, select {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd7dd;
  border-radius: 6px;
  padding: 7px 10px;
  background: #fff;
}

input[type="checkbox"] {
  width: auto;
  min-height: 0;
  padding: 0;
}

textarea {
  width: 100%;
  border: 1px solid #cbd7dd;
  border-radius: 6px;
  padding: 9px 10px;
  resize: vertical;
  min-height: 110px;
}

a { color: var(--teal); font-weight: 700; text-decoration: none; }

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

.sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 18px 14px;
}

.brand {
  border-bottom: 1px solid rgba(255,255,255,.15);
  padding: 4px 4px 20px;
  margin-bottom: 14px;
}

.brand b {
  display: block;
  font-size: 19px;
}

.nav {
  display: grid;
  gap: 14px;
}

.nav-group {
  display: grid;
  gap: 7px;
}

.nav-title {
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  padding: 8px 8px 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-radius: 6px;
  user-select: none;
}

.nav-title:hover,
.nav-title:focus-visible {
  background: rgba(255,255,255,.1);
  outline: none;
}

.nav-title::after {
  content: "-";
  font-weight: 900;
  color: rgba(255,255,255,.72);
}

.nav-group.collapsed .nav-title::after {
  content: "+";
}

.nav-sub {
  display: grid;
  gap: 5px;
}

.nav-group.collapsed .nav-sub {
  display: none;
}

.nav button {
  width: 100%;
  color: rgba(255,255,255,.78);
  background: transparent;
  text-align: left;
  padding-left: 24px;
  min-height: 34px;
}

.nav button.nav-direct {
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  padding: 8px;
  min-height: 38px;
}

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

.main {
  padding: 22px;
  min-width: 0;
}

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

.title-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  min-width: 0;
}

h1, h2, p {
  margin: 0;
}

h1 {
  font-size: 25px;
  line-height: 1.25;
  white-space: nowrap;
}

h2 {
  font-size: 16px;
}

.topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: nowrap;
  justify-content: flex-end;
}

.primary {
  background: var(--teal);
  color: #fff;
}

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

.secondary {
  background: #e3ecef;
  color: #22313a;
}

.ghost {
  background: #fff;
  color: #25343d;
  border: 1px solid var(--line);
}

.small {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.full { width: 100%; }

.summary-strip {
  display: grid;
  grid-template-columns: .72fr 1fr 1fr .92fr repeat(5, .88fr);
  gap: 8px;
  margin-bottom: 14px;
}

#workbenchGlobalSummary[hidden] {
  display: none !important;
}

.summary-strip span {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-width: 0;
  height: 58px;
  padding: 8px 11px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.summary-strip span.warn {
  background: #fffaf0;
  border-color: #e5c078;
}

.summary-strip em {
  min-width: 0;
  font-style: normal;
  color: var(--muted);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.summary-strip b {
  color: #0b2235;
  font-size: 20px;
  line-height: 1;
  white-space: nowrap;
}

.page {
  display: none;
}

.page.active {
  display: block;
}

body.page-rules-active .summary-strip {
  display: none;
}

body.production-active .main > .topbar,
body.production-active .main > .summary-strip {
  display: none;
}

.production-page {
  display: none;
}

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

.production-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  margin-bottom: 14px;
}

.production-topbar p {
  margin-top: 6px;
  color: var(--muted);
}

.production-summary {
  grid-template-columns: .72fr 1fr 1fr .92fr .88fr;
}

.production-work-grid {
  grid-template-columns: 320px minmax(280px, .58fr) minmax(520px, 1fr);
}

.carton-label-summary {
  grid-template-columns: repeat(7, minmax(96px, 1fr)) auto;
  align-items: center;
}

#page-gap-on-carton-labels .summary-action-btn {
  justify-self: end;
  align-self: center;
  min-height: 38px;
  margin-left: auto;
  white-space: nowrap;
}

.carton-label-work-grid {
  grid-template-columns: 320px minmax(280px, .5fr) minmax(560px, 1fr);
}

.carton-label-work-grid .tabs {
  justify-content: flex-end;
}

.carton-label-work-grid .excel-table {
  min-width: 100%;
}

.carton-label-work-grid .excel-table .empty {
  height: 180px;
  text-align: center;
  vertical-align: middle;
  background: #fbfdfe;
  color: var(--muted);
}

.production-preview-table th,
.production-preview-table td {
  min-width: 88px;
  white-space: nowrap;
}

.production-preview-table .total-row td {
  background: #fffaf0;
  font-weight: 800;
}

.production-preview-table .prepack-note-cell {
  white-space: pre-line;
  line-height: 1.45;
}

.production-preview-table .merged-color-cell {
  vertical-align: middle;
}

.special-preview-tools {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.special-image-upload {
  margin-top: 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--soft);
}

.special-image-upload .subsection-title {
  margin: 0 0 10px;
  font-size: 15px;
}

.special-image-list {
  display: grid;
  gap: 8px;
}

.special-image-row {
  display: grid;
  grid-template-columns: 16px 58px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 5px 8px;
  border: 1px solid #d7e2e8;
  border-radius: 5px;
  background: #fff;
}

.color-dot {
  width: 16px;
  height: 16px;
  border-radius: 3px;
  background: var(--dot-color, #8a98a4);
  border: 1px solid rgba(0, 0, 0, .12);
}

.image-file-name {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  cursor: pointer;
}

.special-remark-cell {
  min-width: 140px;
  white-space: normal;
  padding: 4px;
}

.special-remark-cell textarea {
  width: 100%;
  min-width: 132px;
  min-height: 34px;
  resize: vertical;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  padding: 5px 7px;
  font: inherit;
  line-height: 1.35;
}

.special-remark-cell textarea:focus {
  border-color: var(--teal);
  background: #fff;
  outline: none;
  box-shadow: 0 0 0 2px rgba(22, 119, 134, .12);
}

body.special-production-fullscreen {
  overflow: hidden;
}

body.special-production-fullscreen #page-special-production-output .preview-panel {
  position: fixed;
  inset: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  padding: 14px;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(7, 31, 51, .28);
}

body.special-production-fullscreen #page-special-production-output .preview-panel .excel-wrap {
  flex: 1;
  max-height: none;
  overflow: auto;
}

body.special-production-fullscreen #page-special-production-output .production-preview-table th,
body.special-production-fullscreen #page-special-production-output .production-preview-table td {
  min-width: 96px;
}

body.special-production-fullscreen #page-special-production-output .special-remark-cell,
body.special-production-fullscreen #page-special-production-output .special-remark-cell textarea {
  min-width: 320px;
}

body.special-production-fullscreen #page-special-production-output .special-remark-cell textarea {
  min-height: 68px;
  white-space: normal;
}

#page-special-production-output .preview-panel {
  grid-column: 2 / 4;
  grid-row: 1 / span 2;
}

.special-buyer-review-panel {
  grid-column: 2 / 4;
}

.buyer-review-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(120px, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.buyer-review-summary span {
  display: grid;
  gap: 4px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fbfdff;
}

.buyer-review-summary em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.buyer-review-summary b {
  font-size: 18px;
}

.buyer-review-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 12px;
  min-height: 360px;
}

.buyer-review-table-wrap {
  max-height: 430px;
}

.buyer-review-table .review-status-ok td:first-child {
  color: #24724b;
  font-weight: 800;
}

.buyer-review-table .review-status-warning td:first-child {
  color: #9a6500;
  font-weight: 800;
}

.buyer-review-table .review-status-ignored td:first-child {
  color: #587085;
  font-weight: 800;
}

.buyer-review-table .review-status-manual-ok td:first-child {
  color: #24724b;
  font-weight: 800;
}

.buyer-review-table .review-status-error td:first-child,
.buyer-review-table .diff-cell {
  color: #c0392b;
  font-weight: 800;
}

.buyer-review-table tr.selected-row td {
  background: #eef8fa;
  box-shadow: inset 0 1px 0 #167786, inset 0 -1px 0 #167786;
}

.buyer-review-table .review-status-ignored td,
.buyer-review-table .review-status-manual-ok td {
  background: #f7fbf8;
}

.buyer-review-side {
  display: grid;
  gap: 12px;
  align-content: start;
  min-width: 0;
}

.buyer-review-reason {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid #d8e6ed;
  border-radius: 7px;
  background: #fbfdff;
}

.buyer-review-reason b {
  font-size: 15px;
}

.buyer-review-reason p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.buyer-review-diff-note {
  color: #9c3227 !important;
  font-weight: 700;
}

.buyer-review-confirmed {
  color: #24724b !important;
}

.buyer-review-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.buyer-review-actions .primary {
  padding-inline: 10px;
}

.buyer-source-card {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.buyer-source-card pre {
  min-height: 150px;
  max-height: 260px;
  margin: 0;
  padding: 10px;
  overflow: auto;
  border-radius: 7px;
  background: #0f1f2d;
  color: #d9e8f1;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

body.special-buyer-review-fullscreen {
  overflow: hidden;
}

body.special-buyer-review-fullscreen #specialBuyerReviewPanel {
  position: fixed;
  inset: 12px;
  z-index: 21;
  display: flex;
  flex-direction: column;
  padding: 14px;
  background: var(--panel);
  box-shadow: 0 18px 45px rgba(7, 31, 51, .28);
}

body.special-buyer-review-fullscreen #specialBuyerReviewPanel .buyer-review-layout {
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 340px;
  min-height: 0;
}

body.special-buyer-review-fullscreen #specialBuyerReviewPanel .buyer-review-table-wrap,
body.special-buyer-review-fullscreen #specialBuyerReviewPanel .buyer-source-card pre {
  max-height: none;
}

.production-rule-layout {
  display: grid;
  grid-template-columns: minmax(280px, .9fr) minmax(360px, 1.1fr);
  gap: 14px;
}

.production-rule-toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.rule-page-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.production-rule-layout .rule-block {
  background: var(--soft);
  border: 1px solid #e0e8ec;
  border-radius: 6px;
  padding: 14px;
  min-width: 0;
}

.production-rule-layout .rule-block:last-child {
  grid-column: 1 / -1;
}

.production-rule-layout .subsection-title {
  margin: 16px 0 10px;
  font-size: 15px;
}

.rule-block h3 {
  margin: 0 0 12px;
  font-size: 16px;
}

.rule-block-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.rule-block-title h3 {
  margin: 0;
}

.editable-rule-table input,
.editable-rule-table select {
  min-height: 30px;
  height: 30px;
  padding: 4px 7px;
  border-radius: 4px;
  font-size: 13px;
}

.editable-rule-table input[type="checkbox"] {
  width: 16px;
  height: 16px;
  min-height: 0;
}

.editable-rule-table td {
  vertical-align: middle;
}

.mix-rule-table input {
  text-align: center;
}

.mix-size-toolbar {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.rule-hint {
  margin-top: 10px;
  color: var(--muted);
  font-size: 13px;
}

.field-hint {
  margin: -6px 0 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

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

.rule-note {
  margin-top: 14px;
  padding: 10px 12px;
  background: #fffaf0;
  border: 1px solid #e5c078;
  border-radius: 6px;
  color: #5f4a17;
  font-size: 13px;
}

.rulebook-panel {
  max-width: none;
}

.rulebook-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 14px;
  align-items: start;
}

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

.rulebook-card {
  background: var(--soft);
  border: 1px solid #d8e4e9;
  border-radius: 6px;
  padding: 16px 18px;
}

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

.rulebook-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.rulebook-card ol {
  margin: 0;
  padding-left: 20px;
  color: #263f4c;
  line-height: 1.7;
}

.rulebook-card li + li {
  margin-top: 3px;
}

.rulebook-updates {
  position: sticky;
  top: 14px;
  background: #f8fbfc;
  border: 1px solid #d8e4e9;
  border-radius: 6px;
  padding: 16px;
}

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

.update-item {
  border-left: 3px solid #77abb8;
  padding-left: 12px;
  margin-bottom: 14px;
}

.update-item:last-child {
  margin-bottom: 0;
}

.update-item time {
  display: block;
  color: #0f6975;
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 5px;
}

.update-item p {
  margin: 0;
  color: #314c5a;
  font-size: 13px;
  line-height: 1.55;
}

.usage-help-panel {
  max-width: none;
}

.usage-help-panel .panel-title {
  align-items: flex-start;
}

.usage-subtitle {
  margin-top: 6px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.usage-alert {
  margin-bottom: 16px;
  border: 1px solid #e5b35b;
  border-radius: 7px;
  background: #fff8e8;
  padding: 13px 16px;
  color: #6f4b09;
}

.usage-alert b {
  display: block;
  margin-bottom: 5px;
  font-size: 16px;
}

.usage-alert p {
  margin: 0;
  line-height: 1.6;
}

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

.usage-card {
  min-width: 0;
  border: 1px solid #d8e4e9;
  border-radius: 7px;
  background: #f8fbfc;
  padding: 16px 18px;
}

.usage-card h3 {
  margin: 0 0 10px;
  font-size: 17px;
}

.usage-card ol {
  margin: 0;
  padding-left: 20px;
  color: #263f4c;
  line-height: 1.7;
}

.usage-card li + li {
  margin-top: 4px;
}

.usage-card details {
  border: 1px solid #c9dce5;
  border-radius: 7px;
  background: #fff;
  padding: 0;
  overflow: hidden;
}

.usage-card summary {
  cursor: pointer;
  padding: 12px 14px;
  background: #eaf5f8;
  color: #16323d;
  font-weight: 800;
}

.usage-card details ol {
  padding: 12px 18px 14px 34px;
}

.tail-drag-demo {
  margin: 0 14px 14px;
  border: 1px solid #bfcbd1;
  border-radius: 7px;
  background: #fff;
  overflow: hidden;
}

.tail-drag-demo-title {
  padding: 10px 12px;
  background: #f7fafb;
  color: #1c3440;
  font-weight: 800;
}

.tail-drag-demo-grid {
  display: grid;
  grid-template-columns: .85fr 1.15fr .85fr .75fr .75fr .85fr;
  border-top: 1px solid #333;
  border-left: 1px solid #333;
  margin: 0 12px 12px;
  font-family: "Times New Roman", "SimSun", serif;
  font-size: 14px;
}

.demo-cell {
  min-height: 34px;
  display: grid;
  place-items: center;
  border-right: 1px solid #333;
  border-bottom: 1px solid #333;
  padding: 4px 6px;
  text-align: center;
  white-space: nowrap;
}

.demo-head {
  background: var(--yellow);
  font-weight: 800;
}

.demo-source {
  background: #fff7a8;
  box-shadow: inset 0 0 0 2px #d88300;
  font-weight: 800;
}

.demo-mixed {
  background: #d9d9d9;
}

.tail-drag-arrow {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 12px 13px;
  color: #5b6f7a;
  font-size: 13px;
}

.tail-drag-arrow b {
  position: relative;
  padding: 7px 14px;
  border: 1px solid #f0ad4e;
  border-radius: 999px;
  background: #fff3d8;
  color: #805000;
}

.tail-drag-arrow b::before,
.tail-drag-arrow b::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 20px;
  height: 2px;
  background: #f0ad4e;
}

.tail-drag-arrow b::before {
  right: 100%;
}

.tail-drag-arrow b::after {
  left: 100%;
}

.settings-grid.single {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.work-grid {
  display: grid;
  grid-template-columns: minmax(280px, 320px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.preview-panel {
  grid-column: 2;
  grid-row: 1 / span 2;
}

.ai-panel {
  grid-column: 1;
  grid-row: 2;
}

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

.field {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 12px;
}

.field input,
.field select {
  color: var(--text);
  font-size: 14px;
}

.meta-list {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.meta-list b {
  color: var(--text);
}

.rule-card-actions {
  margin-top: 12px;
}

.rule-card-actions button {
  width: 100%;
}

.rule-page-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  background: #edf4f6;
  color: #24535b;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.badge.ai-online {
  background: #e1f3e8;
  color: #24724b;
}

.badge.ai-offline {
  background: #fff5f4;
  color: #b13f39;
}

.tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.tabs button {
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid var(--line);
  background: #fff;
  color: #263740;
  font-size: 12px;
}

.tabs button.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

.excel-wrap,
.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid #bfcbd1;
}

.preview-panel .excel-wrap {
  max-height: calc(100vh - 245px);
}

.preview-adjust-bar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  margin: -4px 0 10px;
  color: var(--muted);
  font-size: 12px;
}

.preview-adjust-bar span {
  flex: 1;
  min-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.excel-table {
  border-collapse: collapse;
  min-width: 100%;
  width: max-content;
  background: #fff;
  font-family: "Times New Roman", "SimSun", serif;
  font-size: 14px;
  table-layout: auto;
}

.excel-table th,
.excel-table td {
  border: 1px solid #333;
  min-height: 28px;
  padding: 3px 5px;
  text-align: center;
  vertical-align: middle;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.18;
  min-width: 72px;
}

.excel-table th:nth-child(1),
.excel-table td:nth-child(1),
.excel-table th:nth-child(2),
.excel-table td:nth-child(2) {
  min-width: 92px;
}

.excel-table th:nth-child(3),
.excel-table td:nth-child(3),
.excel-table th:nth-child(4),
.excel-table td:nth-child(4) {
  min-width: 74px;
}

.excel-table th:nth-child(5),
.excel-table td:nth-child(5),
.excel-table th:nth-child(10),
.excel-table td:nth-child(10) {
  min-width: 86px;
}

.excel-table th:nth-child(6),
.excel-table td:nth-child(6) {
  min-width: 138px;
  max-width: 230px;
}

.excel-table th:nth-child(7),
.excel-table td:nth-child(7) {
  min-width: 128px;
  max-width: 220px;
}

.excel-table th:nth-child(8),
.excel-table td:nth-child(8),
.excel-table th:nth-child(9),
.excel-table td:nth-child(9) {
  min-width: 78px;
}

.excel-table th {
  font-weight: 700;
}

.excel-table .yellow th,
.excel-table tr.yellow th {
  background: var(--yellow);
}

.excel-table .total td {
  font-weight: 700;
  background: #fafafa;
}

.excel-table tr.row-highlight td {
  background: #fff7a8;
  box-shadow: inset 0 2px 0 #d88300, inset 0 -2px 0 #d88300;
}

.excel-table tr.row-highlight td:first-child {
  box-shadow: inset 2px 0 0 #d88300, inset 0 2px 0 #d88300, inset 0 -2px 0 #d88300;
}

.excel-table tr.row-highlight td:last-child {
  box-shadow: inset -2px 0 0 #d88300, inset 0 2px 0 #d88300, inset 0 -2px 0 #d88300;
}

.excel-table tr.draggable-tail-row {
  cursor: grab;
}

.excel-table tr.draggable-tail-row.dragging {
  cursor: grabbing;
}

.excel-table tr.draggable-tail-row:hover td {
  background: #fffdf0;
}

.excel-table tr.dragging td {
  opacity: .65;
  background: #fff7a8;
}

.excel-table tr.drop-allowed td {
  background: #e8f7ee !important;
  box-shadow: inset 0 2px 0 #24724b, inset 0 -2px 0 #24724b;
}

.excel-table tr.drop-blocked td {
  background: #fff5f4 !important;
  box-shadow: inset 0 2px 0 #c94842, inset 0 -2px 0 #c94842;
}

.preview-drag-ghost {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  max-width: 260px;
  border: 1px solid #1f6f78;
  border-radius: 6px;
  background: #ffffff;
  color: #1b2830;
  box-shadow: 0 10px 28px rgba(16, 40, 54, .22);
  padding: 8px 10px;
  font-size: 13px;
  font-weight: 800;
  white-space: nowrap;
}

.preview-confirm-backdrop {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 18, 24, .42);
}

.preview-confirm-dialog {
  position: relative;
  width: min(520px, calc(100vw - 48px));
  border: 1px solid #b8ccd6;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(12, 30, 40, .28);
  padding: 24px;
}

.move-confirm-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.move-confirm-grid div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7fafb;
  padding: 10px;
}

.move-confirm-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.move-confirm-grid b {
  display: block;
  overflow-wrap: anywhere;
}

.preview-confirm-actions {
  grid-template-columns: 1fr auto auto;
}

.excel-table .editable-cell {
  cursor: text;
}

.excel-table .editable-cell:focus {
  outline: 2px solid #d88300;
  outline-offset: -2px;
  background: #fff7a8;
}

.excel-table .empty {
  height: 180px;
  color: var(--muted);
  font-family: "Microsoft YaHei", Arial, sans-serif;
  border-color: #d8e0e4;
}

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

.data-table th,
.data-table td {
  border-bottom: 1px solid #e2e8eb;
  padding: 10px;
  text-align: left;
  white-space: nowrap;
}

.data-table th {
  background: #f3f7f8;
  font-size: 13px;
  color: #4d606a;
}

.data-table .empty {
  text-align: center;
  color: var(--muted);
  padding: 36px;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 14px;
}

.kpi-row div {
  background: var(--soft);
  border: 1px solid #e0e8ec;
  border-radius: 6px;
  padding: 10px;
}

.kpi-row b {
  display: block;
  font-size: 22px;
}

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

.download-link {
  display: block;
  margin-top: 12px;
  text-align: center;
  border: 1px solid var(--teal);
  border-radius: 6px;
  padding: 10px;
}

.hidden-link {
  display: none;
}

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

.finding {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid #e0e8ec;
  border-left: 4px solid var(--warn);
  border-radius: 6px;
  padding: 10px;
  background: #fffaf0;
  min-width: 0;
}

.finding > div {
  min-width: 0;
}

.finding b {
  display: block;
  font-size: 15px;
  line-height: 1.25;
}

.finding.locatable {
  cursor: pointer;
}

.finding.locatable:hover {
  border-color: #d5a15c;
  background: #fff5df;
}

.finding p {
  color: #5f6f78;
  font-size: 12px;
  margin-top: 4px;
  line-height: 1.45;
  white-space: normal;
  overflow-wrap: anywhere;
}

.finding button,
.finding .badge {
  flex: 0 0 auto;
}

.finding.ok {
  border-left-color: var(--ok);
  background: #f2fbf6;
}

.finding.error {
  border-left-color: var(--danger);
  background: #fff5f4;
}

.finding-card.actionable {
  cursor: pointer;
  border-color: #d5a15c;
  background: #fff8e8;
  transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease;
}

.finding-card.actionable:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px rgba(123, 85, 32, .12);
}

.finding-card.actionable small {
  display: inline-block;
  margin-top: 8px;
  color: var(--teal-dark);
  font-size: 12px;
  font-weight: 800;
}

.gap-on-color-match-modal {
  width: min(820px, calc(100vw - 48px));
}

.color-match-table-wrap {
  margin-top: 18px;
}

.color-match-table select,
.color-match-table input {
  width: 100%;
  min-width: 160px;
}

.matrix-layout {
  display: block;
}

.rule-editor-layout {
  display: grid;
  gap: 14px;
}

.rule-template-bar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid #dfe6ef;
  border-radius: 10px;
  background: #fbfcff;
}

.rule-template-select {
  flex: 1;
  min-width: 280px;
}

.rule-save-status {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 118px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid #d7e0ea;
  background: #f7fafc;
  color: #44515c;
  font-size: 13px;
  font-weight: 900;
  white-space: nowrap;
}

.rule-save-status::before {
  content: "";
  width: 9px;
  height: 9px;
  margin-right: 8px;
  border-radius: 999px;
  background: currentColor;
}

.rule-save-status.is-loaded {
  border-color: #c9d8ea;
  background: #f3f7fb;
  color: #496275;
}

.rule-save-status.is-dirty {
  border-color: #f3c978;
  background: #fff8e8;
  color: #94620e;
}

.rule-save-status.is-saving {
  border-color: #8fb9ff;
  background: #eef6ff;
  color: #0b63de;
}

.rule-save-status.is-saved {
  border-color: #83d2a4;
  background: #effaf3;
  color: #24724b;
}

.rule-matrix-stage {
  display: block;
}

.rule-current-scope-panel,
.matrix-inspector-panel {
  border: 1px solid #dfe5ec;
  border-radius: 10px;
  background: #fbfcff;
  padding: 12px;
  box-shadow: 0 1px 0 rgba(23, 32, 42, .02);
}

.compact-title {
  margin-bottom: 12px;
  align-items: center;
}

.compact-title h3 {
  margin: 0;
  font-size: 15px;
}

.rule-structure-list {
  display: grid;
  gap: 8px;
}

.rule-structure-list button {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid #dde5ed;
  border-radius: 8px;
  background: #fff;
  padding: 10px 11px;
  color: #25313b;
  text-align: left;
  cursor: pointer;
}

.rule-structure-list button.active {
  border-color: #7bb2ff;
  background: #eef6ff;
  box-shadow: inset 0 0 0 1px #b8d6ff;
}

.rule-structure-list span {
  font-weight: 800;
}

.rule-structure-list b {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.rule-template-field {
  min-width: 320px;
}

.matrix-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: end;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.rule-scope-toolbar {
  justify-content: flex-start;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
}

.category-tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(120px, 1fr));
  gap: 0;
  flex: 1 1 100%;
  max-width: 820px;
  border: 1px solid #d6e0ea;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.category-tabs button {
  min-height: 38px;
  border: 0;
  border-right: 1px solid #d6e0ea;
  background: #fff;
  color: #25313b;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.category-tabs button:last-child {
  border-right: 0;
}

.category-tabs button.active {
  background: #edf5ff;
  color: #0b63de;
  box-shadow: inset 0 0 0 2px #2c77ff;
}

.field.compact {
  margin-bottom: 0;
}

.carton-pool {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  flex-wrap: wrap;
  justify-content: flex-end;
}

.style-actions,
.size-toolbar {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.size-toolbar {
  margin-bottom: 12px;
  padding: 10px;
  border: 1px solid #dfe7ef;
  border-radius: 10px;
  background: #fbfcff;
}

.size-toolbar .field {
  min-width: 160px;
}

.size-toolbar .carton-dimension-field {
  min-width: 74px;
}

.carton-dimension-field input,
.carton-weight-field input {
  width: 74px;
}

.carton-weight-field {
  min-width: 74px;
}

.custom-carton-controls {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
  margin-left: auto;
}

.custom-carton-controls[hidden] {
  display: none !important;
}

.dimension-times {
  align-self: center;
  color: var(--muted);
  font-size: 18px;
  font-weight: 900;
  padding-top: 18px;
}

.matrix-undo-btn {
  min-height: 42px;
  padding: 0 22px;
  border: 1px solid #b8c7d8;
  border-radius: 10px;
  background: #fff;
  color: #1f3448;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(23, 32, 42, .06);
}

.matrix-undo-btn:not(:disabled):hover {
  border-color: #6fa8ff;
  background: #eef6ff;
  color: #0b63de;
}

.matrix-undo-btn:disabled {
  cursor: not-allowed;
  opacity: .45;
}

.rule-name-field {
  min-width: 260px;
}

.style-field {
  min-width: 220px;
}

.matrix-context {
  margin-bottom: 10px;
  padding: 9px 11px;
  border: 1px solid #dfe7ef;
  border-radius: 10px;
  background: #fbfcff;
  color: #44515c;
  font-size: 13px;
  font-weight: 700;
}

.size-note {
  color: var(--muted);
  font-size: 12px;
  align-self: center;
}

.carton-pool b {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 11px;
  background: #f7fafb;
  color: #20313a;
}

.matrix-scroll {
  width: 100%;
  overflow: auto;
  border: 1px solid #d9e1ea;
  border-radius: 10px;
  background: #fff;
}

.rule-matrix {
  width: 100%;
  min-width: 760px;
  border-collapse: collapse;
  background: #fff;
  table-layout: fixed;
}

.rule-matrix th,
.rule-matrix td {
  border: 1px solid #d8e0e8;
  height: 58px;
  padding: 6px;
  text-align: center;
  vertical-align: middle;
}

.rule-matrix thead th {
  height: 42px;
  background: #f4f7fb;
  font-weight: 800;
}

.rule-matrix thead th span {
  display: block;
  color: #d14343;
  font-size: 13px;
  line-height: 1.25;
  white-space: normal;
}

.rule-matrix .mixed-tail-input {
  width: min(120px, 100%);
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 8px;
  text-align: center;
  font: inherit;
  font-weight: 700;
}

.rule-matrix .switch-cell {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

.rule-matrix .mixed-tail-note {
  caption-side: bottom;
  padding: 10px;
  text-align: left;
  color: var(--muted);
  background: #f7fafb;
  border: 1px solid #333;
  border-top: 0;
}

.rule-matrix tr.priority-mixed-carton td,
.rule-matrix tr.priority-mixed-carton th {
  background: #f4fbf7;
}

.preview-table tr.mixed-tail-row td,
.data-table tr.mixed-tail-row td,
.excel-table tr.mixed-tail-row td {
  background: #d9d9d9;
}

.matrix-cell {
  cursor: pointer;
}

.matrix-cell b,
.matrix-cell span {
  display: block;
}

.matrix-cell.configured b {
  color: #1b2830;
}

.matrix-cell.configured span {
  margin-top: 3px;
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
}

.matrix-cell.empty {
  color: #7a8a92;
}

.matrix-cell:hover,
.matrix-cell.active {
  background: #eaf4ff;
  box-shadow: inset 0 0 0 2px #63a7f7;
}

.compact-settings {
  grid-template-columns: 1fr;
  gap: 8px;
}

.compact-settings div {
  padding: 9px 10px;
  border-radius: 8px;
}

.status-ok {
  color: #24724b;
  font-weight: 800;
}

.status-warn {
  color: #c94842;
  font-weight: 800;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 18, 24, .42);
}

.modal-backdrop[hidden] {
  display: none;
}

.rule-modal {
  position: relative;
  width: min(720px, calc(100vw - 48px));
  max-height: calc(100vh - 48px);
  overflow: auto;
  border: 1px solid #b8ccd6;
  border-radius: 12px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(12, 30, 40, .28);
  padding: 26px 28px 24px;
}

.production-save-modal {
  width: min(520px, calc(100vw - 48px));
}

.complete-order-add-modal {
  width: min(1040px, calc(100vw - 48px));
}

.complete-order-select-modal {
  width: min(1280px, calc(100vw - 48px));
}

.complete-order-select-tools {
  grid-template-columns: minmax(280px, 1fr) auto;
  align-items: end;
  gap: 14px 18px;
  margin-top: 18px;
}

.complete-order-select-table-wrap {
  max-height: min(58vh, 560px);
  overflow: auto;
  margin-top: 12px;
}

.complete-order-add-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 18px;
  margin-top: 18px;
}

.complete-order-size-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.complete-order-size-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #dbe6eb;
  color: var(--ink);
  font-weight: 700;
}

.complete-order-size-entry {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 8px;
  align-items: end;
}

.complete-order-size-entry .field {
  min-width: 0;
  margin: 0;
}

.complete-order-size-entry input {
  text-align: center;
}

.production-save-modal .field {
  margin-top: 18px;
}

.production-save-actions {
  grid-template-columns: 1fr auto auto;
}

.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: 50%;
  background: transparent;
  color: #607582;
  font-size: 28px;
  line-height: 1;
}

.modal-close:hover {
  background: #edf4f6;
}

.modal-head h2 {
  font-size: 22px;
  margin-right: 44px;
}

.modal-head p {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 16px 0 18px;
}

.modal-tags span,
.quick-fill button {
  border: 1px solid #8bc9d5;
  border-radius: 999px;
  background: #eef9fb;
  color: var(--teal-dark);
  padding: 7px 14px;
  font-weight: 700;
  font-size: 13px;
}

.modal-form {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px 22px;
}

.modal-form .wide {
  grid-column: span 2;
}

.multi-mix-editor {
  border: 1px solid #dbe6eb;
  border-radius: 10px;
  background: #f7fafb;
  padding: 16px;
}

.mix-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.mix-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.quick-fill {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 22px;
}

.quick-fill span {
  flex: 0 0 100%;
  color: var(--muted);
  font-size: 13px;
}

.quick-fill button {
  min-height: 34px;
  background: #fff;
  color: #25343d;
}

.modal-preview {
  margin-top: 20px;
  border: 1px solid #dbe6eb;
  border-radius: 8px;
  background: #f7fafb;
  padding: 14px 16px;
}

.modal-preview b {
  display: block;
  margin-bottom: 8px;
}

.modal-preview p {
  color: #5f7482;
  font-size: 13px;
  line-height: 1.6;
}

.modal-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
}

.danger {
  border: 1px solid #e5afaa;
  background: #fff5f4;
  color: #b13f39;
}

.cell-editor {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #fbfdfe;
}

.panel-title.tight {
  margin-bottom: 8px;
}

.cell-title {
  color: var(--teal);
  font-weight: 800;
  margin-bottom: 14px;
}

.editor-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 12px;
}

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

.settings-grid div {
  background: var(--soft);
  border: 1px solid #e0e8ec;
  border-radius: 6px;
  padding: 12px;
  min-width: 0;
}

.settings-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 5px;
}

.settings-grid b {
  display: block;
  overflow-wrap: anywhere;
}

.output-dir-hub {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.output-dir-hub button {
  display: grid;
  gap: 6px;
  min-height: 92px;
  height: auto;
  justify-items: start;
  align-content: center;
  padding: 14px;
  border-radius: 12px;
  text-align: left;
}

.output-dir-hub button b {
  color: var(--text);
  font-size: 15px;
}

.output-dir-hub button span {
  margin: 0;
  line-height: 1.45;
  white-space: normal;
}

.ai-settings-form {
  margin-top: 16px;
  display: grid;
  gap: 14px;
}

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

.check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 14px;
  background: var(--soft);
  border: 1px solid #e0e8ec;
  border-radius: 6px;
  padding: 12px;
}

.check-grid label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 28px;
  color: #263740;
}

.ai-actions {
  max-width: 420px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(18px);
  background: #1f2d35;
  color: #fff;
  border-radius: 6px;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: .18s ease;
  z-index: 10;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 1050px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 3;
    padding: 10px;
  }
  .brand {
    display: none;
  }
  .nav {
    display: flex;
    overflow-x: auto;
  }
  .nav button {
    width: auto;
    white-space: nowrap;
    min-height: 34px;
  }
  .topbar {
    display: grid;
  }
  .top-actions {
    justify-content: flex-start;
    flex-wrap: wrap;
  }
  h1 {
    white-space: normal;
  }
  .summary-strip {
    grid-template-columns: repeat(3, minmax(120px, 1fr));
  }
  .work-grid {
    grid-template-columns: 1fr;
  }
  .production-topbar {
    display: grid;
  }
  .production-summary,
  .production-work-grid,
  .production-rule-toolbar,
  .mix-size-toolbar,
  .production-rule-layout,
  .production-field-grid,
  .usage-layout,
  .settings-grid.single {
    grid-template-columns: 1fr;
  }
  .preview-panel,
  .summary-panel,
  .ai-panel,
  .cartons-panel {
    grid-column: auto;
    grid-row: auto;
  }
  .settings-grid {
    grid-template-columns: 1fr;
  }
  .output-dir-hub {
    grid-template-columns: 1fr;
  }
  #page-gap-on-carton-labels .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }
  #page-gap-on-carton-labels .top-actions .primary {
    grid-column: 1 / -1;
  }
  .form-row,
  .check-grid {
    grid-template-columns: 1fr;
  }
  .matrix-layout {
    grid-template-columns: 1fr;
  }
  .matrix-toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .size-toolbar,
  .style-actions {
    align-items: stretch;
    flex-direction: column;
  }
  .carton-pool {
    justify-content: flex-start;
  }
}

#page-production-output .production-summary {
  grid-template-columns: repeat(5, minmax(96px, 1fr)) auto;
  align-items: center;
}

#page-special-production-output .production-summary {
  grid-template-columns: repeat(6, minmax(96px, 1fr)) auto;
  align-items: center;
}

#page-fuli-production-output .production-summary {
  grid-template-columns: repeat(4, minmax(160px, 230px));
}

#page-production-output .production-summary .summary-action-btn,
#page-special-production-output .production-summary .summary-action-btn,
#page-gap-on-carton-labels .carton-label-summary .summary-action-btn {
  justify-self: end;
  align-self: center;
  margin-left: 0;
}

@media (max-width: 520px) {
  #page-gap-on-carton-labels.carton-label-summary,
  #page-gap-on-carton-labels .carton-label-summary {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 12px;
  }
  h1 {
    font-size: 21px;
  }
  .steps {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .top-actions button {
    flex: 1 1 42%;
  }
  .editor-actions {
    grid-template-columns: 1fr;
  }
}

/* Apple-inspired workstation refresh. Keeps existing IDs and behavior intact. */
:root {
  --bg: #f5f7fb;
  --panel: rgba(255, 255, 255, .82);
  --text: #17202a;
  --muted: #687385;
  --line: rgba(25, 38, 58, .1);
  --sidebar: rgba(255, 255, 255, .72);
  --teal: #1479ff;
  --teal-dark: #0067e6;
  --soft: rgba(255, 255, 255, .62);
  --danger: #d94c45;
  --warn: #b46a10;
  --ok: #248a52;
  --shadow-sm: 0 1px 2px rgba(22, 32, 45, .06), 0 10px 30px rgba(22, 32, 45, .05);
  --shadow-md: 0 18px 45px rgba(22, 32, 45, .1);
  --radius: 14px;
}

body {
  background:
    radial-gradient(circle at 8% 0%, rgba(20, 121, 255, .08), transparent 30%),
    linear-gradient(135deg, #f8fafc 0%, #eef2f7 46%, #f7f8fb 100%);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255, 255, 255, .36) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, .34) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, .7), transparent 70%);
}

button {
  border-radius: 999px;
  min-height: 36px;
  padding: 0 16px;
  font-weight: 700;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

input,
select,
textarea {
  border-color: rgba(25, 38, 58, .12);
  border-radius: 10px;
  background: rgba(255, 255, 255, .78);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .72);
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(20, 121, 255, .58);
  outline: none;
  box-shadow: 0 0 0 4px rgba(20, 121, 255, .12);
}

.app-shell {
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  background: var(--sidebar);
  color: var(--text);
  border-right: 1px solid rgba(255, 255, 255, .66);
  box-shadow: 10px 0 35px rgba(22, 32, 45, .05);
  backdrop-filter: blur(28px) saturate(1.4);
  -webkit-backdrop-filter: blur(28px) saturate(1.4);
  padding: 22px 14px;
}

.brand {
  position: relative;
  border-bottom: 0;
  padding: 12px 12px 18px 56px;
  margin-bottom: 18px;
}

.brand::before {
  content: "RL";
  position: absolute;
  left: 10px;
  top: 10px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  background: linear-gradient(145deg, #1a83ff, #0f5bd8);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  box-shadow: 0 10px 24px rgba(20, 121, 255, .28);
}

.brand b {
  color: #111827;
  font-size: 17px;
  line-height: 1.25;
}

.brand span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.nav {
  gap: 8px;
}

.nav-group {
  gap: 4px;
}

.nav-title {
  color: #2e3948;
  font-size: 13px;
  font-weight: 800;
  min-height: 36px;
  padding: 7px 10px;
}

.nav-title:hover,
.nav-title:focus-visible {
  background: rgba(20, 121, 255, .08);
}

.nav-title::after {
  color: #8b98a9;
}

.nav button {
  color: #697588;
  border-radius: 10px;
  min-height: 34px;
  padding-left: 18px;
  font-size: 13px;
  font-weight: 650;
}

.nav button.active,
.nav button:hover {
  background: rgba(20, 121, 255, .1);
  color: #0f5bd8;
  box-shadow: inset 0 0 0 1px rgba(20, 121, 255, .08);
}

.nav button.nav-direct {
  color: #2e3948;
  font-size: 13px;
  font-weight: 800;
  min-height: 36px;
  padding: 7px 10px;
  border-radius: 10px;
}

.nav button.nav-direct.active,
.nav button.nav-direct:hover {
  background: rgba(20, 121, 255, .1);
  color: #0f5bd8;
  box-shadow: inset 0 0 0 1px rgba(20, 121, 255, .08);
}

.main {
  position: relative;
  min-height: 100vh;
  padding: 26px 28px 34px;
}

.topbar,
.production-topbar {
  align-items: center;
  padding: 18px;
  margin-bottom: 16px;
  border: 1px solid rgba(255, 255, 255, .74);
  border-radius: 18px;
  background: rgba(255, 255, 255, .68);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(24px) saturate(1.35);
  -webkit-backdrop-filter: blur(24px) saturate(1.35);
}

h1 {
  font-size: 26px;
  font-weight: 780;
  color: #101828;
}

h2 {
  color: #1d2939;
  font-size: 15px;
  font-weight: 780;
}

.topbar p,
.production-topbar p {
  color: #667085;
  font-size: 13px;
}

.top-actions {
  align-items: center;
  gap: 9px;
}

.summary-module-filter {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #475467;
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.summary-module-filter select {
  width: 132px;
  min-height: 36px;
  padding: 5px 28px 5px 9px;
  border-radius: 6px;
  background: #fff;
}

#page-production-output .top-actions {
  flex-wrap: wrap;
  max-width: 520px;
}

#page-production-output .summary-action-btn,
#page-special-production-output .summary-action-btn,
#page-gap-on-carton-labels .summary-action-btn {
  margin-left: auto;
  min-height: 38px;
  white-space: nowrap;
}

#page-production-output .production-summary {
  grid-template-columns: repeat(5, minmax(96px, 1fr)) auto;
  align-items: center;
}

#page-special-production-output .production-summary {
  grid-template-columns: repeat(6, minmax(96px, 1fr)) auto;
  align-items: center;
}

#page-production-output .production-summary .summary-action-btn,
#page-special-production-output .production-summary .summary-action-btn,
#page-gap-on-carton-labels .carton-label-summary .summary-action-btn {
  justify-self: end;
  align-self: center;
}

.quick-search {
  width: 190px;
  display: flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 0 12px;
  border: 1px solid rgba(25, 38, 58, .1);
  border-radius: 999px;
  background: rgba(255, 255, 255, .72);
  color: #8a96a8;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .8);
}

.quick-search span {
  font-size: 12px;
  font-weight: 700;
}

.quick-search input {
  min-height: 30px;
  border: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  font-size: 13px;
}

.quick-search input:focus {
  box-shadow: none;
}

.primary {
  background: linear-gradient(180deg, #2589ff, #0f6eea);
  color: #fff;
  box-shadow: 0 10px 22px rgba(20, 121, 255, .22);
}

.primary:hover {
  background: linear-gradient(180deg, #1479ff, #005ed8);
}

.secondary {
  background: rgba(20, 121, 255, .1);
  color: #0f5bd8;
  border: 1px solid rgba(20, 121, 255, .13);
}

.ghost {
  background: rgba(255, 255, 255, .62);
  color: #344054;
  border: 1px solid rgba(25, 38, 58, .1);
}

.ghost:hover,
.secondary:hover {
  box-shadow: 0 8px 18px rgba(22, 32, 45, .08);
}

.summary-strip {
  grid-template-columns: repeat(9, minmax(96px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.summary-strip span {
  height: 64px;
  border: 1px solid rgba(255, 255, 255, .72);
  border-radius: 14px;
  background: rgba(255, 255, 255, .68);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

.summary-strip span.warn {
  background: rgba(255, 248, 230, .82);
  border-color: rgba(230, 170, 70, .26);
}

.summary-strip em {
  color: #7a8596;
  font-size: 12px;
}

.summary-strip b {
  color: #101828;
  font-size: 19px;
  font-weight: 790;
}

.work-grid {
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  gap: 16px;
}

.production-work-grid {
  grid-template-columns: 330px minmax(280px, .58fr) minmax(520px, 1fr);
}

.carton-label-work-grid {
  grid-template-columns: 330px minmax(280px, .5fr) minmax(560px, 1fr);
}

.panel {
  border: 1px solid rgba(255, 255, 255, .76);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(22px) saturate(1.25);
  -webkit-backdrop-filter: blur(22px) saturate(1.25);
  padding: 16px;
}

.preview-panel {
  box-shadow: var(--shadow-md);
}

.panel-title {
  margin-bottom: 14px;
}

.field {
  color: #667085;
  font-size: 12px;
  font-weight: 700;
}

.meta-list,
.compact-note,
.rule-note {
  color: #697588;
}

.meta-list span,
.buyer-review-summary span,
.kpi-row div,
.special-image-upload,
.buyer-review-reason {
  border-color: rgba(25, 38, 58, .08);
  border-radius: 12px;
  background: rgba(248, 250, 252, .76);
}

.badge {
  min-height: 25px;
  background: rgba(20, 121, 255, .1);
  color: #0f5bd8;
  font-weight: 760;
}

.badge.ai-online {
  background: rgba(36, 138, 82, .12);
  color: #197342;
}

.badge.ai-offline {
  background: rgba(217, 76, 69, .11);
  color: #b7342d;
}

.tabs button {
  border-radius: 999px;
}

.data-table,
.excel-table,
.production-preview-table {
  overflow: hidden;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, .86);
}

.data-table th,
.data-table td {
  border-bottom: 1px solid rgba(25, 38, 58, .08);
  padding: 10px 12px;
}

.data-table th {
  background: rgba(244, 247, 251, .92);
  color: #667085;
  font-size: 12px;
  font-weight: 800;
}

.excel-table .empty,
.data-table .empty {
  background: rgba(248, 250, 252, .68);
}

.toast {
  border-radius: 999px;
  background: rgba(17, 24, 39, .88);
  box-shadow: 0 18px 40px rgba(17, 24, 39, .24);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
}

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

  .sidebar {
    height: auto;
    background: rgba(255, 255, 255, .86);
  }

  .quick-search {
    width: 100%;
  }
}

@media (max-width: 720px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .production-topbar {
    padding: 14px;
  }

  .summary-strip {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .quick-search,
  .top-actions .primary {
    grid-column: 1 / -1;
  }

  .top-actions button {
    width: 100%;
    min-width: 0;
    padding-inline: 10px;
    white-space: normal;
  }
}

#page-gap-on-production-output .production-work-grid {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  align-items: stretch;
}

#page-gap-on-production-output .ai-panel {
  grid-column: 2;
  grid-row: 1;
}

#page-gap-on-carton-labels .carton-label-summary {
  grid-template-columns: repeat(7, minmax(78px, 1fr)) auto;
  align-items: center;
}

#page-gap-on-carton-labels .carton-label-summary .summary-action-btn {
  grid-column: 8;
  justify-self: end;
  align-self: center;
  width: max-content;
  margin-left: 0;
}

#page-gap-on-carton-labels .carton-label-summary .summary-action-group {
  grid-column: 8;
  justify-self: end;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

#page-gap-on-carton-labels .carton-label-summary .summary-action-group .summary-action-btn {
  margin-left: 0;
  min-height: 38px;
  width: max-content;
}

.gap-on-white-envelope-preview-modal {
  width: min(1180px, calc(100vw - 48px));
}

.white-envelope-preview-tabs {
  margin: 14px 0 10px;
}

.white-envelope-preview-table-wrap {
  max-height: min(62vh, 680px);
}

@media (max-width: 1180px) {
  #page-gap-on-carton-labels .carton-label-summary {
    grid-template-columns: repeat(4, minmax(110px, 1fr));
  }

  #page-gap-on-carton-labels .carton-label-summary .summary-action-btn {
    grid-column: 1 / -1;
    justify-self: end;
  }

  #page-gap-on-carton-labels .carton-label-summary .summary-action-group {
    grid-column: 1 / -1;
    justify-self: end;
  }
}

@media (max-width: 720px) {
  #page-gap-on-carton-labels .carton-label-summary {
    grid-template-columns: repeat(2, minmax(120px, 1fr));
  }
}

#page-gap-on-production-output .preview-panel {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  min-height: calc(100vh - 360px);
  flex-direction: column;
}

#page-gap-on-production-output .preview-panel .excel-wrap {
  flex: 1;
  max-height: none;
  min-height: 520px;
}

#gapOnProductionPreviewTable {
  width: 100%;
}

#gapOnProductionPreviewTable th,
#gapOnProductionPreviewTable td {
  min-width: 64px;
  padding: 2px 4px;
  font-size: 13px;
  line-height: 1.12;
}

#gapOnProductionPreviewTable th:nth-child(1),
#gapOnProductionPreviewTable td:nth-child(1),
#gapOnProductionPreviewTable th:nth-child(2),
#gapOnProductionPreviewTable td:nth-child(2) {
  min-width: 76px;
}

#gapOnProductionPreviewTable th:last-child,
#gapOnProductionPreviewTable td:last-child {
  min-width: 86px;
}

@media (max-width: 1050px) {
  #page-gap-on-production-output .production-work-grid,
  #page-gap-on-production-output .ai-panel,
  #page-gap-on-production-output .preview-panel {
    grid-column: auto;
    grid-row: auto;
  }
}

#page-workbench .work-grid,
#page-gap-on-carton-labels .carton-label-work-grid,
#page-gap-on-production-output .production-work-grid,
#page-production-output .production-work-grid,
#page-fuli-production-output .production-work-grid,
#page-special-production-output .production-work-grid {
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  align-items: stretch;
}

#page-workbench .ai-panel,
#page-gap-on-carton-labels .ai-panel,
#page-gap-on-production-output .ai-panel,
#page-production-output .ai-panel,
#page-fuli-production-output .ai-panel,
#page-special-production-output .ai-panel {
  grid-column: 2;
  grid-row: 1;
}

#page-workbench .preview-panel,
#page-gap-on-carton-labels .preview-panel,
#page-gap-on-production-output .preview-panel,
#page-production-output .preview-panel,
#page-fuli-production-output .preview-panel,
#page-special-production-output .preview-panel {
  grid-column: 1 / -1;
  grid-row: 2;
  display: flex;
  min-height: calc(100vh - 360px);
  flex-direction: column;
}

#page-workbench .preview-panel .excel-wrap,
#page-gap-on-carton-labels .preview-panel .excel-wrap,
#page-gap-on-production-output .preview-panel .excel-wrap,
#page-production-output .preview-panel .excel-wrap,
#page-fuli-production-output .preview-panel .excel-wrap,
#page-special-production-output .preview-panel .excel-wrap {
  flex: 1;
  max-height: none;
  min-height: 520px;
}

#fuliProductionPreviewTable {
  width: 100%;
}

#page-special-production-output .special-buyer-review-panel {
  grid-column: 1 / -1;
  grid-row: 3;
}

#page-complete-order-summary .production-work-grid {
  grid-template-columns: minmax(280px, 330px) minmax(0, 1fr);
  align-items: stretch;
}

#page-complete-order-summary #completeOrderManualPanel {
  grid-column: 1;
  grid-row: 1;
}

#page-complete-order-summary .ai-panel {
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}

#page-complete-order-summary .ai-panel .table-wrap {
  min-height: 420px;
  max-height: 540px;
  overflow: auto;
}

#page-complete-order-summary #completeOrderBatchTable {
  min-width: 920px;
}

#previewTable,
#gapOnLabelPreviewTable,
#gapOnProductionPreviewTable,
#productionPreviewTable,
#specialProductionPreviewTable,
#specialBuyerReviewTable {
  width: 100%;
}

#previewTable th,
#previewTable td,
#gapOnLabelPreviewTable th,
#gapOnLabelPreviewTable td,
#gapOnProductionPreviewTable th,
#gapOnProductionPreviewTable td,
#productionPreviewTable th,
#productionPreviewTable td,
#specialProductionPreviewTable th,
#specialProductionPreviewTable td,
#specialBuyerReviewTable th,
#specialBuyerReviewTable td {
  min-width: 64px;
  padding: 2px 4px;
  font-size: 13px;
  line-height: 1.12;
}

@media (max-width: 1050px) {
  #page-workbench .work-grid,
  #page-gap-on-carton-labels .carton-label-work-grid,
  #page-gap-on-production-output .production-work-grid,
  #page-production-output .production-work-grid,
  #page-fuli-production-output .production-work-grid,
  #page-special-production-output .production-work-grid {
    grid-template-columns: 1fr;
  }

  #page-workbench .ai-panel,
  #page-workbench .preview-panel,
  #page-gap-on-carton-labels .ai-panel,
  #page-gap-on-carton-labels .preview-panel,
  #page-gap-on-production-output .ai-panel,
  #page-gap-on-production-output .preview-panel,
  #page-production-output .ai-panel,
  #page-production-output .preview-panel,
  #page-fuli-production-output .ai-panel,
  #page-fuli-production-output .preview-panel,
  #page-special-production-output .ai-panel,
  #page-special-production-output .preview-panel,
  #page-special-production-output .special-buyer-review-panel {
    grid-column: auto;
    grid-row: auto;
  }

  #page-complete-order-summary .production-work-grid {
    grid-template-columns: 1fr;
  }

#page-complete-order-summary #completeOrderManualPanel,
#page-complete-order-summary .ai-panel {
    grid-column: auto;
    grid-row: auto;
  }
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf2f6;
}

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

.auth-card {
  padding: 42px;
  border: 1px solid #d8e1e7;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 18px 48px rgba(37, 58, 71, .12);
}

.auth-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  margin-bottom: 20px;
  border-radius: 8px;
  background: #1677e8;
  color: #fff;
  font-size: 18px;
  font-weight: 900;
}

.auth-eyebrow {
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-card h1 {
  margin: 0;
  font-size: 26px;
}

.auth-subtitle,
.auth-hint {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.55;
}

.auth-form {
  display: grid;
  gap: 14px;
  margin-top: 28px;
}

.auth-form label {
  display: grid;
  gap: 7px;
  color: #41515b;
  font-size: 14px;
  font-weight: 700;
}

.auth-form .primary {
  margin-top: 6px;
}

.auth-error {
  margin: 0;
  padding: 9px 10px;
  border: 1px solid #f2c7c2;
  border-radius: 6px;
  background: #fff4f2;
  color: #a73d34;
  font-size: 14px;
  line-height: 1.45;
}

.auth-admin-section {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.auth-user-create-grid {
  grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.auth-user-create-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.auth-user-table-wrap {
  margin-top: 14px;
}

.auth-user-table {
  min-width: 820px;
}

.auth-user-table input,
.auth-user-table select {
  min-width: 110px;
}

.auth-user-table .small {
  min-height: 32px;
}

.role-viewer .main .page button:not(.nav-title),
.role-viewer .main .page input,
.role-viewer .main .page select,
.role-viewer .main .page textarea {
  pointer-events: none;
  opacity: .58;
}

.role-viewer .main .page .tabs button,
.role-viewer .main .page [data-page-jump],
.role-viewer .main .page .download-link {
  pointer-events: auto;
  opacity: 1;
}

@media (max-width: 720px) {
  .auth-page {
    padding: 16px;
  }

  .auth-card {
    padding: 30px 24px;
  }

  .auth-user-create-grid {
    grid-template-columns: 1fr;
  }
}
