:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --ink: #17202c;
  --muted: #667085;
  --line: #d9dee7;
  --green: #12b981;
  --blue: #2563eb;
  --red: #ef4444;
  --amber: #f59e0b;
  --shadow: 0 12px 34px rgba(20, 31, 48, 0.1);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Microsoft YaHei", "PingFang SC", system-ui, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(37, 99, 235, 0.06) 1px, transparent 1px),
    linear-gradient(rgba(18, 185, 129, 0.05) 1px, transparent 1px),
    var(--bg);
  background-size: 28px 28px;
}

button,
input,
select {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-header {
  height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  background: rgba(255, 255, 255, 0.92);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(14px);
}

.brand-block,
.header-actions,
.stage-toolbar,
.view-tools,
.recognition-bar,
.panel-title,
.mini-upload,
.switch-row,
.status-line,
.sku-row {
  display: flex;
  align-items: center;
}

.brand-block {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #17202c;
  color: #fff;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 18px;
  line-height: 1.2;
}

.brand-block p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.header-actions {
  gap: 8px;
}

.primary-btn,
.secondary-btn,
.icon-btn,
.segmented button,
.position-grid button,
.output-item,
.mobile-actions button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
}

.primary-btn {
  height: 40px;
  padding: 0 18px;
  border-color: #16202c;
  background: #16202c;
  color: white;
  font-weight: 700;
}

.secondary-btn {
  height: 36px;
  padding: 0 12px;
  font-weight: 700;
}

.secondary-btn.full {
  width: 100%;
}

.icon-btn {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
}

.workspace {
  height: calc(100vh - 68px);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 320px;
  gap: 12px;
  padding: 12px;
}

.left-panel,
.right-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 0;
  overflow: auto;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

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

.panel-title span {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: #eef4ff;
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
}

.panel-title h2 {
  font-size: 15px;
}

.upload-box {
  min-height: 158px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 8px;
  padding: 18px;
  border: 1px dashed #a8b1c1;
  border-radius: 8px;
  background: var(--surface-2);
  text-align: center;
  color: var(--muted);
}

.upload-box strong {
  color: var(--ink);
}

.upload-box.dragover {
  border-color: var(--blue);
  background: #eef4ff;
}

