:root {
  color-scheme: light;
  --brand: #082c4a;
  --ink: #17212a;
  --muted: #66727c;
  --line: #d9dee3;
  --soft: #f4f6f8;
  --panel: #ffffff;
  --ok: #1f7a5b;
  --warn: #9c5b16;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: #eef1f4;
  color: var(--ink);
  font-family: Arial, "Microsoft YaHei", sans-serif;
}

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

button, select, input, textarea {
  border: 1px solid var(--line);
  border-radius: 6px;
}

button {
  min-height: 38px;
  padding: 0 13px;
  background: #fff;
  color: var(--ink);
  cursor: pointer;
}

button:hover { border-color: #8a98a3; }

input, textarea, select {
  width: 100%;
  min-height: 38px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea { resize: vertical; }

input:focus, textarea:focus, select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(8, 44, 74, .12);
}

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

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

.control-panel {
  background: var(--brand);
  color: #fff;
  padding: 18px;
  overflow: auto;
  max-height: 100vh;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 13px;
  margin-bottom: 16px;
}

.brand-lockup img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  background: #09283c;
}

.brand-lockup strong {
  display: block;
  font-size: 23px;
  letter-spacing: 0;
}

.brand-lockup span {
  display: block;
  max-width: 220px;
  margin-top: 4px;
  color: #cbd7df;
  font-size: 12px;
  line-height: 1.35;
}

.notice {
  display: grid;
  gap: 5px;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: rgba(255,255,255,.06);
}

.notice span {
  color: #cbd7df;
  font-size: 12px;
  line-height: 1.45;
}

.panel-block {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

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

h1, h2, p { margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 16px; }

.field-list {
  display: grid;
  gap: 11px;
}

.locked-field {
  display: grid;
  gap: 6px;
}

.field-title {
  font-weight: 700;
  color: #66727c;
}

.lock-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 82px;
  gap: 8px;
  align-items: center;
}

