:root {
  --bg: #F6F3EE; --card: #FFFFFF; --ink: #1C1B19; --sub: #6B675F; --line: #E7E3DB; --soft: #EFEBE4;
  --teal: #2A6F6A; --teal-soft: #E3EFEC; --gold: #C98A2B; --rust: #B0492F; --ok: #2E7D4F;
  --r: 10px; --sh: 0 1px 2px rgba(28,27,25,.06), 0 4px 14px rgba(28,27,25,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 "Microsoft JhengHei", "Noto Sans TC", "Noto Sans CJK TC", system-ui, sans-serif; }
button, input, select { font: inherit; color: inherit; }
.muted { color: var(--sub); }
.small { font-size: 12px; }
.warn { color: var(--rust); }
.ok { color: var(--ok); font-weight: 700; }
.miss { color: var(--rust); }
.mono { font-family: Consolas, "SFMono-Regular", Menlo, monospace; font-size: 12.5px; }
.sp { flex: 1; }
.row { display: flex; align-items: center; margin: 10px 0; }
.gap { gap: 8px; }
.wrap { flex-wrap: wrap; }

/* 頂部 */
.top { display: flex; align-items: center; gap: 16px; padding: 10px 20px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.logo { font-weight: 800; letter-spacing: .14em; color: var(--teal); font-size: 15px; }
.ttl { font-weight: 700; font-size: 17px; }
.status { display: flex; gap: 8px; flex: 1; flex-wrap: wrap; min-width: 0; }
.pill { background: var(--soft); border-radius: 999px; padding: 4px 12px; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.pill b { margin-right: 4px; }
.pill .dt { color: var(--teal); font-weight: 700; }
.topAct { display: flex; gap: 6px; }

.tabs { display: flex; gap: 4px; padding: 10px 20px 0; border-bottom: 1px solid var(--line); background: var(--card); overflow-x: auto; }
.tabs button { border: 0; background: none; padding: 10px 16px; border-bottom: 3px solid transparent; cursor: pointer; font-weight: 600; color: var(--sub); white-space: nowrap; }
.tabs button.on { color: var(--teal); border-bottom-color: var(--teal); }
.badge { background: var(--gold); color: #fff; border-radius: 999px; padding: 0 7px; font-size: 11.5px; margin-left: 4px; }
.badge:empty { display: none; }
main { padding: 16px 20px 60px; max-width: 1400px; margin: 0 auto; }

/* 按鈕 */
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 7px 14px; cursor: pointer; font-weight: 600; white-space: nowrap; }
.btn:hover { border-color: #cfc8bb; }
.btn.primary { background: var(--teal); border-color: var(--teal); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.primary:disabled { opacity: .45; cursor: not-allowed; }
.btn.danger { color: var(--rust); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn.big { padding: 10px 20px; font-size: 15px; }
.ico { border: 0; background: none; cursor: pointer; color: var(--sub); padding: 2px 6px; border-radius: 6px; }
.ico:hover { background: var(--soft); color: var(--ink); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh); }
.card h3 { margin: 4px 0 10px; font-size: 15px; }
.card h3 + p { margin-top: -4px; }

/* 篩選 */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 12px; cursor: pointer; font-weight: 600; font-size: 13px; }
.chip span { color: var(--sub); font-weight: 400; margin-left: 2px; }
.chip.on { background: var(--teal); border-color: var(--teal); color: #fff; }
.chip.on span { color: #d5e8e5; }
.chips.small .chip { padding: 2px 8px; font-size: 12px; }
.kwRow { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
.kwBox { position: relative; flex: 1; min-width: 260px; max-width: 520px; }
.kwBox input { width: 100%; padding: 8px 32px 8px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.kwBox input:focus { outline: 2px solid var(--teal-soft); border-color: var(--teal); }
.kwBox .ico { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); }
.cb { display: inline-flex; align-items: center; gap: 5px; cursor: pointer; white-space: nowrap; }
.cb input { accent-color: var(--teal); }

.bulk { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; background: var(--teal-soft); border-radius: 8px; margin-bottom: 10px; position: sticky; top: 58px; z-index: 5; }
.selSummary b { color: var(--teal); }

.tableWrap { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); overflow: auto; max-height: calc(100vh - 290px); min-height: 240px; }
table.items { width: 100%; border-collapse: collapse; }
.items th { position: sticky; top: 0; background: #FBFAF7; text-align: left; font-size: 12.5px; color: var(--sub); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); z-index: 1; white-space: nowrap; }
.items td { padding: 6px 10px; border-bottom: 1px solid var(--soft); vertical-align: middle; }
.items tr.on td { background: #F3F8F6; }
.items tr:hover td { background: #FAF8F4; }
.items tr.on:hover td { background: #EAF3F0; }
.items .ck { width: 34px; text-align: center; }
.items .ck input { width: 16px; height: 16px; accent-color: var(--teal); cursor: pointer; }
.items .num { text-align: right; font-variant-numeric: tabular-nums; width: 70px; }
.items .qty { width: 86px; }
.items .qty input { width: 72px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; text-align: right; }
.items tr.on .qty input { border-color: var(--teal); background: #fff; }
.items .nm { min-width: 260px; }
.items .empty, .empty { text-align: center; padding: 50px 10px; color: var(--sub); }
.bdot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; vertical-align: 1px; }
.bc.ov { color: var(--gold); font-weight: 700; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 4px; background: var(--soft); color: var(--sub); font-weight: 600; font-family: inherit; }

/* 格式 */
.cols2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.fmtForm { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px 10px; margin: 12px 0 6px; }
.fmtForm label, .grid2 label, .grid3 label, .grid4 label, #props label { display: flex; flex-direction: column; font-size: 12px; color: var(--sub); gap: 3px; }
.fmtForm input, .grid2 input, .grid3 input, .grid4 input, #props input:not([type=checkbox]), #props select, select { padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; background: #fff; min-width: 0; }
#fmtSelect { width: 100%; }
.fmtPreview, .detPrev { max-width: 300px; margin: 10px auto 0; }
svg.sheet { width: 100%; display: block; }
svg.sheet .paper { fill: #fff; stroke: #bdb6a8; stroke-width: .6; }
svg.sheet .cell { fill: var(--teal-soft); stroke: var(--teal); stroke-width: .35; }
svg.sheet.over .cell { stroke: var(--rust); }
svg.sheet text { fill: var(--teal); font-family: system-ui, sans-serif; }
.detCard { display: grid; grid-template-columns: 200px 1fr; gap: 16px; margin-top: 14px; padding-top: 14px; border-top: 1px dashed var(--line); }
.detTitle { font-weight: 700; margin-bottom: 6px; }
table.kv { border-collapse: collapse; font-size: 13px; }
table.kv th { text-align: left; color: var(--sub); font-weight: 400; padding: 2px 12px 2px 0; }
#detName { flex: 1; padding: 6px 8px; border: 1px solid var(--line); border-radius: 6px; min-width: 120px; }

/* 版面設計 */
.designer { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 16px; align-items: start; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.stageBox { background: repeating-conic-gradient(#ECE8E1 0 25%, #F4F1EC 0 50%) 0 0/16px 16px; border: 1px solid var(--line); border-radius: var(--r); padding: 20px; display: flex; justify-content: center; align-items: center; min-height: 300px; }
.stage { position: relative; box-shadow: 0 2px 10px rgba(0,0,0,.18); touch-action: none; user-select: none; }
.stageInner { transform-origin: 0 0; position: absolute; left: 0; top: 0; }
.lbl.design .el { cursor: move; outline: 1px dashed rgba(42,111,106,.35); outline-offset: 0; }
.lbl.design .el:hover { outline-color: var(--teal); }
.lbl.design .el.sel { outline: 1.5px solid var(--teal); z-index: 2; }
.lbl .safe { position: absolute; border: .2mm dashed rgba(176,73,47,.35); pointer-events: none; }
.rs { position: absolute; display: none; background: #fff; border: .3mm solid var(--teal); z-index: 3; }
.el.sel .rs { display: block; }
.rs[data-h=se] { width: 1.6mm; height: 1.6mm; right: -.8mm; bottom: -.8mm; cursor: nwse-resize; }
.rs[data-h=e] { width: 1.2mm; height: 2.4mm; right: -.6mm; top: calc(50% - 1.2mm); cursor: ew-resize; }
.rs[data-h=s] { width: 2.4mm; height: 1.2mm; bottom: -.6mm; left: calc(50% - 1.2mm); cursor: ns-resize; }
.dRight { position: sticky; top: 70px; }
.dRight .ptitle { font-weight: 700; margin: 12px 0 6px; font-size: 13px; }
.dRight .ptitle:first-child { margin-top: 0; }
.dRight label.full { margin-bottom: 8px; }
.dRight .chips { margin: -2px 0 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 6px 0; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1.2fr; gap: 8px; align-items: end; margin: 6px 0; }
.grid3 .cb { flex-direction: row !important; font-size: 12px; padding-bottom: 6px; white-space: normal; }
.grid4 { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.grid2 > *, .grid3 > *, .grid4 > *, .fmtForm > * { min-width: 0; }
.grid2 input, .grid3 input, .grid4 input, .fmtForm input, #props input:not([type=checkbox]), #props select { width: 100%; }
#props .cb { flex-direction: row; color: var(--ink); font-size: 13px; margin: 6px 0; }
.seg { display: flex; gap: 2px; align-items: center; background: var(--soft); border-radius: 8px; padding: 3px; margin: 6px 0; flex-wrap: wrap; }
.seg button { border: 0; background: none; min-width: 30px; height: 28px; border-radius: 6px; cursor: pointer; font-size: 14px; }
.seg button.on { background: #fff; color: var(--teal); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.seg .sp { flex: 0 0 8px; }

/* 標籤內容（設計與列印共用，單位 mm） */
.lbl { position: relative; overflow: hidden; background: #fff; color: #000; }
.el { position: absolute; overflow: hidden; }
.el-tx { display: flex; flex-direction: column; line-height: 1.18; word-break: break-all; }
.el-tx .tx { width: 100%; }
.el-tx .tx.clamp { display: -webkit-box; -webkit-box-orient: vertical; overflow: hidden; }
.el-bc svg { display: block; }
.nobc { width: 100%; height: 100%; border: .25mm dashed #c33; color: #c33; display: flex; align-items: center; justify-content: center; font-size: 7pt; }

/* 列印 */
.printLayout { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 16px; align-items: start; }
.pSide { position: sticky; top: 70px; }
.pSide h3 { margin-top: 16px; }
.startGrid { max-width: 220px; }
.startGrid .cell { cursor: pointer; }
.startGrid .cell.skip { fill: #eee; stroke: #ccc; }
.startGrid .cell.startc { fill: var(--gold); stroke: var(--gold); }
.howto { margin-top: 16px; font-size: 12.5px; background: var(--soft); border-radius: 8px; padding: 10px 12px; }
.howto ol { margin: 6px 0 0; padding-left: 18px; }
#printWarn .warn { margin: 10px 0; font-size: 13px; }
.pPreview { display: flex; flex-wrap: wrap; gap: 16px; align-content: flex-start; min-height: 300px; }
.pageWrap { position: relative; }
.page { position: relative; background: #fff; transform-origin: 0 0; box-shadow: 0 1px 6px rgba(0,0,0,.18); overflow: hidden; }
.pno { position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--sub); }
.slot { position: absolute; }
.slot.grid { outline: .15mm dashed #888; }
.slot .tnum { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; font: 700 14pt Arial, sans-serif; color: #999; }

.dropMask { position: fixed; inset: 0; background: rgba(42,111,106,.86); color: #fff; display: none; align-items: center; justify-content: center; text-align: center; font-size: 22px; font-weight: 700; z-index: 100; border: 4px dashed #fff; }
.dropMask small { font-size: 14px; font-weight: 400; }
.dropMask.show { display: flex; }
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 8px; opacity: 0; pointer-events: none; transition: .25s; z-index: 120; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.bad { background: var(--rust); }
.ver { position: fixed; right: 10px; bottom: 6px; font-size: 11px; color: #a9a397; }

@media (max-width: 980px) {
  .cols2, .designer, .printLayout { grid-template-columns: 1fr; }
  .dRight, .pSide { position: static; }
  .fmtForm { grid-template-columns: repeat(2, 1fr); }
  .detCard { grid-template-columns: 1fr; }
  .bulk { top: 0; position: static; }
}
@media (max-width: 600px) {
  .status { order: 3; flex-basis: 100%; }
  .topAct { margin-left: auto; }
  .items td:nth-child(2), .items td:nth-child(3) { white-space: nowrap; }
  main { padding: 12px 16px 60px; }
  .top { padding: 10px 16px; }
  .tabs { padding: 6px 8px 0; }
}

@media print {
  html, body { background: #fff !important; }
  body > *:not(main), main > section:not(#pane-print), .pSide { display: none !important; }
  main { padding: 0 !important; max-width: none !important; }
  #pane-print { display: block !important; }
  .printLayout { display: block !important; }
  .pPreview { display: block !important; }
  .pageWrap { width: auto !important; height: auto !important; break-after: page; page-break-after: always; }
  .pageWrap:last-child { break-after: auto; page-break-after: auto; }
  .page { transform: none !important; box-shadow: none !important; }
  .pno { display: none !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.card h3.mt { margin-top: 20px; }
.tplList { list-style: none; margin: 0; padding: 0; }
.tplList li { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 0; border-top: 1px solid var(--soft); flex-wrap: wrap; }
.tplList .row { margin: 0; }
a.btn { text-decoration: none; display: inline-block; color: var(--ink); }
