:root {
  --bg: #fdf6ec;
  --card: #ffffff;
  --ink: #3d2b1f;
  --muted: #8a7260;
  --primary: #e8590c;
  --primary-dark: #c24506;
  --ring: #f4c48f;
  --line: #f0e2ce;
  --radius: 14px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

/* 一屏布局：页面本身不滚动，由各栏内部消化 */
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.wrap { width: 100%; max-width: 1480px; margin: 0 auto; padding: 0 16px; }

/* 顶栏（压缩高度） */
.topbar {
  flex: none;
  background: linear-gradient(135deg, #f6b26b, #e8590c);
  padding: 10px 0;
  color: #fff;
  box-shadow: 0 2px 10px rgba(232, 89, 12, 0.22);
}
.topbar .wrap { display: flex; align-items: baseline; gap: 12px; }
.logo { font-size: 18px; font-weight: 800; letter-spacing: 1px; }
.brand-sub { font-size: 12px; opacity: 0.92; }
.topbar-note { margin-left: auto; font-size: 12px; opacity: 0.85; }

/* 左中右三栏工作区 */
.workspace {
  flex: 1;
  min-height: 0;
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 12px 16px 14px;
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr) 290px;
  gap: 12px;
}
.col { min-height: 0; display: flex; flex-direction: column; gap: 12px; }
.col-left, .col-right { overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }

/* 卡片 */
.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: 0 2px 10px rgba(120, 90, 50, 0.08);
}
.card[hidden] { display: none; }

.step-title { font-size: 15px; font-weight: 700; display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.step-no {
  width: 22px; height: 22px; border-radius: 50%;
  background: var(--primary); color: #fff;
  font-size: 12px; display: inline-flex; align-items: center; justify-content: center;
  flex: none;
}

/* 上传区 */
.dropzone {
  display: block;
  border: 2px dashed var(--ring);
  background: #fffaf3;
  border-radius: var(--radius);
  padding: 16px 12px;
  text-align: center;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}
.dropzone:hover, .dropzone.drag { background: #fff3e2; border-color: var(--primary); }
.dz-icon { font-size: 26px; }
.dz-main { font-size: 14px; font-weight: 600; margin-top: 4px; }
.dz-sub { font-size: 11px; color: var(--muted); margin-top: 4px; }

/* 传图后压缩拖放区，为左列省出纵向空间 */
.dropzone.compact { padding: 8px 12px; }
.dropzone.compact .dz-icon, .dropzone.compact .dz-sub { display: none; }
.dropzone.compact .dz-main { margin-top: 0; font-size: 12px; font-weight: 500; color: var(--muted); }

.preview-original { margin-top: 10px; text-align: center; }
.preview-original img { max-width: 110px; max-height: 76px; border-radius: 10px; box-shadow: 0 2px 8px rgba(0,0,0,.15); }
.orig-size { font-size: 11px; color: var(--muted); margin-top: 6px; }

/* 参数 */
.field { margin-bottom: 10px; }
.field > label { display: flex; justify-content: space-between; font-weight: 600; font-size: 13px; }
.field .val { color: var(--primary); font-weight: 700; }
.field select {
  width: 100%; margin-top: 6px; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 14px; color: var(--ink);
  appearance: none; -webkit-appearance: none;
}
.field-hint { font-size: 11px; color: var(--muted); margin-top: 4px; }

input[type="range"] {
  width: 100%; margin-top: 6px; accent-color: var(--primary); height: 20px;
}

.switch-row {
  display: flex; align-items: center; gap: 10px;
  font-size: 13px; margin: 1px 0 5px; cursor: pointer;
}
.switch-row input { accent-color: var(--primary); width: 16px; height: 16px; }

/* 按钮 */
.btn-primary {
  width: 100%; padding: 11px; margin-top: 4px;
  background: var(--primary); color: #fff;
  border: none; border-radius: 12px;
  font-size: 15px; font-weight: 700; cursor: pointer;
  box-shadow: 0 4px 12px rgba(232, 89, 12, 0.3);
  transition: background 0.2s, transform 0.05s;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { background: #e6b392; cursor: not-allowed; }

.btn-ghost {
  padding: 9px 14px; border: 1px solid var(--ring);
  background: #fff; color: var(--primary-dark);
  border-radius: 10px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.btn-ghost:hover { background: #fff3e2; }

/* 中列：图纸预览（占满整列高度） */
.card-center { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.result-head {
  flex: none;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 10px; flex-wrap: wrap;
}
.result-head .step-title { margin-bottom: 0; }
#grid-info {
  font-size: 12px; color: var(--muted);
  min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.canvas-wrap {
  flex: 1; min-height: 200px;
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 10px;
  display: flex;
  overflow: auto; -webkit-overflow-scrolling: touch;
}
#pattern-canvas {
  display: block; margin: auto;
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  image-rendering: pixelated;
}
.empty-hint { margin: auto; color: var(--muted); font-size: 14px; text-align: center; line-height: 2; }

/* 右列：材料清单 + 导出 */
.card-right { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.sub-title { font-size: 14px; font-weight: 700; margin-bottom: 8px; flex: none; }

.legend {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding-right: 2px; scrollbar-width: thin;
}
.legend-item {
  flex: none;
  display: flex; align-items: center; gap: 10px;
  background: #fffaf3; border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font-size: 12px;
}
.lg-swatch { width: 22px; height: 22px; border-radius: 6px; flex: none; box-shadow: inset 0 0 0 1px rgba(0,0,0,.06); }
.lg-code { font-weight: 700; min-width: 56px; }
.lg-name { color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lg-count { font-weight: 700; color: var(--primary); }

.download-btns { flex: none; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.download-btns .btn-ghost { width: 100%; }

/* 窄屏回退：恢复纵向排列与页面滚动 */
@media (max-width: 1080px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .workspace { display: flex; flex-direction: column; padding: 12px; }
  .col { overflow: visible; }
  .card-center { min-height: 72vh; }
  .canvas-wrap { min-height: 52vh; }
  .legend { max-height: 42vh; }
  .topbar-note { display: none; }
}
