:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --line: #e2ded6;
  --ink: #23201c;
  --mute: #7b746a;
  --acc: #b0702c;
  --acc-ink: #ffffff;
  --sel: #2f7df6;
  --soft: #f7f5f1;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 13px;
  color: var(--ink);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body { display: flex; flex-direction: column; overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button {
  border: 1px solid var(--line); background: var(--panel); border-radius: 6px;
  padding: 5px 9px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: #c9c2b6; background: var(--soft); }
button.on { background: #2b2824; color: #fff; border-color: #2b2824; }
button.accent { background: var(--acc); color: var(--acc-ink); border-color: var(--acc); }
button.accent:hover { filter: brightness(1.07); }
button.ico { font-size: 15px; padding: 2px 9px; }
button:disabled { opacity: .4; cursor: default; }
input[type=number], input[type=text], input:not([type]), select {
  border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: #fff; min-width: 0;
}
input:focus, select:focus { outline: 2px solid #c9a06c55; border-color: var(--acc); }

.bar {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 15px; letter-spacing: .2px; }
.brand span { color: var(--mute); font-weight: 400; }
.pname { width: 180px; font-weight: 600; }
.grp { display: flex; gap: 4px; align-items: center; }
.spacer { flex: 1; }
.tabs { display: flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; }
.tabs button { border: 0; border-radius: 0; padding: 6px 14px; }
.lbl { color: var(--mute); font-size: 12px; }

main { flex: 1; display: flex; min-height: 0; position: relative; }
.list {
  width: 210px; background: var(--panel); border-right: 1px solid var(--line);
  overflow-y: auto; padding: 8px 6px;
}
.list h4 { margin: 4px 6px 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--mute); }
.li {
  display: flex; align-items: center; gap: 7px; padding: 5px 6px; border-radius: 6px; cursor: pointer;
  border: 1px solid transparent;
}
.li:hover { background: var(--soft); }
.li.sel { background: #eaf2ff; border-color: #bcd4fb; }
.li img { width: 22px; height: 22px; border-radius: 4px; flex: none; }
.li .n { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.li .d { color: var(--mute); font-size: 11px; font-variant-numeric: tabular-nums; }

.view { flex: 1; position: relative; min-width: 0; }
#canvas-wrap { position: absolute; inset: 0; }
#canvas-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.vtools {
  position: absolute; left: 10px; top: 10px; display: flex; gap: 8px; flex-wrap: wrap;
  pointer-events: none;
}
.vtools .grp { pointer-events: auto; background: #ffffffe8; padding: 4px; border-radius: 8px; border: 1px solid var(--line); }
.vtools button { padding: 3px 8px; }
.vtools select { padding: 2px 4px; }
.sizebadge {
  position: absolute; left: 10px; bottom: 10px; background: #1f1d1ad9; color: #fff;
  padding: 5px 9px; border-radius: 7px; font-variant-numeric: tabular-nums; pointer-events: none;
}
.empty {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); text-align: center;
  color: var(--mute); line-height: 1.6; pointer-events: none; background: #ffffffc0; padding: 16px 22px; border-radius: 10px;
}
.empty b { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

.props {
  width: 290px; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding: 12px;
}
.props h3 { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--mute); margin: 16px 0 7px; font-weight: 600; }
.props h3:first-child { margin-top: 0; }
.props .title { font-size: 15px; font-weight: 600; margin-bottom: 2px; }
.props .sub { color: var(--mute); }
.props input.name { width: 100%; font-weight: 600; font-size: 14px; }
.g3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.g3 label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; color: var(--mute); }
.g3 label.thick { color: var(--acc); font-weight: 600; }
.g3 label.thick input { border-color: #e1c49f; background: #fffaf2; }
.g3 input { width: 100%; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; align-items: center; }
.chips button { padding: 2px 7px; font-size: 12px; }
.chips .lbl { margin-right: 2px; }
.decors { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.decors button {
  padding: 0; aspect-ratio: 1; border-radius: 6px; overflow: hidden; border: 2px solid transparent; position: relative;
  background-size: cover;
}
.decors button.on { border-color: var(--sel); box-shadow: 0 0 0 1px #fff inset; }
.decors button:hover { border-color: #9ab9ef; }
.decname { margin-top: 5px; color: var(--mute); }
.tints { display: grid; grid-template-columns: repeat(9, 1fr); gap: 4px; }
.tints button { padding: 0; aspect-ratio: 1; border-radius: 50%; border: 1px solid #0002; }
.tints button.on { outline: 2px solid var(--sel); outline-offset: 1px; }
.tintrow { display: flex; gap: 6px; align-items: center; margin-top: 7px; color: var(--mute); }
.tintrow input[type=color] { width: 34px; height: 24px; padding: 0; border: 1px solid var(--line); border-radius: 5px; background: none; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 3px 8px; font-size: 12px; }
.seg button + button { border-left: 1px solid var(--line); }
.edgebox { margin-top: 8px; background: var(--soft); border-radius: 8px; padding: 6px; }
.edgebox svg { display: block; width: 100%; height: auto; }
.edgebox .side { cursor: pointer; }
.edgebox .side:hover .vis { stroke-opacity: .6; }
.row { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 7px; align-items: center; }
.actions { display: flex; gap: 6px; margin-top: 18px; flex-wrap: wrap; }
.danger { color: #c0392b; }
.kbd { font-size: 12px; color: var(--mute); line-height: 1.8; }
.kbd b { display: inline-block; min-width: 88px; color: var(--ink); font-weight: 500; }
.note { color: var(--mute); font-size: 12px; line-height: 1.5; }

.status {
  padding: 5px 12px; background: var(--panel); border-top: 1px solid var(--line); color: var(--mute);
  font-variant-numeric: tabular-nums; display: flex; gap: 18px; flex-wrap: wrap;
}

/* список деталей */
.cut { position: absolute; inset: 0; background: var(--bg); overflow: auto; padding: 18px 22px 40px; z-index: 5; }
.cut h2 { margin: 0 0 4px; font-size: 20px; }
.cut .opts { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin: 12px 0 18px; }
.cut .opts label { display: flex; gap: 6px; align-items: center; }
.cut h3 { margin: 22px 0 8px; font-size: 14px; display: flex; gap: 10px; align-items: baseline; }
.cut h3 span { color: var(--mute); font-weight: 400; font-size: 12px; }
.cut table { border-collapse: collapse; width: 100%; background: var(--panel); border: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.cut th, .cut td { border-bottom: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: middle; }
.cut th { font-size: 11px; color: var(--mute); font-weight: 600; background: var(--soft); text-transform: uppercase; letter-spacing: .4px; }
.cut td.num, .cut th.num { text-align: right; }
.cut td.big { font-weight: 600; font-size: 14px; }
.cut td.e span { display: inline-block; min-width: 30px; padding: 1px 5px; border-radius: 4px; font-size: 11px; text-align: center; }
.cut tr:hover td { background: #fbf9f5; }
.cut .sum { margin-top: 18px; display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.cut .card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; }
.cut .card h4 { margin: 0 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--mute); }
.cut .card div { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.cut .emptycut { color: var(--mute); padding: 40px 0; }

.dlg { border: 0; border-radius: 12px; padding: 20px 22px; box-shadow: 0 20px 60px #0004; max-width: 94vw; }
.dlg::backdrop { background: #0004; }
.dlg h2 { margin: 0 0 14px; font-size: 17px; }
.fgrid { display: grid; grid-template-columns: repeat(2, 170px); gap: 10px 14px; }
.fgrid label { display: flex; flex-direction: column; gap: 4px; color: var(--mute); font-size: 12px; }
.fgrid label.chk { flex-direction: row; align-items: center; grid-column: span 2; color: var(--ink); font-size: 13px; }
.hint { color: var(--mute); font-size: 12px; max-width: 360px; line-height: 1.5; }
.dbtns { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.plist { min-width: 360px; max-height: 50vh; overflow: auto; }
.plist .pi { display: flex; gap: 8px; align-items: center; padding: 6px 4px; border-bottom: 1px solid var(--line); }
.plist .pi .n { flex: 1; font-weight: 600; }
.plist .pi .d { color: var(--mute); font-size: 12px; }
.plist .pi.cur .n::after { content: " · открыт"; color: var(--acc); font-weight: 400; }

@media (max-width: 900px) {
  .list { display: none; }
  .props { width: 250px; }
}
@media (max-width: 640px) {
  body { overflow: auto; }
  main { flex-direction: column; }
  .view { min-height: 58vh; }
  .props { width: auto; border-left: 0; border-top: 1px solid var(--line); }
  .pname { width: 130px; }
}
@media print {
  .bar, .list, .view, .props, .status, .cut .opts, .noprint { display: none !important; }
  body, html { overflow: visible; height: auto; background: #fff; }
  main { display: block; }
  .cut { position: static; padding: 0; background: #fff; }
  .cut[hidden] { display: block !important; }
}

/* библиотека декоров */
.dtabs { margin-bottom: 7px; display: flex; }
.dtabs button { flex: 1; }
.libbar select { flex: 1; min-width: 0; }
.libbar input { width: 90px; }
.libbar { margin: 0 0 7px; }
.decors button { background-color: #ece8e1; }
.note.dnd { margin-top: 6px; }
.libcats-list { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 14px; max-height: 44vh; overflow: auto; margin: 8px 0; padding: 8px; background: var(--soft); border-radius: 8px; }
.libcats-list label { display: flex; gap: 6px; align-items: center; font-size: 12px; }
.libcats-list label span { color: var(--mute); margin-left: auto; }
#dlg-lib { width: 560px; }
#dlg-msg { max-width: 460px; }
#dlg-msg .body p { margin: 0 0 8px; }
