:root {
  --bg: #f4f5f7; --panel: #ffffff; --ink: #16181d; --muted: #5d6470; --line: #e2e5ea;
  --brand: #0f9d8a; --brand-ink: #ffffff; --chip: #eef1f4; --warn: #b54708; --okc: #067647;
  --stage: #dfe3e8;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #111317; --panel: #1a1d23; --ink: #eceff3; --muted: #9aa3af; --line: #2b3038; --chip: #252a32; --warn: #fdb022; --okc: #47cd89; --stage: #2a2f37; }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brandmark { font-size: 17px; white-space: nowrap; }
.brandmark b { color: var(--brand); letter-spacing: .04em; }
.sub { margin: 0; color: var(--muted); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.langsel select { padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

.layout { display: grid; grid-template-columns: 280px 1fr 330px; height: calc(100vh - 53px); }
.panel { background: var(--panel); overflow-y: auto; padding: 4px 14px 20px; }
.panel.left { border-right: 1px solid var(--line); }
.panel.right { border-left: 1px solid var(--line); }
.panel section { padding: 10px 0; border-bottom: 1px solid var(--line); }
.panel section:last-child { border-bottom: 0; }
h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 6px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }

.stage { position: relative; background: var(--stage); min-height: 300px; }
#viewport { position: absolute; inset: 0; }
#viewport canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.viewbar { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center;
  background: color-mix(in srgb, var(--panel) 88%, transparent); padding: 6px 10px; border-radius: 12px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.viewbar label { display: flex; gap: 4px; align-items: center; padding: 0 4px; }

button, .btn { cursor: pointer; border: 1px solid var(--line); background: var(--chip); border-radius: 8px; padding: 6px 10px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
button:hover, .btn:hover { border-color: var(--brand); }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); font-weight: 600; }
button.ghost { background: transparent; }
button.icon { padding: 3px 7px; min-width: 28px; }
button:disabled { opacity: .4; cursor: default; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.addgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.addgrid button { flex-direction: column; padding: 8px 4px; font-size: 12px; text-align: center; min-height: 64px; }
.addgrid svg { width: 26px; height: 26px; }

.unitlist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.unitlist li { border: 1px solid var(--line); border-radius: 10px; padding: 8px; cursor: pointer; }
.unitlist li.sel { border-color: var(--brand); box-shadow: 0 0 0 2px color-mix(in srgb, var(--brand) 30%, transparent); }
.unitlist .name { font-weight: 600; }
.unitlist .meta { color: var(--muted); font-size: 12px; }
.unitlist .tools { display: flex; gap: 4px; margin-top: 6px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field > span { color: var(--muted); font-size: 12px; }
.field input:not([type=checkbox]):not([type=file]):not([type=color]), .field select, .field textarea { padding: 7px 9px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); width: 100%; }
.check { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch { width: 30px; height: 30px; border-radius: 8px; border: 2px solid var(--line); padding: 0; position: relative; }
.swatch.on { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }
.swatch small { position: absolute; bottom: -15px; left: 50%; transform: translateX(-50%); font-size: 9px; color: var(--muted); }
.swatches.ral { row-gap: 18px; padding-bottom: 6px; }
input[type=color] { flex: none; width: 30px; height: 30px; padding: 0; border: 2px solid var(--line); border-radius: 8px; background: none; }

.list { display: flex; flex-direction: column; gap: 4px; max-height: 300px; overflow-y: auto; padding-right: 2px; }
.list .item { display: flex; gap: 6px; align-items: center; }
.list .item .n { width: 22px; color: var(--muted); font-size: 12px; text-align: right; }
.list .item select { flex: 1; padding: 4px 6px; border: 1px solid var(--line); border-radius: 6px; background: var(--panel); }
.bar { height: 6px; background: var(--chip); border-radius: 3px; overflow: hidden; margin: 4px 0 2px; }
.bar i { display: block; height: 100%; background: var(--brand); }
.bar.over i { background: var(--warn); }
.muted { color: var(--muted); font-size: 12px; }
.colbox { border: 1px solid var(--line); border-radius: 10px; padding: 8px; margin: 6px 0; }
.cellchips { display: flex; flex-wrap: wrap; gap: 3px; margin: 6px 0; }
.cellchips span { background: var(--chip); border-radius: 5px; padding: 1px 5px; font-size: 11px; }

table.sum { width: 100%; border-collapse: collapse; }
table.sum td { padding: 4px 0; border-bottom: 1px dashed var(--line); }
table.sum td:last-child { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; }
.msg { margin: 8px 0; padding: 7px 9px; border-radius: 8px; font-size: 13px; }
.msg.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); }
.msg.ok { background: color-mix(in srgb, var(--okc) 14%, transparent); color: var(--okc); }
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-top: 10px; }
.actions .primary { grid-column: 1 / -1; padding: 10px; }

dialog { border: 0; border-radius: 14px; padding: 18px; width: min(440px, calc(100vw - 32px)); background: var(--panel); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(80px); background: #16181d; color: #fff; padding: 9px 16px; border-radius: 10px; transition: transform .25s; pointer-events: none; z-index: 10; }
#toast.show { transform: translateX(-50%) translateY(0); }
.printonly { display: none; }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 250px 1fr; grid-template-rows: 1fr auto; }
  .panel.right { grid-column: 1 / -1; border-left: 0; border-top: 1px solid var(--line); }
  .layout { height: auto; }
  .stage { height: 70vh; }
}
@media (max-width: 720px) {
  .sub { display: none; }
  .layout { display: flex; flex-direction: column; }
  .stage { order: -1; height: 62vh; }
  .panel { padding: 4px 16px 16px; }
  .panel.left { border-right: 0; }
}

@media print {
  body > *:not(#printSheet) { display: none !important; }
  #printSheet { display: block; color: #000; }
  #printSheet img { width: 100%; border: 1px solid #ccc; }
  #printSheet table { width: 100%; border-collapse: collapse; margin-top: 10px; }
  #printSheet td, #printSheet th { border: 1px solid #ccc; padding: 4px 6px; text-align: left; font-size: 12px; }
}
