* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: #f6f7f8;
  color: #222;
  font-family: Arial, "Microsoft YaHei", sans-serif;
  font-size: 14px;
}

a {
  color: #1463d9;
  text-decoration: none;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  padding: 0 28px;
  background: #111827;
  color: #fff;
}

.brand,
.topbar a {
  color: #fff;
}

.topbar nav {
  display: flex;
  gap: 18px;
}

.page {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.toolbar,
.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.filters,
.status-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

input,
select,
textarea,
button,
.button {
  border: 1px solid #d4d7dd;
  border-radius: 6px;
  background: #fff;
  color: #222;
  font: inherit;
  padding: 9px 11px;
}

.filters input[name="search"] {
  width: 220px;
}

.filters select {
  width: 160px;
}

button,
.button {
  cursor: pointer;
  background: #fff;
}

.primary,
button.primary {
  border-color: #166534;
  background: #166534;
  color: #fff;
}

.ghost {
  color: #374151;
}

.table-wrap,
.panel {
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  background: #fff;
  overflow: hidden;
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid #edf0f3;
  padding: 12px;
  text-align: left;
  vertical-align: top;
}

th {
  background: #f9fafb;
  color: #4b5563;
  font-weight: 700;
}

.empty,
.muted {
  color: #6b7280;
}

.notice {
  border: 1px solid #badbcc;
  border-radius: 8px;
  background: #f0fdf4;
  color: #166534;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.notice.warning {
  border-color: #fed7aa;
  background: #fff7ed;
  color: #c2410c;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  background: #fff;
  padding: 12px 14px;
  margin-bottom: 12px;
}

.pagination-bar.bottom {
  margin-top: 12px;
  margin-bottom: 0;
}

.pagination-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  min-height: 32px;
  border: 1px solid #d4d7dd;
  border-radius: 6px;
  background: #fff;
  color: #1f2937;
  padding: 6px 9px;
}

.page-link.active {
  border-color: #166534;
  background: #166534;
  color: #fff;
}

.page-link.disabled {
  color: #9ca3af;
  background: #f9fafb;
}

.status {
  display: inline-block;
  border-radius: 999px;
  background: #eef6ff;
  color: #174ea6;
  padding: 4px 9px;
  white-space: nowrap;
}

.status.danger {
  background: #fef2f2;
  color: #b42318;
}

.status-blue {
  background: #eef6ff;
  color: #174ea6;
}

.status-green {
  background: #ecfdf3;
  color: #067647;
}

.status-red {
  background: #fef2f2;
  color: #b42318;
}

.status-orange {
  background: #fff7ed;
  color: #c2410c;
}

.status-purple {
  background: #f5f3ff;
  color: #6d28d9;
}

.status-orange-red {
  background: #fff1eb;
  color: #c2410c;
}

.status-gray {
  background: #f3f4f6;
  color: #4b5563;
}

.muted-status {
  background: #f3f4f6;
  color: #4b5563;
}

h1 {
  margin: 4px 0;
  font-size: 28px;
}

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

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.panel {
  padding: 18px;
  margin-bottom: 16px;
}

dl {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px 16px;
  margin: 0;
}

dt {
  color: #6b7280;
}

dd {
  margin: 0;
}

.preline {
  white-space: pre-line;
}

.item-row {
  border-top: 1px solid #edf0f3;
  padding: 16px 0;
}

.item-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
}

.item-meta.detail {
  align-items: center;
}

.production-table th,
.production-table td {
  padding: 12px;
  vertical-align: top;
}

.orders-board-table {
  min-width: 2050px;
  table-layout: fixed;
}

.orders-board-table .col-select {
  width: 44px;
  min-width: 44px;
}

.orders-board-table .order-number-cell {
  width: 90px;
  min-width: 90px;
}

.orders-board-table .preview-cell {
  width: 160px;
  min-width: 160px;
  max-width: 180px;
}

.orders-board-table .product-cell {
  width: 220px;
  min-width: 200px;
}

.orders-board-table .design-notes-cell {
  width: 260px;
  min-width: 240px;
}

.orders-board-table .modeler-cell {
  width: 120px;
  min-width: 110px;
}

.orders-board-table .status-cell {
  width: 120px;
  min-width: 110px;
}

