:root {
  --ink: #162027;
  --muted: #66737f;
  --line: #d9e2e7;
  --panel: #ffffff;
  --bg: #f3f6f7;
  --brand: #1f4e5f;
  --brand-dark: #153946;
  --accent: #bf7b2f;
  --danger: #b42318;
  --ok: #207a4c;
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

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

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

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

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

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 6px 18px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  background: var(--brand);
  color: #fff;
  border-radius: 6px;
  font-weight: 700;
}

.brand-title {
  font-weight: 700;
}

.brand-subtitle,
#pageMeta,
.panel-head p,
.muted,
.result-line {
  color: var(--muted);
  font-size: 13px;
}

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

.nav-item {
  border: 0;
  background: transparent;
  color: #30404b;
  text-align: left;
  padding: 11px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.is-active {
  background: #eaf3f6;
  color: var(--brand);
  font-weight: 700;
}

.main {
  min-width: 0;
  padding: 20px 24px 36px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
}

h2 {
  font-size: 17px;
}

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

.primary-btn,
.secondary-btn {
  min-height: 38px;
  border-radius: 6px;
  padding: 0 14px;
  border: 1px solid transparent;
  cursor: pointer;
  white-space: nowrap;
}

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

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

.secondary-btn {
  background: #fff;
  border-color: var(--line);
  color: var(--ink);
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

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

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

.metric-card,
.panel,
.task-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.metric-card {
  padding: 15px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  font-size: 26px;
  font-weight: 800;
  margin-top: 6px;
}

.metric-value.small-value {
  font-size: 20px;
  word-break: break-word;
}

.metric-card.warn .metric-value {
  color: var(--danger);
}

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

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

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

.team-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 11px 12px;
}

.team-name {
  font-weight: 700;
}

.team-number {
  color: var(--brand);
  font-weight: 800;
  font-size: 20px;
}

.toolbar {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

#poSearchPanel .toolbar {
  margin-top: 10px;
}

#poSearchPanel .task-list {
  margin-top: 10px;
}

#poSearchPanel .po-detail-panel {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 14px;
}

.search-input,
select,
input[type="file"],
input[type="date"],
input[type="text"],
input[type="number"],
textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 38px;
  padding: 8px 10px;
  background: #fff;
}

.search-input {
  min-width: 280px;
  flex: 1;
}

.task-list {
  display: grid;
  gap: 9px;
}

.task-card {
  padding: 13px 14px;
  cursor: pointer;
}

.task-card:hover {
  border-color: #94b6c2;
}

.factory-incomplete {
  border-color: #f0a39b;
  background: #fff8f7;
}

.factory-incomplete .pill {
  background: #fff0ed;
  color: var(--danger);
}

.task-top,
.task-bottom {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: center;
}

.task-title {
  font-weight: 800;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 9px;
  border-radius: 999px;
  background: #eef4f6;
  color: var(--brand);
  font-size: 12px;
  white-space: nowrap;
}

.danger-pill {
  background: #fff0ed;
  color: var(--danger);
}

.task-card.status-delayed,
.set-card.status-delayed {
  border-color: #e58a80;
  background: #fff5f3;
}

.task-card.status-partial,
.set-card.status-partial {
  border-color: #e0ad62;
  background: #fff9ed;
}

.task-card.status-unshipped,
.set-card.status-unshipped {
  border-color: #82afc0;
  background: #f1f8fb;
}

.task-card.status-unmatched,
.set-card.status-unmatched {
  border-color: #c2cbd2;
  background: #f7f8f9;
}

.task-card.status-shipped,
.set-card.status-shipped {
  border-color: #9cc8ad;
  background: #f3fbf6;
}

.pill.status-delayed,
.status-pill.status-delayed {
  background: #fff0ed;
  color: var(--danger);
}

.pill.status-partial,
.status-pill.status-partial {
  background: #fff2d9;
  color: #946118;
}

.pill.status-unshipped,
.status-pill.status-unshipped {
  background: #e4f2f7;
  color: var(--brand);
}

.pill.status-unmatched,
.status-pill.status-unmatched {
  background: #eef1f3;
  color: #52606b;
}

.pill.status-shipped,
.status-pill.status-shipped {
  background: #e8f6ee;
  color: var(--ok);
}

.due-date-alert {
  color: var(--danger);
  font-weight: 800;
}

.qty {
  font-weight: 800;
  white-space: nowrap;
}

.task-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 0 0 auto;
}

.qr-ticket-link {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border: 1px solid var(--brand);
  border-radius: 6px;
  color: var(--brand);
  background: #fff;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.qr-ticket-link:hover {
  background: #eaf3f6;
}

.order-download-btn {
  font-family: inherit;
}

.task-meta {
  margin: 6px 0;
  color: var(--muted);
  font-size: 13px;
}

.po-card {
  display: grid;
  gap: 8px;
}

.po-summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.po-summary-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  background: #fbfcfc;
}

.po-summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.po-summary-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 18px;
}

.po-detail-panel.is-hidden {
  display: none;
}

.style-preview {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-form {
  display: grid;
  gap: 14px;
}

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

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

label span {
  color: var(--ink);
  font-weight: 700;
}

label.wide {
  grid-column: 1 / -1;
}

.qty-mode-controls {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 8px;
}

textarea {
  resize: vertical;
}

#completionText {
  color: var(--brand);
}

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

.record {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fbfcfc;
}

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

.step {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
}

.step b {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  flex: 0 0 auto;
}

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

