/* ==========================================================
   拼豆图纸生成器 — 样式
   ========================================================== */
:root {
  --bg: #f6f2ec;
  --card: #ffffff;
  --ink: #221f1c;
  --ink-2: #4a453e;
  --muted: #8d867c;
  --line: #e9e3d9;
  --line-2: #f2ece2;
  --accent: #d1543c;
  --accent-soft: #fbeee9;
  --green: #2f7a63;
  --green-soft: #e8f3ef;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(34, 31, 28, .04), 0 8px 24px -12px rgba(34, 31, 28, .18);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Source Han Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 10% -10%, #fdf8f0 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #f0f6f3 0%, transparent 55%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 700; letter-spacing: -.01em; }

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px; padding: 12px 24px;
  background: rgba(250, 247, 242, .86);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 10px; font-weight: 750; font-size: 15.5px; }
.brand .logo {
  display: inline-grid; place-items: center;
  width: 26px; height: 26px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 15px; line-height: 1;
  transform: translateY(3px);
}
.brand small { font-weight: 400; color: var(--muted); font-size: 12.5px; }
.top-actions { display: flex; align-items: center; gap: 10px; }

/* ---------- 徽章 / 按钮 ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 11px; border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  border: 1px solid transparent;
}
.badge.free { background: #fdf1e5; color: #a9702b; border-color: #f2ddc3; }
.badge.pro { background: var(--green-soft); color: var(--green); border-color: #cfe6dd; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.btn {
  appearance: none; cursor: pointer;
  border: 1px solid var(--line); background: #fff;
  padding: 8px 14px; border-radius: 10px;
  font-weight: 600; font-size: 13.5px;
  transition: .16s ease;
  white-space: nowrap;
}
.btn:hover { background: #fdfbf8; border-color: #ddd5c8; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #bf4a34; border-color: #bf4a34; }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; padding: 11px 14px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.btn.small { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }

/* ---------- 布局 ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 348px;
  gap: 18px; padding: 20px 24px 64px;
  max-width: 1500px; margin: 0 auto;
  align-items: start;
}
.left { display: grid; grid-template-columns: minmax(0, 1fr); gap: 18px; min-width: 0; }
.left > .card { min-width: 0; }
.right {
  display: grid; gap: 18px;
  position: sticky; top: 74px;
}
@media (max-width: 1060px) {
  .layout {
    display: flex; flex-direction: column; gap: 18px;
    align-items: stretch;
    padding: 14px 14px 64px;
  }
  .left, .right { display: contents; }
  #dropZone { order: 1; }
  #previewCard { order: 2; }
  #paramsCard { order: 3; }
  #statsCard { order: 4; }
  #exportCard { order: 5; }
  .card, #dropZone { scroll-margin-top: 64px; }
}

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.card-head h2 { font-size: 14px; }
.muted { color: var(--muted); font-size: 12.5px; }

/* ---------- 上传区 ---------- */
.drop {
  display: flex; align-items: center; gap: 18px;
  padding: 18px; border-style: dashed;
  transition: .18s ease;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop-icon {
  width: 46px; height: 46px; flex: none; border-radius: 13px;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent); font-size: 22px;
}
.drop-text { flex: 1 1 auto; min-width: 0; }
.drop-text strong { display: block; font-size: 14px; }
.drop-text span { color: var(--muted); font-size: 12.5px; }
.drop-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- 预览 ---------- */
.canvas-wrap {
  position: relative; overflow: auto;
  max-height: 62vh; min-height: 240px; max-width: 100%;
  border-radius: 10px; background: #fbf8f2;
  border: 1px solid var(--line-2);
  display: grid; place-items: center;
  padding: 8px;
}
#previewCanvas { display: block; image-rendering: pixelated; flex: none; }
.hint {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: var(--muted); font-size: 13px; pointer-events: none;
  text-align: center; padding: 20px;
}
.hint.hidden { display: none; }
.seg { display: inline-flex; background: var(--line-2); border-radius: 9px; padding: 2px; }
.seg button {
  border: 0; background: transparent; cursor: pointer;
  padding: 4px 10px; border-radius: 7px; font-size: 12.5px; color: var(--muted);
  font-weight: 600;
}
.seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.08); }

#zoomRange { width: 108px; accent-color: var(--accent); }

