:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --line: #d9dee5;
  --text: #1d2730;
  --muted: #65727f;
  --accent: #0b7285;
  --accent-soft: #e3f4f7;
  --warn: #b7791f;
  --error: #c53030;
  --radius: 8px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text); background: var(--bg);
  display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 6px; padding: 6px 10px; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.small { padding: 3px 8px; font-size: 12px; }
button.danger { color: var(--error); }
input[type=number], input[type=text], input[type=date], select, textarea {
  border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; background: #fff; width: 100%;
}
input[type=number] { font-family: var(--mono); }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

header.top {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
header.top h1 { font-size: 16px; margin: 0 14px 0 0; font-weight: 650; letter-spacing: .2px; }
header.top h1 span { color: var(--muted); font-weight: 400; }
header.top .spacer { flex: 1; }
.menu { position: relative; display: inline-block; }
.menu .dropdown {
  display: none; position: absolute; right: 0; top: 100%; z-index: 20; min-width: 220px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 8px 24px rgba(0,0,0,.12); padding: 6px;
}
.menu.open .dropdown { display: block; }
.dropdown button { display: block; width: 100%; text-align: left; border: none; padding: 7px 10px; border-radius: 6px; }
.dropdown button:hover { background: var(--accent-soft); }
.dropdown hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

main { flex: 1; display: flex; min-height: 0; }
aside.panel {
  width: 400px; flex: 0 0 400px; overflow-y: auto; background: var(--panel); border-right: 1px solid var(--line);
  padding: 10px 12px 60px;
}
section.step { border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 10px; background: #fff; }
section.step > h2 {
  margin: 0; padding: 9px 12px; font-size: 13.5px; font-weight: 600; cursor: pointer; display: flex; align-items: center; gap: 8px; user-select: none;
}
section.step > h2 .num { display: inline-flex; width: 20px; height: 20px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 11.5px; align-items: center; justify-content: center; }
section.step > h2 .chev { margin-left: auto; color: var(--muted); font-size: 11px; transition: transform .15s; }
section.step.collapsed > h2 .chev { transform: rotate(-90deg); }
section.step.collapsed > .body { display: none; }
section.step > .body { padding: 2px 12px 12px; border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
.row.three { grid-template-columns: 1fr 1fr 1fr; }
.row.four { grid-template-columns: 1fr 1fr 1fr 1fr; }
.row.one { grid-template-columns: 1fr; }
label.field { display: block; font-size: 12px; color: var(--muted); }
label.field > span { display: block; margin-bottom: 3px; }
label.check { display: flex; align-items: center; gap: 6px; font-size: 13px; margin-top: 8px; }
.hint { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint code { font-family: var(--mono); font-size: 11.5px; background: var(--bg); padding: 1px 4px; border-radius: 4px; }

.feature {
  border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px 10px; margin-top: 8px; background: #fbfcfd;
}
.feature.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.feature .head { display: flex; align-items: center; gap: 8px; }
.feature .head input[type=text] { flex: 1; }
.feature .head .tag { font-size: 11px; color: var(--muted); white-space: nowrap; }
.addbar { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.addbar select { width: auto; flex: 1; min-width: 90px; }

.warnings { margin-top: 4px; }
.warning { display: flex; gap: 8px; padding: 6px 8px; border-radius: 6px; margin-top: 6px; font-size: 12.5px; background: #fff8e6; border: 1px solid #f3dca3; }
.warning.error { background: #fdecec; border-color: #f3b4b4; }
.warning.info { background: var(--accent-soft); border-color: #bfe3ea; }
.warning .lvl { font-weight: 600; text-transform: uppercase; font-size: 10.5px; padding-top: 2px; }
.warning.warn .lvl { color: var(--warn); } .warning.error .lvl { color: var(--error); } .warning.info .lvl { color: var(--accent); }

.view { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.tabs { display: flex; gap: 2px; padding: 8px 12px 0; border-bottom: 1px solid var(--line); background: var(--panel); align-items: center; }
.tabs button.tab { border: 1px solid transparent; border-bottom: none; border-radius: 8px 8px 0 0; padding: 7px 14px; background: transparent; color: var(--muted); }
.tabs button.tab.active { background: var(--bg); color: var(--text); border-color: var(--line); }
.tabs .tools { margin-left: auto; display: flex; gap: 6px; align-items: center; padding-bottom: 6px; flex-wrap: wrap; }
.tabs .tools label { font-size: 12px; color: var(--muted); display: flex; align-items: center; gap: 4px; }
.tabs .tools select { width: auto; padding: 3px 6px; }
.canvas { flex: 1; position: relative; overflow: hidden; background: var(--bg); }
.canvas.hidden { display: none; }
#preview { width: 100%; height: 100%; display: block; cursor: grab; touch-action: none; }
#preview.dragging { cursor: grabbing; }
#preview .cut { fill: none; stroke: #111; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
#preview .outline { stroke-width: 1.6; }
#preview .hidden { fill: none; stroke: #7a8794; stroke-width: 1; stroke-dasharray: 6 3; vector-effect: non-scaling-stroke; }
#preview .hidden.groove { stroke: #2b8a9e; }
#preview .hidden.feet { stroke: #b7791f; stroke-dasharray: 3 2; }
#preview .lidlabel { font-size: 18px; fill: #aab4bd; }
#preview .handle rect { fill: rgba(11,114,133,.06); stroke: rgba(11,114,133,.55); stroke-width: 1; vector-effect: non-scaling-stroke; cursor: move; }
#preview .handle:hover rect { fill: rgba(11,114,133,.14); }
#preview .handle.selected rect { stroke: var(--accent); stroke-width: 2; fill: rgba(11,114,133,.12); }
#preview .handle text { font-size: 12px; fill: var(--accent); pointer-events: none; }
#preview.nohandles .handle { display: none; }
#preview.nostep .step { display: none; }
#preview.nogroove .groove { display: none; }
.statusbar { position: absolute; left: 10px; bottom: 8px; font-size: 12px; color: var(--muted); font-family: var(--mono); background: rgba(255,255,255,.85); padding: 3px 8px; border-radius: 6px; pointer-events: none; }
.legend { position: absolute; right: 10px; bottom: 8px; font-size: 11.5px; color: var(--muted); background: rgba(255,255,255,.85); padding: 4px 8px; border-radius: 6px; display: flex; gap: 12px; }
.legend i { display: inline-block; width: 18px; border-top: 2px solid #111; vertical-align: middle; margin-right: 4px; }
.legend i.dash { border-top-style: dashed; border-color: #7a8794; }
.legend i.groove { border-top-style: dashed; border-color: #2b8a9e; }

#sheetwrap { position: absolute; inset: 0; overflow: auto; padding: 16px; display: flex; justify-content: center; align-items: flex-start; }
#sheetwrap svg { background: #fff; box-shadow: 0 4px 24px rgba(0,0,0,.15); max-width: 100%; height: auto; }

.empty { color: var(--muted); font-size: 13px; padding: 6px 0; }
.kbd { font-family: var(--mono); font-size: 11px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; background: #fff; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #1d2730; color: #fff; padding: 9px 14px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .2s; pointer-events: none; z-index: 50; }
.toast.show { opacity: 1; }

#print-root { display: none; }
@media print {
  body > *:not(#print-root) { display: none !important; }
  body { background: #fff; display: block; }
  #print-root { display: block; }
  #print-root svg { width: 100%; height: auto; display: block; }
}

.jobstatus { font-size: 12px; color: var(--muted); max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.jobstatus.dirty { color: var(--warn); }
.modal { position: fixed; inset: 0; background: rgba(20,30,40,.45); display: flex; align-items: center; justify-content: center; z-index: 40; }
.modal[hidden] { display: none; }
.modal-card { background: #fff; border-radius: 10px; width: min(900px, 94vw); max-height: 86vh; display: flex; flex-direction: column; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-head { display: flex; gap: 10px; align-items: center; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 15px; flex: 0 0 auto; }
.modal-head input[type=search] { flex: 1; }
.modal-body { overflow: auto; padding: 6px 14px; }
.modal-foot { padding: 8px 14px 12px; border-top: 1px solid var(--line); }
table.jobs { width: 100%; border-collapse: collapse; font-size: 13px; }
table.jobs th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; padding: 8px 6px; border-bottom: 1px solid var(--line); }
table.jobs td { padding: 7px 6px; border-bottom: 1px solid #eef1f4; vertical-align: middle; }
table.jobs tr.current td { background: var(--accent-soft); }
table.jobs td.actions { white-space: nowrap; text-align: right; }
table.jobs td.name { font-weight: 600; cursor: pointer; }
table.jobs td.name:hover { color: var(--accent); }