.date-input {
  width: 160px;
}

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

.download-link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.download-link.is-disabled {
  color: var(--muted);
  background: #f4f7f8;
  cursor: not-allowed;
}

.upload-grid {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
  align-items: end;
}

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

.upload-status {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
}

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

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

.data-table th,
.data-table td {
  padding: 10px 11px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  font-size: 13px;
  white-space: nowrap;
}

.data-table th {
  background: #edf3f5;
  color: #30404b;
  font-weight: 800;
}

.team-adjust-select {
  min-width: 116px;
  min-height: 32px;
  padding: 5px 8px;
}

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

.empty-cell {
  color: var(--muted);
  text-align: center !important;
  padding: 28px !important;
}

.compact-empty {
  padding: 14px;
  margin-bottom: 10px;
}

.daily-po-list {
  margin: 4px 0 14px;
}

.daily-po-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

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

.daily-po-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.daily-po-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  padding: 10px 11px;
}

.daily-po-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.daily-po-item b {
  white-space: nowrap;
  color: var(--brand);
}

.chart-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
  margin: 12px 0 6px;
}

.chart-date-range,
.chart-actions {
  display: flex;
  gap: 10px;
  align-items: end;
  flex-wrap: wrap;
}

.chart-date-range label {
  min-width: 160px;
}

.compact-task-list {
  gap: 8px;
}

.compact-po-card {
  padding: 11px 12px;
}

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

.set-card {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  padding: 12px;
}

.set-card-head,
.set-card-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.set-card-title {
  font-weight: 800;
}

.set-card-meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.set-card-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  margin-top: 10px;
}

.detail-table {
  min-width: 760px;
}

.style-thumb,
.style-fallback {
  width: 72px;
  height: 96px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f6f8f9;
}

.style-thumb {
  display: block;
  object-fit: cover;
}

.style-fallback {
  display: grid;
  place-items: center;
  color: var(--brand);
  font-weight: 800;
  font-size: 13px;
  text-align: center;
  padding: 6px;
}

.color-summary {
  white-space: normal !important;
  line-height: 1.55;
  min-width: 260px;
}

.preview-only-row {
  background: #fffaf2;
}

.recent-order-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 260px;
  white-space: normal;
}

.recent-order-list span {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef4f6;
  color: #30404b;
  font-size: 12px;
  white-space: nowrap;
}

.mini-chart {
  display: grid;
  gap: 8px;
  align-items: end;
  min-height: 190px;
  padding-top: 12px;
  overflow-x: auto;
}

.day-bar {
  position: relative;
  display: grid;
  align-content: end;
  justify-items: center;
  min-height: 160px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfcfc;
  cursor: pointer;
  overflow: hidden;
  padding: 8px 4px;
  color: var(--ink);
}

.day-bar:hover {
  border-color: #94b6c2;
}

.day-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #cfe3ea;
  z-index: 0;
}

.day-bar strong,
.day-bar em {
  position: relative;
  z-index: 1;
}

.day-bar strong {
  font-size: 13px;
}

.day-bar em {
  color: var(--muted);
  font-size: 12px;
  font-style: normal;
}

.factory-chart {
  display: grid;
  gap: 10px;
}

.factory-chart.single {
  max-width: 760px;
}

.output-row {
  display: grid;
  grid-template-columns: 92px minmax(160px, 1fr) minmax(320px, auto);
  align-items: center;
  gap: 10px;
}

.output-name {
  font-weight: 800;
}

.output-bars {
  height: 18px;
  border-radius: 999px;
  background: #e9eff2;
  overflow: hidden;
}

.dual-output-bars,
.triple-output-bars {
  display: grid;
  gap: 2px;
  background: transparent;
  border-radius: 0;
}

.dual-output-bars {
  grid-template-rows: 1fr 1fr;
  height: 28px;
}

.triple-output-bars {
  grid-template-rows: 1fr 1fr 1fr;
  height: 38px;
}

.dual-output-bars .output-bar,
.triple-output-bars .output-bar {
  min-width: 3%;
}

.output-bar {
  display: block;
  height: 100%;
  border-radius: inherit;
}

.output-bar.active {
  background: var(--brand);
}

.output-bar.done {
  background: var(--accent);
}

.output-bar.complete {
  background: var(--ok);
}

.panel-subhead {
  margin: 14px 0 8px;
  font-weight: 800;
}

.output-data {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.empty {
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

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

  .sidebar {
    height: auto;
    position: static;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .nav {
    display: flex;
    overflow-x: auto;
  }

  .nav-item {
    flex: 0 0 auto;
  }

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

  .metrics-grid,
  .team-list,
  .settings-grid,
  .upload-grid,
  .po-summary-grid,
  .form-grid,
  .daily-po-grid,
  .set-list {
    grid-template-columns: 1fr;
  }

  .search-input {
    min-width: 100%;
  }

  #newFactoryName,
  #addFactoryBtn,
  #factorySelect {
    width: 100%;
  }

  .mini-chart {
    grid-template-columns: repeat(7, minmax(36px, 1fr));
  }

  .output-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .output-data {
    white-space: normal;
  }

  .task-bottom,
  .task-actions {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .qty-mode-controls {
    grid-template-columns: 1fr;
  }

  .chart-toolbar,
  .chart-date-range,
  .chart-actions {
    align-items: stretch;
    width: 100%;
  }

  .chart-date-range label,
  .chart-date-range .date-input,
  .chart-actions .small-btn {
    width: 100%;
  }
}