.orders-board-table .after-sales-cell {
  width: 140px;
  min-width: 130px;
}

.orders-board-table .fulfillment-cell {
  width: 140px;
  min-width: 130px;
}

.orders-board-table .date-cell {
  width: 120px;
  min-width: 110px;
}

.orders-board-table .note-cell {
  width: 240px;
  min-width: 220px;
}

.orders-board-table .action-cell {
  width: 100px;
  min-width: 90px;
}

.order-name a {
  font-weight: 700;
}

.order-preview-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: flex-start;
}

.order-preview-card {
  width: 120px;
}

.order-preview-thumb {
  width: 110px;
  height: 110px;
  max-width: 110px;
  max-height: 110px;
  display: block;
  object-fit: contain;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
}

.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.mini-button {
  display: inline-block;
  border: 1px solid #d4d7dd;
  border-radius: 5px;
  background: #fff;
  color: #1f2937;
  font-size: 12px;
  line-height: 1.2;
  padding: 4px 6px;
  white-space: nowrap;
}

.item-list {
  display: grid;
  gap: 12px;
}

.order-item-summary {
  min-width: 180px;
  max-width: 220px;
  line-height: 1.35;
}

.order-item-summary + .order-item-summary {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid #e5e7eb;
}

.order-item-title {
  display: block;
  font-weight: 600;
  word-break: normal;
  overflow-wrap: break-word;
}

.order-item-variant,
.order-item-qty,
.order-item-sku {
  display: block;
  color: #4b5563;
  font-size: 13px;
}

.design-notes-list {
  display: grid;
  gap: 10px;
}

.design-note-summary {
  display: grid;
  gap: 4px;
}

.design-note-summary strong {
  font-size: 12px;
  color: #4b5563;
}