/* 悬浮提示 */
.tip {
  position: absolute; z-index: 20; pointer-events: none;
  background: #241f1a; color: #fff; font-size: 12px;
  padding: 5px 9px; border-radius: 7px; white-space: nowrap;
  transform: translate(-50%, -140%); opacity: 0; transition: opacity .1s;
  box-shadow: 0 6px 18px rgba(0,0,0,.22);
}
.tip.show { opacity: 1; }

/* ---------- 统计 ---------- */
.stats-grid {
  display: grid; grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px; margin-bottom: 14px;
}
@media (max-width: 620px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat {
  background: #fcfaf6; border: 1px solid var(--line-2);
  border-radius: 11px; padding: 9px 11px;
}
.stat b { display: block; font-size: 19px; font-weight: 750; letter-spacing: -.02em; }
.stat span { color: var(--muted); font-size: 12px; }

.colors { max-height: 246px; overflow: auto; border-top: 1px solid var(--line-2); }
.color-row {
  display: grid; grid-template-columns: 18px 44px minmax(0, 1fr) auto;
  align-items: center; gap: 8px; padding: 5px 2px;
  border-bottom: 1px solid var(--line-2); font-size: 12.5px;
}
.color-row:last-child { border-bottom: 0; }
.sw {
  width: 15px; height: 15px; border-radius: 4px;
  border: 1px solid rgba(0,0,0,.14); display: block;
}
.color-row .code { font-weight: 650; font-variant-numeric: tabular-nums; }
.color-row .nm { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.color-row .cnt { font-variant-numeric: tabular-nums; font-weight: 650; }
.color-row .bar { grid-column: 2 / -1; height: 3px; border-radius: 2px; background: var(--line-2); overflow: hidden; }
.color-row .bar i { display: block; height: 100%; background: var(--accent); opacity: .55; }

/* ---------- 控件 ---------- */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field-head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin-bottom: 6px; gap: 8px;
}
.field-head label { font-size: 13px; font-weight: 600; }
.field-head .val {
  font-size: 12.5px; font-weight: 700; color: var(--accent);
  font-variant-numeric: tabular-nums;
}
input[type=range] {
  width: 100%; accent-color: var(--accent); height: 18px; margin: 0;
  cursor: pointer;
}
select, input[type=text], input[type=password], textarea {
  width: 100%; padding: 8px 10px; border-radius: 9px;
  border: 1px solid var(--line); background: #fff; outline: none;
  transition: .15s;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.row { display: flex; gap: 8px; align-items: center; }
.row > * { min-width: 0; }

.check {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 11px; border: 1px solid var(--line-2);
  border-radius: 10px; background: #fcfaf6; cursor: pointer;
  font-size: 13px; font-weight: 600;
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; }
.check small { font-weight: 400; color: var(--muted); }

details.adv { border-top: 1px solid var(--line-2); margin-top: 14px; padding-top: 12px; }
details.adv summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--ink-2);
  list-style: none; display: flex; align-items: center; gap: 6px;
}
details.adv summary::-webkit-details-marker { display: none; }
details.adv summary::before { content: "▸"; color: var(--muted); transition: .15s; }
details.adv[open] summary::before { transform: rotate(90deg); }
details.adv > * + * { margin-top: 12px; }

/* ---------- 导出 ---------- */
.export-list { display: grid; gap: 8px; }
.export-note {
  margin-top: 10px; font-size: 12px; color: var(--muted);
  background: #fcfaf6; border: 1px dashed var(--line); border-radius: 9px; padding: 8px 10px;
}