.lock-button.locked {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.locked-input {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(8, 44, 74, 0.08);
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  background: var(--soft);
}

.upload-box {
  min-height: 126px;
  place-items: center;
  margin-bottom: 10px;
  border: 1px dashed #95a3ad;
  border-radius: 8px;
  background: #f8fafb;
  text-align: center;
}

.upload-box input { display: none; }
.upload-box strong { color: var(--ink); font-size: 16px; }
.upload-box span { max-width: 260px; color: var(--muted); font-weight: 400; line-height: 1.4; }
.upload-box.dragging { border-color: var(--brand); background: #edf3f7; }

.file-row {
  min-height: 38px;
  align-items: center;
  grid-template-columns: 95px 1fr;
  margin-bottom: 10px;
}

.check-row {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-weight: 700;
}

.check-row input {
  width: 16px;
  min-height: 16px;
}

.package-options {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.package-options > span {
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}

.package-quantity-row {
  grid-template-columns: 86px minmax(0, 1fr);
  align-items: center;
}

.package-quantity-row input {
  text-align: center;
  font-weight: 700;
}

.packaging-picker-panel {
  display: grid;
  gap: 12px;
  margin: 12px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
}

.picker-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.picker-title strong {
  color: var(--ink);
  font-size: 14px;
}

.picker-title span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.package-preset-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
}

.package-preset-card img {
  width: 100%;
  height: 78px;
  object-fit: contain;
  border: 1px solid #edf1f4;
  background: #fff;
}

.package-preset-card.selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(8, 44, 74, .12);
}

.button-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.source-links {
  display: grid;
  gap: 7px;
}

.source-links a {
  display: block;
  overflow: hidden;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafb;
  color: var(--brand);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

.image-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.image-thumb-wrap {
  position: relative;
  width: 74px;
  height: 74px;
}

.image-thumb-wrap img {
  width: 74px;
  height: 74px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
}

.image-thumb-wrap b,
.assignment-preview b {
  position: absolute;
  left: 4px;
  bottom: 4px;
  padding: 2px 5px;
  border-radius: 4px;
  background: rgba(8, 44, 74, .92);
  color: #fff;
  font-size: 10px;
  line-height: 1.2;
}

.image-card small {
  display: block;
  margin-bottom: 6px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-warning {
  display: inline-block;
  margin: -2px 0 6px;
  color: #9c5b16;
  font-size: 12px;
  font-weight: 700;
  line-height: 1.3;
}

.image-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 58px 58px;
  gap: 6px;
}

.assignment-panel {
  display: grid;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.assignment-head {
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
}

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

.assignment-row {
  display: grid;
  grid-template-columns: 78px 1fr;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.assignment-preview {
  position: relative;
  width: 78px;
  height: 78px;
}

.assignment-preview img {
  width: 78px;
  height: 78px;
  object-fit: contain;
  border: 1px solid var(--line);
  background: #fff;
}

.assignment-empty-thumb {
  display: grid;
  width: 78px;
  height: 78px;
  place-items: center;
  border: 1px dashed var(--line);
  color: var(--muted);
  background: #fff;
  font-size: 12px;
}

.assignment-row strong,
.assignment-row span,
.assignment-row p,
.assignment-row em {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.assignment-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.assignment-row strong {
  color: var(--ink);
  font-size: 12px;
}

.assignment-row em {
  color: var(--muted);
  font-size: 11px;
  font-style: normal;
}

.assignment-row p {
  margin: 3px 0 7px;
  color: #51616d;
  font-size: 11px;
  font-weight: 700;
}

.assignment-row select {
  min-height: 34px;
  padding: 6px 8px;
}

.empty-assignment {
  padding: 10px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

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

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

.topbar p {
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

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

.toolbar select { width: 92px; }

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

.ghost { background: #f8fafb; }

.editor-strip {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) minmax(190px, 1.25fr) repeat(4, minmax(132px, 1fr)) 74px 134px;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.editor-strip > button { white-space: nowrap; }

.image-cleanup-dialog {
  width: min(1120px, calc(100vw - 32px));
  max-width: none;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 22px 70px rgba(0, 0, 0, .32);
}

.image-cleanup-dialog::backdrop {
  background: rgba(5, 22, 35, .72);
}

.cleanup-head,
.cleanup-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 14px 16px;
}

.cleanup-head { border-bottom: 1px solid var(--line); }
.cleanup-footer { border-top: 1px solid var(--line); }
.cleanup-head strong { display: block; font-size: 18px; }
.cleanup-head span,
.cleanup-footer > span { color: var(--muted); font-size: 12px; }

.cleanup-toolbar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
  padding: 12px 16px 8px;
}

.cleanup-toolbar label {
  min-width: 190px;
  flex: 1 1 190px;
}

.cleanup-toolbar label[hidden] { display: none; }

.cleanup-toolbar label input[type="range"] {
  width: calc(100% - 42px);
  min-height: 24px;
  padding: 0;
  vertical-align: middle;
}

.cleanup-toolbar output {
  display: inline-block;
  width: 34px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  text-align: right;
}

.cleanup-tool-group { display: flex; gap: 6px; }
.cleanup-tool.active {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}

.cleanup-help {
  padding: 0 16px 10px;
  color: var(--muted);
  font-size: 12px;
}

.cleanup-canvas-wrap {
  display: grid;
  min-height: 280px;
  max-height: calc(100vh - 285px);
  place-items: center;
  overflow: auto;
  padding: 16px;
  border-top: 1px solid var(--line);
  background-color: #eef1f4;
  background-image:
    linear-gradient(45deg, #d9dee3 25%, transparent 25%),
    linear-gradient(-45deg, #d9dee3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d9dee3 75%),
    linear-gradient(-45deg, transparent 75%, #d9dee3 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

#cleanupCanvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: calc(100vh - 320px);
  background: transparent;
  cursor: crosshair;
  touch-action: none;
}

#cleanupCanvas.eraser-active { cursor: cell; }
.cleanup-footer > div { display: flex; gap: 8px; }

.precision-control {
  min-width: 0;
}

.precision-control input[type="range"] {
  width: 100%;
  min-height: 22px;
  padding: 0;
}

.precision-row {
  display: grid;
  grid-template-columns: 28px minmax(56px, 1fr) 28px;
  gap: 4px;
  align-items: center;
}

.precision-row button {
  min-height: 28px;
  height: 28px;
  padding: 0;
  border-radius: 6px;
  background: #f8fafb;
  font-size: 16px;
  line-height: 1;
}

.precision-row input[type="number"] {
  min-height: 28px;
  height: 28px;
  padding: 0 6px;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}

.detail-slot-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.detail-slot-panel[hidden] {
  display: none;
}

.detail-slot-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.detail-slot-head strong {
  color: var(--ink);
  font-size: 13px;
}

.detail-slot-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

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

.detail-slot-control {
  min-width: 0;
}

.detail-slot-control span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-slot-control select {
  min-height: 34px;
  padding: 6px 8px;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 14px;
  align-items: start;
  width: 100%;
  min-width: 0;
}

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

.guide-toggle {
  width: 16px;
  height: 16px;
  min-height: 0;
  margin: 0 6px 0 0;
  padding: 0;
  vertical-align: middle;
  accent-color: #087eae;
  cursor: pointer;
}

.guide-toggle-label {
  display: inline;
  color: var(--brand);
  vertical-align: middle;
  cursor: pointer;
}

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

.canvas-preview-stage {
  position: relative;
}

/* Preview-only DOM overlay: never drawn onto an export canvas. */
.canvas-guides {
  position: absolute;
  inset: 1px;
  pointer-events: none;
  user-select: none;
}

.guide-line {
  position: absolute;
  pointer-events: none;
}

.guide-left, .guide-right {
  top: 0;
  bottom: 0;
  width: 0;
  border-left: 1px dashed #087eae;
  filter: drop-shadow(1px 0 0 #fff);
}

.guide-left { left: 10%; }
.guide-right { left: 90%; }

.guide-top, .guide-bottom {
  left: 0;
  right: 0;
  height: 0;
  border-top: 1px dashed #087eae;
  filter: drop-shadow(0 1px 0 #fff);
}

.guide-top { top: 10%; }
.guide-bottom { top: 90%; }

.canvas-frame:not(.main-image-guides) .canvas-guides,
.canvas-frame:not(.main-image-guides) .guide-toggle,
.canvas-frame:not(.main-image-guides) .guide-toggle-label,
.canvas-frame:not(.main-image-guides) .guide-help,
.guide-toggle:not(:checked) ~ .canvas-preview-stage .canvas-guides {
  display: none;
}

@media print {
  .canvas-guides, .guide-toggle, .guide-toggle-label, .guide-help { display: none; }
}

#activeCanvas {
  cursor: grab;
  touch-action: none;
  user-select: none;
}

#activeCanvas:active {
  cursor: grabbing;
}

#activeCanvas.is-rotating {
  cursor: ew-resize;
}

.canvas-gesture-help {
  margin: 10px 2px 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  background: #fff;
}

.thumb-grid {
  display: grid;
  gap: 10px;
  width: 300px;
  min-width: 300px;
  min-height: 220px;
  padding: 2px;
  max-height: calc(100vh - 162px);
  overflow: auto;
  position: relative;
  z-index: 2;
}

.thumb {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.thumb.active {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(8, 44, 74, .12);
}

.thumb canvas {
  width: 92px;
  height: 92px;
}

.thumb strong {
  display: block;
  margin-bottom: 4px;
  font-size: 13px;
}

.thumb span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.local-download-links {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.local-download-links strong {
  color: var(--brand);
  font-size: 13px;
}

.local-download-links a {
  display: block;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 1fr; }
  .control-panel { max-height: none; }
  .editor-strip, .workspace-grid { grid-template-columns: 1fr; }
  .detail-slot-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .thumb-grid { max-height: none; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
}

@media (max-width: 620px) {
  .preview-area, .control-panel { padding: 14px; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .toolbar { width: 100%; }
  .toolbar button, .toolbar select { flex: 1; }
  .detail-slot-head { align-items: flex-start; flex-direction: column; }
  .detail-slot-grid { grid-template-columns: 1fr; }
  .two-col { grid-template-columns: 1fr; }
}
