:root {
  color-scheme: light;
  --ink: #18201c;
  --muted: #65706a;
  --line: #d8ded9;
  --line-strong: #b9c2bc;
  --surface: #f3f5f3;
  --panel: #fbfcfb;
  --paper: #ffffff;
  --accent: #176b46;
  --accent-hover: #10583a;
  --accent-soft: #e4f1e9;
  --danger: #a43b36;
  --danger-soft: #fae9e7;
  --radius: 10px;
  --shadow: 0 20px 60px rgba(28, 46, 36, 0.13);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; background: var(--surface); color: var(--ink); }
body { font-size: 14px; }
button, input, textarea, select { font: inherit; }
button, select, input[type="range"], input[type="checkbox"], input[type="file"] { cursor: pointer; }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(23, 107, 70, 0.22);
  outline-offset: 2px;
}

.hidden { display: none !important; }

.app-shell { min-height: 100dvh; }
.topbar {
  height: 68px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  background: rgba(251, 252, 251, 0.96);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(12px);
}

.brand-block { display: flex; align-items: center; gap: 11px; min-width: 0; }
.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 3px;
  padding: 5px;
  border-radius: 9px;
  background: var(--accent);
}
.brand-mark span { background: #f3faf6; border-radius: 2px; }
.brand-block h1 { margin: 0; font-size: 17px; line-height: 1.2; letter-spacing: 0.01em; }
.brand-block p { margin: 2px 0 0; color: var(--muted); font-size: 11px; }
.topbar-actions { display: flex; align-items: center; gap: 16px; }
.save-state { color: var(--muted); font-size: 12px; }

.workspace {
  display: grid;
  grid-template-columns: minmax(360px, 430px) minmax(620px, 1fr);
  min-height: calc(100dvh - 68px);
}

.control-panel {
  border-right: 1px solid var(--line);
  background: var(--panel);
  overflow: auto;
}
.panel-section { padding: 24px; border-bottom: 1px solid var(--line); }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.section-heading h2 { font-size: 17px; margin: 3px 0 0; letter-spacing: -0.01em; }
.step-label { color: var(--accent); font-size: 11px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > span { font-size: 12px; font-weight: 650; color: #435049; }
.field small { color: var(--muted); text-align: right; font-size: 11px; }
.field-grid { display: grid; gap: 13px; }
.field-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }

input[type="text"], input[type="number"], textarea, select {
  width: 100%;
  min-height: 39px;
  padding: 8px 10px;
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
  transition: border-color 140ms ease, box-shadow 140ms ease;
}
.color-field input[type="color"] {
  width: 100%;
  min-height: 39px;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  background: var(--paper);
}
.color-field input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-field input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 4px; }
textarea { resize: vertical; line-height: 1.55; min-height: 92px; }
input:hover, textarea:hover, select:hover { border-color: #8f9c94; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(23, 107, 70, 0.1); outline: none; }
input:disabled { cursor: not-allowed; color: #7b8580; background: #eef1ef; }

.button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 39px;
  padding: 8px 15px;
  font-weight: 700;
  white-space: nowrap;
  transition: background-color 140ms ease, border-color 140ms ease, transform 100ms ease;
}
.button:active { transform: translateY(1px); }
.button:disabled { cursor: not-allowed; opacity: 0.45; }
.button-primary { color: #f8fcfa; background: var(--accent); }
.button-primary:hover:not(:disabled) { background: var(--accent-hover); }
.button-secondary { color: var(--ink); background: var(--paper); border-color: var(--line-strong); }
.button-secondary:hover { background: #f1f4f2; border-color: #8f9c94; }
.text-button { border: 0; padding: 3px 0; color: var(--accent); background: transparent; font-weight: 700; font-size: 12px; }
.text-button:hover { text-decoration: underline; text-underline-offset: 3px; }
.text-button.danger { color: var(--danger); }

.spec-summary {
  margin-top: 12px;
  padding: 13px 14px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: #254c37;
}
.summary-metric { min-width: 0; }
.summary-metric strong { display: block; font-size: 14px; }
.summary-metric span { font-size: 10px; color: #52715e; }
.spec-details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 13px; }
.spec-details summary { color: var(--accent); font-weight: 700; cursor: pointer; }
.spec-details[open] summary { margin-bottom: 16px; }
.save-spec-row { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; margin-top: 14px; }

.upload-field {
  position: relative;
  margin-top: 15px;
  min-height: 60px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 13px;
  border: 1px dashed #9eaaa2;
  border-radius: 8px;
  background: #f8faf8;
}
.upload-field:hover { border-color: var(--accent); background: #f3f8f5; }
.upload-field.dragging { border-color: var(--accent); background: var(--accent-soft); box-shadow: 0 0 0 3px rgba(23, 107, 70, 0.1); }
.upload-field input[type="file"] { position: absolute; inset: 0; opacity: 0; width: 100%; }
.upload-copy { display: flex; flex-direction: column; gap: 3px; pointer-events: none; }
.upload-copy strong { font-size: 13px; }
.upload-copy span { color: var(--muted); font-size: 11px; }
.upload-field .text-button { position: relative; margin-left: auto; z-index: 2; }
.image-file { padding-top: 11px; color: var(--muted); font-size: 11px; }
.image-queue-heading { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; margin-bottom: 8px; }
.image-queue-heading strong { color: var(--ink); font-size: 12px; }
.image-queue-heading span { text-align: right; }
.image-queue { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; max-height: 246px; overflow: auto; padding: 1px; }
.image-item { position: relative; min-width: 0; margin: 0; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; }
.image-item img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: #eef1ef; }
.image-item figcaption { display: flex; gap: 5px; padding: 6px; min-width: 0; }
.image-number { flex: none; color: var(--accent); font-weight: 800; }
.image-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.image-remove { position: absolute; top: 4px; right: 4px; min-width: 0; min-height: 25px; padding: 3px 7px; border: 0; border-radius: 5px; color: #fff; background: rgba(31, 41, 35, 0.82); font-size: 10px; font-weight: 700; }
.image-remove:hover { background: var(--danger); }

.check-field { display: flex; align-items: center; gap: 9px; margin-top: 14px; color: #435049; font-size: 12px; font-weight: 650; }
.check-field input { width: 17px; height: 17px; accent-color: var(--accent); }
.check-field-feature { align-items: flex-start; padding: 11px 12px; border: 1px solid #c9d9cf; border-radius: 8px; background: var(--accent-soft); }
.check-field-feature input { margin-top: 2px; }
.check-field-feature span { display: flex; flex-direction: column; gap: 3px; }
.check-field-feature strong { color: #244d36; }
.check-field-feature small { color: #587062; font-size: 11px; font-weight: 500; line-height: 1.4; }
.page-result { margin-top: 14px; padding: 12px 14px; border-radius: 8px; background: #eff2f0; color: #4f5c55; line-height: 1.5; font-size: 12px; }
.page-result strong { color: var(--ink); }

.preview-panel { min-width: 0; display: flex; flex-direction: column; background: #e8ece9; }
.preview-toolbar {
  min-height: 58px;
  padding: 10px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  border-bottom: 1px solid #d3d9d5;
  background: rgba(243, 245, 243, 0.92);
}
.preview-toolbar > div { display: flex; align-items: baseline; gap: 9px; }
.preview-toolbar strong { font-size: 13px; }
.preview-toolbar span { color: var(--muted); font-size: 11px; }
.zoom-control { display: flex; align-items: center; gap: 9px; }
.zoom-control input { width: 120px; accent-color: var(--accent); }
.zoom-control output { min-width: 33px; color: var(--ink); font-variant-numeric: tabular-nums; font-size: 11px; }

.notice { margin: 14px 20px 0; padding: 10px 12px; border-radius: 7px; font-size: 12px; line-height: 1.45; }
.notice-info { color: #385344; background: #dce7e0; border: 1px solid #cadbd0; }
.notice-error { color: #762c28; background: var(--danger-soft); border: 1px solid #efcac6; }

.paper-stage {
  flex: 1;
  min-height: 520px;
  overflow: auto;
  display: grid;
  place-items: start center;
  padding: 30px 40px 44px;
}
.sheet-frame { position: relative; flex: none; }
.print-sheet {
  position: relative;
  width: 210mm;
  height: 297mm;
  overflow: hidden;
  background: var(--paper);
}
.screen-sheet {
  transform-origin: top left;
  box-shadow: var(--shadow);
}
.label-cell {
  position: absolute;
  overflow: hidden;
  display: flex;
  color: #111713;
  background: transparent;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.label-cell.guide { outline: 0.25mm dashed rgba(75, 94, 83, 0.48); outline-offset: -0.25mm; }
.label-cell.photo-only { padding: 0 !important; }
.label-cell.circle { border-radius: 50%; }
.label-cell.circle:not(.photo-only) { overflow: hidden; }
.label-cell.circle.photo-only { overflow: visible; }
.label-cell.circle.photo-only .label-content {
  position: absolute;
  left: calc(0mm - var(--bleed));
  top: calc(0mm - var(--bleed));
  width: calc(100% + var(--bleed) + var(--bleed));
  height: calc(100% + var(--bleed) + var(--bleed));
  border-radius: 50%;
  -webkit-clip-path: circle(50% at 50% 50%);
  clip-path: circle(50% at 50% 50%);
  overflow: hidden;
}
.label-cell.skipped { background: repeating-linear-gradient(135deg, rgba(89, 103, 94, 0.06) 0, rgba(89, 103, 94, 0.06) 2mm, transparent 2mm, transparent 4mm); }
.label-cell.skipped::after { content: "跳過"; margin: auto; color: #97a29b; font-size: 9pt; }
.label-content { position: relative; width: 100%; height: 100%; min-width: 0; display: flex; gap: 1.5mm; overflow: hidden; }
.label-content.position-top { flex-direction: column; }
.label-content.position-left { flex-direction: row; }
.label-image { display: block; object-fit: contain; min-width: 0; min-height: 0; }
.position-top .label-image { width: 100%; height: 58%; }
.position-left .label-image { width: 42%; height: 100%; }
.label-text { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.28; }
.label-text span { width: 100%; }
.label-content.position-background .label-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.label-content.position-background .label-text { position: relative; z-index: 1; padding: 1mm; background: rgba(255, 255, 255, 0.72); }
.label-content.only-image .label-image { width: 100%; height: 100%; object-fit: cover; }

.page-nav { min-height: 48px; padding: 8px 20px 14px; display: flex; justify-content: center; align-items: center; gap: 8px; }
.page-button { min-width: 34px; height: 32px; padding: 0 10px; border: 1px solid #b7c0ba; border-radius: 7px; background: #f7f9f7; color: #4e5a53; font-weight: 700; }
.page-button[aria-current="page"] { background: var(--accent); color: #fff; border-color: var(--accent); }

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 50;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: 8px;
  color: #f7fbf8;
  background: #27332c;
  box-shadow: 0 12px 30px rgba(23, 32, 27, 0.2);
  transition: opacity 180ms ease, transform 180ms ease;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

#printRoot { display: none; }

@media (max-width: 1050px) {
  .workspace { grid-template-columns: 380px minmax(500px, 1fr); }
  .save-state { display: none; }
}

@media (max-width: 820px) {
  .topbar { position: relative; padding: 0 16px; }
  .workspace { display: block; }
  .control-panel { border-right: 0; }
  .preview-panel { min-height: 760px; }
  .paper-stage { place-items: start center; padding-inline: 16px; }
}

@media (max-width: 520px) {
  .topbar { height: auto; min-height: 64px; }
  .brand-block p { display: none; }
  .topbar-actions { gap: 8px; }
  .panel-section { padding: 20px 16px; }
  .field-grid-2 { grid-template-columns: 1fr; }
  .save-spec-row { grid-template-columns: 1fr; }
  .image-queue { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preview-toolbar { align-items: flex-start; flex-direction: column; gap: 9px; padding: 12px 16px; }
  .zoom-control { width: 100%; }
  .zoom-control input { flex: 1; }
  .notice { margin-inline: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}

@page { size: A4 portrait; margin: 0; }

@media print {
  html, body { width: 210mm; height: auto; margin: 0 !important; padding: 0 !important; background: #fff !important; }
  .app-shell, .toast { display: none !important; }
  #printRoot { display: block !important; }
  .print-sheet { width: 210mm; height: 297mm; margin: 0; box-shadow: none; break-after: page; page-break-after: always; }
  .print-sheet:last-child { break-after: auto; page-break-after: auto; }
  .label-cell.guide { outline: none; }
  .label-cell.skipped { background: transparent; }
  .label-cell.skipped::after { content: none; }
}