/* ---------- 弹层 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: none; place-items: center; padding: 20px;
  background: rgba(30, 26, 22, .45); backdrop-filter: blur(3px);
}
.modal.open { display: grid; }
.sheet {
  width: min(520px, 100%); max-height: 88vh; overflow: auto;
  background: #fff; border-radius: 18px; padding: 22px;
  box-shadow: 0 30px 80px -20px rgba(0,0,0,.4);
  animation: pop .18s ease;
}
@keyframes pop { from { transform: translateY(8px) scale(.99); opacity: 0; } }
.sheet.wide { width: min(760px, 100%); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 4px; }
.sheet h3 { font-size: 17px; }
.x {
  border: 0; background: transparent; cursor: pointer; font-size: 20px;
  line-height: 1; color: var(--muted); padding: 2px 6px; border-radius: 8px;
}
.x:hover { background: var(--line-2); color: var(--ink); }

.tiers { display: grid; gap: 8px; margin: 16px 0; }
.tier {
  display: flex; align-items: center; gap: 12px;
  border: 1px solid var(--line); border-radius: 12px; padding: 11px 14px;
  cursor: pointer; transition: .15s;
}
.tier:hover { border-color: #d9cfc0; background: #fdfbf8; }
.tier.best { border-color: var(--accent); background: var(--accent-soft); }
.tier .t-name { font-weight: 700; }
.tier .t-desc { color: var(--muted); font-size: 12px; }
.tier .t-price { margin-left: auto; font-weight: 800; font-size: 17px; letter-spacing: -.02em; }
.tier .t-price small { font-size: 11px; font-weight: 600; color: var(--muted); }
.tag-best {
  font-size: 10.5px; font-weight: 700; color: #fff; background: var(--accent);
  padding: 2px 7px; border-radius: 999px; letter-spacing: .02em;
}

.key-box { display: grid; gap: 8px; margin-top: 6px; }
.key-input {
  text-align: center; letter-spacing: .14em; font-weight: 700;
  text-transform: uppercase; font-size: 15px !important;
}
.status-line {
  font-size: 12.5px; padding: 9px 11px; border-radius: 9px;
  background: #fcfaf6; border: 1px solid var(--line-2); color: var(--muted);
}
.status-line.ok { background: var(--green-soft); border-color: #cfe6dd; color: var(--green); font-weight: 600; }
.status-line.err { background: #fdeeec; border-color: #f6d4ce; color: #b8402c; font-weight: 600; }

/* 商家面板 */
.admin-grid { display: grid; grid-template-columns: 1fr 110px; gap: 10px; align-items: end; }
table.keys {
  width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 12px;
  font-variant-numeric: tabular-nums;
}
table.keys th, table.keys td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line-2); }
table.keys th { color: var(--muted); font-weight: 600; font-size: 12px; }
table.keys td.k { font-family: ui-monospace, Menlo, Consolas, monospace; letter-spacing: .04em; }

/* Toast */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 14px);
  background: #241f1a; color: #fff; padding: 10px 18px; border-radius: 999px;
  font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
  transition: .2s ease; z-index: 200; max-width: 88vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

footer.foot {
  text-align: center; color: var(--muted); font-size: 12px;
  padding: 0 24px 34px;
}

@media (max-width: 640px) {
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand { font-size: 14px; white-space: nowrap; gap: 7px; }
  .brand small { display: none; }
  .brand .logo { width: 23px; height: 23px; border-radius: 8px; font-size: 13px; }
  .top-actions { gap: 6px; }
  .badge { font-size: 11px; padding: 3px 8px; }
  .btn { padding: 7px 11px; font-size: 13px; }
  .layout { padding: 14px; gap: 14px; }
  .drop { flex-direction: column; align-items: stretch; text-align: center; padding: 16px; gap: 12px; }
  .drop-icon { margin: 0 auto; }
  .drop-actions { justify-content: center; }
  .drop-text span { overflow-wrap: anywhere; }
  .card { padding: 14px; }
  .canvas-wrap { max-height: 52vh; }
  .card-head { gap: 8px; }
  #zoomRange { width: 76px; }
  .sheet { padding: 18px; }
}

/* ---------- 工具栏 / 色板 / 去除杂色 ---------- */
.brand-name { white-space: nowrap; }
.brand-short { display: none; white-space: nowrap; }

.right { position: static; }