.mini-upload {
  gap: 10px;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.mini-upload span {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #e8f8f2;
  color: var(--green);
  font-weight: 900;
}

.mini-upload small,
.field,
.switch-row,
.recognition-bar span,
.status-line {
  color: var(--muted);
  font-size: 13px;
}

.field {
  display: grid;
  gap: 7px;
  margin-bottom: 12px;
}

.field input,
.field select {
  width: 100%;
  height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

.field input[type="range"] {
  padding: 0;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.segmented,
.position-grid,
.output-grid,
.package-list {
  display: grid;
  gap: 8px;
}

.segmented {
  grid-template-columns: repeat(3, 1fr);
}

.segmented button,
.position-grid button,
.output-item {
  height: 36px;
}

.segmented button.active,
.position-grid button.active,
.output-item.active {
  border-color: var(--blue);
  background: #eef4ff;
  color: var(--blue);
  font-weight: 800;
}

.switch-row {
  justify-content: space-between;
  min-height: 36px;
}

.switch input {
  display: none;
}

.switch b {
  width: 42px;
  height: 24px;
  display: block;
  border-radius: 999px;
  background: #cfd6e2;
  position: relative;
}

.switch b::after {
  content: "";
  width: 18px;
  height: 18px;
  position: absolute;
  top: 3px;
  left: 3px;
  border-radius: 50%;
  background: white;
  transition: 0.2s ease;
}

.switch input:checked + b {
  background: var(--green);
}

.switch input:checked + b::after {
  transform: translateX(18px);
}

.center-stage {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
}

.stage-toolbar,
.recognition-bar {
  justify-content: space-between;
  gap: 12px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.step-tabs {
  display: flex;
  gap: 6px;
}

.step-tabs button {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--muted);
}

.step-tabs button.active {
  background: #17202c;
  color: #fff;
  font-weight: 800;
}

.view-tools {
  gap: 6px;
}

.view-tools .icon-btn {
  width: 34px;
  height: 34px;
}

.canvas-wrap {
  min-height: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #dfe5ee;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.7);
}

.product-canvas {
  height: 100%;
  min-height: 420px;
  position: relative;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 8px;
  background:
    linear-gradient(45deg, #f6f8fb 25%, transparent 25%),
    linear-gradient(-45deg, #f6f8fb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f6f8fb 75%),
    linear-gradient(-45deg, transparent 75%, #f6f8fb 75%),
    #ffffff;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.empty-state {
  display: grid;
  gap: 8px;
  text-align: center;
  color: var(--muted);
}

.empty-state strong {
  font-size: 20px;
  color: var(--ink);
}

#previewImage {
  max-width: 86%;
  max-height: 78%;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 14px 44px rgba(20, 31, 48, 0.22);
}

.detect-box {
  position: absolute;
  border: 2px solid var(--green);
  background: rgba(18, 185, 129, 0.1);
  border-radius: 4px;
}

.detect-box span {
  position: absolute;
  left: -2px;
  top: -28px;
  padding: 4px 8px;
  border-radius: 4px;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.main-box {
  width: 42%;
  height: 54%;
  left: 29%;
  top: 22%;
}

.sub-box {
  width: 18%;
  height: 22%;
  right: 18%;
  bottom: 18%;
  border-color: var(--amber);
  background: rgba(245, 158, 11, 0.12);
}

.sub-box span {
  background: var(--amber);
}

.logo-layer {
  position: absolute;
  right: 26px;
  bottom: 24px;
  padding: 8px 12px;
  border: 1px solid rgba(23, 32, 44, 0.12);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.82);
  color: #17202c;
  font-weight: 900;
  letter-spacing: 0;
  box-shadow: 0 8px 22px rgba(20, 31, 48, 0.12);
}

.sku-list {
  display: grid;
  gap: 8px;
  margin-bottom: 10px;
}

.sku-row {
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.sku-color {
  width: 24px;
  height: 24px;
  flex: none;
  border-radius: 50%;
  border: 1px solid rgba(23, 32, 44, 0.16);
}

.sku-row input {
  min-width: 0;
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  color: var(--ink);
}

.sku-row button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 6px;
  background: #fff;
  color: var(--red);
}

.position-grid {
  grid-template-columns: repeat(2, 1fr);
}

.output-grid {
  grid-template-columns: repeat(2, 1fr);
}

.package-list {
  margin-bottom: 12px;
}

.package-list div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.package-list strong {
  font-size: 13px;
}

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

.job-status {
  margin-top: 12px;
}

.progress {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5eaf2;
}

.progress i {
  width: 0;
  height: 100%;
  display: block;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), var(--blue));
  transition: width 0.25s ease;
}

.status-line {
  justify-content: space-between;
  margin-top: 8px;
}

.mobile-actions {
  display: none;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 280px minmax(0, 1fr);
  }

  .right-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    overflow: visible;
  }
}

@media (max-width: 760px) {
  .app-header {
    height: auto;
    min-height: 64px;
    padding: 10px;
  }

  .brand-block p,
  .header-actions .icon-btn {
    display: none;
  }

  h1 {
    font-size: 16px;
  }

  .workspace {
    height: auto;
    display: block;
    padding: 10px 10px 76px;
  }

  .left-panel,
  .right-panel,
  .center-stage {
    display: grid;
    gap: 10px;
    margin-bottom: 10px;
  }

  .right-panel {
    grid-template-columns: 1fr;
  }

  .stage-toolbar {
    overflow-x: auto;
  }

  .product-canvas {
    min-height: 380px;
  }

  .mobile-actions {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 30;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
  }

  .mobile-actions button {
    height: 38px;
  }

  .mobile-actions .active {
    background: #17202c;
    color: #fff;
    border-color: #17202c;
  }
}