.design-note-summary p {
  display: -webkit-box;
  margin: 0;
  max-height: 76px;
  overflow: hidden;
  color: #1f2937;
  font-size: 13px;
  line-height: 1.45;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.design-note-summary + .design-note-summary {
  border-top: 1px solid #e5e7eb;
  padding-top: 8px;
}

.cell-subtext {
  margin-top: 6px;
  color: #6b7280;
  font-size: 12px;
  line-height: 1.4;
  word-break: break-word;
}

.detail-design-note {
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fafafa;
  padding: 10px;
  margin: 10px 0 14px;
}

.detail-design-note p {
  margin: 6px 0 0;
  white-space: pre-wrap;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}

figure {
  margin: 0;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

figure img {
  display: block;
  width: 100%;
  height: 220px;
  object-fit: cover;
  background: #f3f4f6;
}

figcaption {
  display: grid;
  gap: 4px;
  padding: 10px;
}

small {
  color: #6b7280;
  word-break: break-all;
}

.missing {
  display: grid;
  place-items: center;
  height: 220px;
  color: #9ca3af;
  background: #f3f4f6;
}

.missing.small {
  height: 110px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  text-align: center;
}

.order-preview-missing {
  display: grid;
  place-items: center;
  color: #9ca3af;
  font-size: 12px;
  text-align: center;
}

.bulk-actions {
  display: none;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  border: 1px solid #bfdbfe;
  border-radius: 8px;
  background: #eff6ff;
  padding: 12px;
  margin-bottom: 12px;
}

.bulk-actions.active {
  display: flex;
}

.bulk-actions select {
  width: 150px;
}

.settings-form,
.inline-form,
.sync-buttons {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.settings-form label {
  color: #4b5563;
  font-weight: 700;
}

.warning-panel {
  border-color: #f59e0b;
  background: #fffbeb;
}

.simple-table table {
  min-width: 900px;
}

.kpi-wide-table table {
  min-width: 1700px;
}

.debug-table table {
  min-width: 1280px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.stat-card {
  display: grid;
  gap: 8px;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  padding: 16px;
}

.stat-card span {
  color: #6b7280;
}

.stat-card strong {
  font-size: 28px;
}

.trend-chart {
  display: flex;
  align-items: end;
  gap: 5px;
  height: 150px;
  border-bottom: 1px solid #e5e7eb;
  padding-top: 14px;
  overflow-x: auto;
}

.trend-bar-wrap {
  display: grid;
  align-items: end;
  justify-items: center;
  gap: 4px;
  min-width: 24px;
  color: #6b7280;
  font-size: 11px;
}

.trend-bar {
  width: 16px;
  min-height: 4px;
  border-radius: 4px 4px 0 0;
  background: #2563eb;
}

.line-chart {
  width: 100%;
  overflow-x: auto;
}

.line-chart svg {
  display: block;
  min-width: 720px;
  width: 100%;
  height: auto;
}

.chart-axis {
  stroke: #d1d5db;
  stroke-width: 1;
}

.chart-area {
  fill: #dbeafe;
  opacity: 0.75;
}

.chart-line {
  fill: none;
  stroke: #2563eb;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 3;
}

.chart-dot {
  fill: #fff;
  stroke: #2563eb;
  stroke-width: 2;
}

.chart-area-warm {
  fill: #fed7aa;
}

.chart-line-warm {
  stroke: #ea580c;
}

.chart-dot-warm {
  stroke: #ea580c;
}

.chart-label {
  fill: #6b7280;
  font-size: 12px;
}

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

.dist-list a {
  display: flex;
  justify-content: space-between;
  border: 1px solid #edf0f3;
  border-radius: 6px;
  padding: 9px 10px;
  color: #1f2937;
}

.dist-list p {
  margin: 0;
  padding: 9px 0;
}

.subheading {
  margin-top: 18px;
}

.delayed-list {
  display: grid;
  gap: 12px;
}

.delayed-row {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: start;
  border-top: 1px solid #edf0f3;
  padding-top: 12px;
}

.delayed-row:first-child {
  border-top: 0;
  padding-top: 0;
}

.delayed-thumb img,
.delayed-thumb span {
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  object-fit: cover;
  background: #f9fafb;
  color: #9ca3af;
  font-size: 12px;
}

.view-all-button {
  display: inline-block;
  margin-top: 14px;
}

.manual-order-form {
  display: grid;
  gap: 16px;
}

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

.form-grid label,
.upload-box {
  display: grid;
  gap: 7px;
  color: #4b5563;
  font-weight: 700;
}

.form-grid input,
.form-grid select,
.form-grid textarea,
.upload-box input {
  font-weight: 400;
}

.span-two {
  grid-column: 1 / -1;
}

.upload-box {
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  padding: 16px;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
}

.note-form {
  display: grid;
  gap: 10px;
}

.note-upload {
  display: grid;
  gap: 7px;
  border: 1px dashed #cbd5e1;
  border-radius: 8px;
  background: #f8fafc;
  color: #4b5563;
  font-weight: 700;
  padding: 12px;
}

.note-upload input {
  font-weight: 400;
}

.note {
  border-top: 1px solid #edf0f3;
  padding-top: 10px;
  margin-top: 10px;
}

.note-attachments {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

.note-attachment img {
  display: block;
  width: 100%;
  height: 130px;
  object-fit: contain;
  background: #f9fafb;
}

.note-attachment figcaption {
  padding: 8px;
}

.note time,
.error {
  color: #6b7280;
  white-space: pre-wrap;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  color: #e5e7eb;
  font-size: 14px;
}

.logout-form {
  margin: 0;
}

.link-button {
  appearance: none;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}

.login-panel {
  width: min(420px, 100%);
  margin: 56px auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  background: #fff;
  padding: 28px;
}

.login-form,
.user-create-form {
  display: grid;
  gap: 10px;
}

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

.inline-actions form {
  display: flex;
  gap: 6px;
  align-items: center;
}

.inline-actions input {
  width: 140px;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.metric-card {
  display: grid;
  gap: 8px;
  border: 1px solid #e0e3e8;
  border-radius: 8px;
  background: #fff;
  color: #1f2937;
  padding: 16px;
}

.metric-card span {
  color: #6b7280;
}

.metric-card strong {
  font-size: 26px;
}

.kpi-chart-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 12px;
  align-items: end;
}

.kpi-chart-item {
  display: grid;
  gap: 6px;
  justify-items: center;
  min-width: 0;
  color: #475569;
  font-size: 12px;
}

.bar-track {
  display: flex;
  align-items: end;
  width: 34px;
  height: 140px;
  border-radius: 6px;
  background: #eef2f7;
  overflow: hidden;
}

.bar-fill {
  width: 100%;
  min-height: 3px;
  border-radius: 6px 6px 0 0;
  background: #2563eb;
}

.orders-table-wrap {
  width: 100%;
  overflow-x: auto;
  overflow-y: visible;
}

.orders-table {
  width: 100%;
  min-width: 1500px;
  border-collapse: collapse;
  table-layout: fixed;
}

.orders-table th,
.orders-table td {
  box-sizing: border-box;
  vertical-align: top;
}

.orders-table .col-select {
  width: 44px !important;
  min-width: 44px !important;
  max-width: 44px !important;
}

.orders-table .order-number-cell {
  width: 100px !important;
  min-width: 100px !important;
  max-width: 100px !important;
  white-space: nowrap;
}

.orders-table .preview-cell {
  width: 150px !important;
  min-width: 150px !important;
  max-width: 150px !important;
}

.orders-table .product-cell {
  width: 220px !important;
  min-width: 220px !important;
}

.orders-table .design-notes-cell {
  width: 260px !important;
  min-width: 260px !important;
  max-width: 260px !important;
}

.orders-table .modeler-cell {
  width: 100px !important;
  min-width: 100px !important;
  max-width: 100px !important;
}

.orders-table .status-cell {
  width: 120px !important;
  min-width: 120px !important;
  max-width: 120px !important;
}

.orders-table .fulfillment-cell {
  width: 140px !important;
  min-width: 140px !important;
  max-width: 140px !important;
}

.orders-table .date-cell {
  width: 130px !important;
  min-width: 130px !important;
  max-width: 130px !important;
}

.orders-table .note-cell {
  width: 240px !important;
  min-width: 220px !important;
  max-width: 260px !important;
}

.orders-table .action-cell {
  width: 100px !important;
  min-width: 100px !important;
  max-width: 100px !important;
}

.orders-table .order-preview-thumb {
  width: 110px;
  height: 110px;
  max-width: 110px;
  max-height: 110px;
  object-fit: contain;
  display: block;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  background: #fff;
}

.orders-table .order-preview-card,
.orders-table .order-preview-card .preview-actions {
  width: 110px;
}

.orders-table .order-preview-card .preview-actions {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 6px;
}

.orders-table .order-preview-card .preview-actions a,
.orders-table .order-preview-card .preview-actions button {
  font-size: 12px;
  line-height: 1.2;
  padding: 4px 6px;
}

.design-notes-content {
  max-height: 72px;
  overflow: hidden;
  line-height: 1.4;
  word-break: normal;
  overflow-wrap: break-word;
}

.internal-note-summary,
.sync-error-content {
  display: -webkit-box;
  margin: 0;
  overflow: hidden;
  line-height: 1.4;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
}

.internal-note-summary {
  -webkit-line-clamp: 4;
}

.sync-error-cell {
  width: 280px;
  max-width: 280px;
}

.sync-error-content {
  -webkit-line-clamp: 5;
}

.danger-button {
  border-color: #dc2626;
  color: #b91c1c;
}

.back {
  color: #6b7280;
}

.loading-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(17, 24, 39, 0.42);
  z-index: 20;
}

.loading-overlay.active {
  display: flex;
}

.loading-box {
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 40px));
  border-radius: 8px;
  background: #fff;
  padding: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.22);
}

.loading-box span {
  color: #6b7280;
}

@media (max-width: 800px) {
  .topbar {
    height: auto;
    min-height: 56px;
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 10px 16px;
    padding: 12px 16px;
  }

  .topbar nav {
    order: 3;
    width: 100%;
    gap: 16px;
    overflow-x: auto;
    padding-bottom: 2px;
    white-space: nowrap;
  }

  .user-menu {
    margin-left: auto;
  }

  .page {
    padding: 16px;
  }

  .pagination-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .pagination-actions {
    width: 100%;
    flex-wrap: wrap;
  }

  .toolbar,
  .header-row,
  .grid.two {
    display: block;
  }

  .filters,
  .status-form,
  .actions {
    margin-bottom: 12px;
  }

  .table-wrap {
    overflow-x: auto;
  }
}