.toolbar {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 10px 0 0; margin-bottom: 10px;
  border-top: 1px dashed var(--line-2);
}
.toolbar button {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 5px 10px; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  cursor: pointer; transition: .15s;
}
.toolbar button:hover { background: #fdfbf8; border-color: #ddd5c8; }
.toolbar button.on { background: #2f2a26; border-color: #2f2a26; color: #fff; }
.toolbar .sep { width: 1px; height: 16px; background: var(--line); margin: 0 2px; }
.paint-ind {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--muted);
}
.paint-ind .sw {
  width: 14px; height: 14px; border-radius: 4px;
  border: 1px solid rgba(0,0,0,.3); display: inline-block; background: transparent;
}
.paint-ind b { color: var(--ink); font-variant-numeric: tabular-nums; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 5px 12px; font-size: 12.5px; font-weight: 600; color: var(--ink-2);
  cursor: pointer; transition: .15s;
}
.chip:hover { background: #fdfbf8; border-color: #ddd5c8; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.chip.muted { color: var(--muted); border-style: dashed; font-weight: 500; }

input.num { width: 92px; flex: 0 0 auto; }

.color-row { cursor: pointer; border-radius: 6px; }
.color-row:hover { background: #fdfaf6; }
.color-row.sel { background: #fdf1e5; }

.clean-meta { margin-top: 12px; font-size: 13px; color: var(--ink-2); }
.clean-meta b { color: var(--accent); font-size: 15px; font-variant-numeric: tabular-nums; }
.clean-tools {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-top: 10px; font-size: 12.5px; color: var(--muted);
}
.clean-tools .num { width: 64px; padding: 5px 8px; }
.clean-list {
  margin-top: 10px; max-height: 44vh; overflow: auto;
  border-top: 1px solid var(--line-2);
}
.clean-row {
  display: grid; grid-template-columns: 22px 46px minmax(0, 1fr) auto 30px;
  align-items: center; gap: 10px; padding: 10px 6px;
  border-bottom: 1px solid var(--line-2); cursor: pointer;
}
.clean-row:hover { background: #fdfaf6; }
.clean-row .sw {
  width: 20px; height: 20px; border-radius: 6px;
  border: 1px solid rgba(0,0,0,.14); display: block;
}
.clean-row .ck { font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.clean-row .cn { color: var(--muted); font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clean-row .cc { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.clean-row .del {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
  font-size: 14px; padding: 3px 6px; border-radius: 6px;
}
.clean-row .del:hover { background: #fbeceb; color: var(--accent); }

#saveImgEl {
  width: 100%; display: block; margin-top: 12px;
  border: 1px solid var(--line); border-radius: 10px;
}

/* ---------- 分块打印 ---------- */
.tile-summary {
  margin-top: 14px; padding: 11px 13px; border-radius: 10px;
  background: #fcfaf6; border: 1px solid var(--line-2);
  font-size: 13px; color: var(--ink-2); line-height: 1.7;
}
.tile-summary b { color: var(--accent); }
#tileMap {
  width: 100%; max-width: 320px; height: auto; display: block;
  margin: 12px auto 0; border-radius: 8px;
}

/* 商家面板：一键发货按钮 */
.send-btn {
  border: 1px solid var(--line); background: #fff; border-radius: 8px;
  padding: 4px 10px; font-size: 12px; font-weight: 700; color: var(--ink-2);
  cursor: pointer; white-space: nowrap; transition: .15s;
}
.send-btn:hover { background: #fdfbf8; border-color: #ddd5c8; }
.send-btn.sent { color: #1a7f4b; border-color: #cfe6dd; background: #f3faf7; }

/* 商家面板：解绑区 */.unbind-box {
  margin-top: 18px; padding-top: 14px;
  border-top: 1px dashed var(--line);
}
#unbindKey {
  font-family: ui-monospace, Menlo, Consolas, monospace;
  letter-spacing: .06em; text-transform: uppercase;
}
#unbindMsg.ok { color: #1a7f4b; font-weight: 600; }
#unbindMsg.err { color: #b8402c; font-weight: 600; }

/* 打印：只留 #printArea，每张 A4 一页 */
#printArea { display: none; }
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff !important; }
  body.printing > *:not(#printArea) { display: none !important; }
  body.printing #printArea { display: block; }
  #printArea img {
    display: block; width: 210mm; height: 297mm;
    page-break-after: always; break-after: page;
  }
  #printArea img:last-child { page-break-after: auto; break-after: auto; }
}

@media (max-width: 640px) {
  .brand-name { display: none; }
  .brand-short { display: inline; font-size: 15px; letter-spacing: -.02em; }
  .toolbar { gap: 6px; }
  .toolbar button { padding: 8px 11px; font-size: 12.5px; min-height: 36px; }
  .btn { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
  .btn.small { min-height: 34px; padding: 6px 12px; }
  .seg button { min-height: 34px; padding: 6px 12px; }
  .chip { min-height: 34px; }
  .paint-ind { width: 100%; margin-left: 0; }
  .clean-row { grid-template-columns: 20px 40px minmax(0, 1fr) auto 26px; gap: 7px; }
}
