:root {
  --bg: #eceef1;
  --panel: #ffffff;
  --line: #dfe3e8;
  --text: #16191d;
  --muted: #6b7380;
  --accent: #0b5cf0;
  --accent-soft: #e8f0ff;
  --warn: #b45309;
  --warn-bg: #fff7e6;
  --danger: #d92d20;
  --danger-bg: #fdecea;
  --ok: #13795b;
  --stage: #2a2d33;
  font-family: "Avenir Next", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-size: 14px; }
body { display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }

.topbar { height: 54px; display: flex; align-items: center; gap: 16px; padding: 0 14px; background: var(--panel); border-bottom: 1px solid var(--line); flex: none; }
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.logo { color: var(--accent); font-size: 20px; }
.file { color: var(--muted); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tools { display: flex; align-items: center; gap: 6px; }
.sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.zoom { min-width: 48px; text-align: center; color: var(--muted); font-variant-numeric: tabular-nums; }

.btn { border: 1px solid var(--line); background: #fff; color: var(--text); border-radius: 8px; padding: 7px 12px; font-weight: 600; }
.btn:hover:not(:disabled) { border-color: #c4cad3; background: #f7f8fa; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { background: #0a4fd0; }
.btn.ghost { background: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn.block { width: 100%; }
.icon { width: 32px; height: 32px; border: 1px solid var(--line); background: #fff; border-radius: 8px; font-size: 17px; line-height: 1; }
.icon:hover:not(:disabled) { background: #f3f5f8; }

main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; background: var(--stage); overflow: hidden; touch-action: none; }
.stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#ov { cursor: default; }
.stage.drag-over::after { content: ''; position: absolute; inset: 12px; border: 3px dashed #8fb3ff; border-radius: 14px; pointer-events: none; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; }
.empty-card { background: #fff; border-radius: 16px; padding: 34px 40px; text-align: center; max-width: 420px; box-shadow: 0 20px 50px rgba(0,0,0,.3); }
.empty-card h2 { margin: 10px 0 6px; font-size: 20px; }
.empty-card p { color: var(--muted); margin: 6px 0 16px; line-height: 1.45; }
.empty-icon { font-size: 40px; color: var(--accent); }
.muted { color: var(--muted); }
.hint { position: absolute; left: 50%; top: 14px; transform: translateX(-50%); background: rgba(16,20,28,.86); color: #fff; padding: 8px 14px; border-radius: 999px; font-weight: 600; pointer-events: none; display: none; white-space: nowrap; }
.hint.show { display: block; }
.perf { position: absolute; right: 10px; bottom: 10px; background: rgba(0,0,0,.7); color: #9ef; font: 12px ui-monospace, Menlo, monospace; padding: 6px 8px; border-radius: 6px; white-space: pre; pointer-events: none; }

.panel { width: 340px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow-y: auto; padding-bottom: 30px; }
.step { padding: 14px 16px 16px; border-bottom: 1px solid var(--line); }
.step h3 { margin: 0 0 10px; font-size: 14px; display: flex; align-items: center; gap: 8px; }
.num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; }
.help { color: var(--muted); margin: 0 0 10px; line-height: 1.45; font-size: 13px; }
.help.small { font-size: 12px; margin: 8px 0 0; }
.meta { color: var(--muted); font-size: 13px; margin-top: 8px; line-height: 1.5; }
label { display: block; font-size: 12px; color: var(--muted); margin-top: 10px; font-weight: 600; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.unit-in { display: flex; align-items: center; gap: 6px; margin-top: 4px; color: var(--muted); font-weight: 500; }
.unit-in input, select { width: 100%; border: 1px solid var(--line); border-radius: 7px; padding: 7px 8px; font: inherit; color: var(--text); background: #fff; font-variant-numeric: tabular-nums; }
select { margin-top: 4px; }
input:focus, select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
input[type=range] { width: 100%; margin-top: 6px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--text); font-weight: 500; font-size: 13px; }
.sub-h { font-size: 12px; font-weight: 700; color: var(--muted); margin: 14px 0 6px; text-transform: uppercase; letter-spacing: .04em; }
.seg { display: flex; background: #f1f3f6; border-radius: 9px; padding: 3px; gap: 3px; margin-top: 8px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 6px 8px; border-radius: 7px; font-weight: 600; color: var(--muted); }
.seg button.on { background: #fff; color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.count-row { display: flex; align-items: center; gap: 8px; }
.stepper { display: flex; align-items: center; gap: 6px; }
.stepper span { min-width: 22px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; }
.models { width: 100%; border-collapse: collapse; margin: 10px 0 6px; font-size: 13px; }
.models th { text-align: left; color: var(--muted); font-weight: 600; font-size: 11px; padding: 0 4px 4px; }
.models td { padding: 2px 3px; }
.models input[type=text] { width: 100%; border: 1px solid transparent; border-radius: 6px; padding: 5px 6px; font: inherit; background: transparent; font-variant-numeric: tabular-nums; }
.models input[type=text]:hover { border-color: var(--line); }
.models input[type=text]:focus { border-color: var(--accent); background: #fff; outline: none; }
.models tr.on { background: var(--accent-soft); }
.models td:first-child { width: 22px; text-align: center; }
.models .del { border: 0; background: none; color: var(--muted); font-size: 15px; }
.msg { font-size: 13px; margin-top: 10px; padding: 8px 10px; border-radius: 8px; line-height: 1.4; }
.msg:empty { display: none; }
.msg.error { background: var(--danger-bg); color: var(--danger); }
.msg.ok { background: #e7f6f0; color: var(--ok); }
.msg.warn { background: var(--warn-bg); color: var(--warn); }

.summary { padding: 14px 16px; }
.summary h4 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.summary table { width: 100%; border-collapse: collapse; font-size: 13px; }
.summary td { padding: 4px 0; border-bottom: 1px dashed var(--line); }
.summary td:last-child { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.summary .neg { color: var(--danger); }
.summary .formula { color: var(--muted); font-size: 12px; margin-top: 8px; line-height: 1.5; }

.modal { position: fixed; inset: 0; background: rgba(10,14,20,.45); display: grid; place-items: center; z-index: 50; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; padding: 24px 30px; border-radius: 14px; min-width: 320px; text-align: center; font-weight: 600; }
.bar { height: 6px; background: #edf0f4; border-radius: 3px; margin-top: 14px; overflow: hidden; }
.bar div { height: 100%; width: 0; background: var(--accent); transition: width .2s; }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #dfe6f5; border-top-color: var(--accent); margin: 0 auto 12px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; align-items: center; }
.toast { background: #1b1f26; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 560px; line-height: 1.4; }
.toast.error { background: var(--danger); }
.toast.warn { background: #92400e; }
.x-btn { flex: none; width: 26px; height: 26px; border: 1px solid var(--line); background: #fff; color: var(--muted); border-radius: 7px; font-size: 16px; line-height: 1; padding: 0; }
.x-btn:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }
.x-btn.on { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.unit-in input.approx { color: var(--muted); font-style: italic; }
.gap-chips { display: flex; gap: 6px; margin: 8px 0 2px 24px; flex-wrap: wrap; }
.gap-chips button { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 600; color: var(--text); }
.gap-chips button::after { content: ' ×'; color: var(--muted); }
.gap-chips button:hover::after { color: var(--danger); }
.gap-chips button.off { color: var(--muted); text-decoration: line-through; background: #f3f5f8; }
.gap-chips button.off::after { content: ' ↺'; text-decoration: none; display: inline-block; margin-left: 3px; }
