:root {
  --bg: #f4f5f6; --panel: #ffffff; --panel2: #f9fafb; --ink: #17191c; --soft: #5c636b; --rule: #dde1e5; --rule2: #eceef0;
  --accent: #d9480f; --accent-ink: #fff; --focus: #1c6ee8; --ok: #2b8a3e; --warn: #9a5b00; --bad: #c92a2a; --tint: #fff4e6;
  --bar: #3d6fb6; --bar2: #5b8bd0; --wait: #9aa4ae; --hdr: 56px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111317; --panel: #181b20; --panel2: #1d2127; --ink: #e8eaed; --soft: #9aa3ad; --rule: #2c3138; --rule2: #23272d;
    --accent: #ff8a3d; --accent-ink: #1b0e05; --focus: #5b9dff; --ok: #69db7c; --warn: #ffc078; --bad: #ff8787; --tint: #2a1e12;
    --bar: #4c7fd0; --bar2: #6a98e0; --wait: #6c7783; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111317; --panel: #181b20; --panel2: #1d2127; --ink: #e8eaed; --soft: #9aa3ad; --rule: #2c3138; --rule2: #23272d;
  --accent: #ff8a3d; --accent-ink: #1b0e05; --focus: #5b9dff; --ok: #69db7c; --warn: #ffc078; --bad: #ff8787; --tint: #2a1e12;
  --bar: #4c7fd0; --bar2: #6a98e0; --wait: #6c7783; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 13px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; }
code { font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; }
h2 { font-size: 15px; margin: 0; font-weight: 650; }
h3 { font-size: 13px; margin: 0 0 6px; font-weight: 650; }
p { margin: 6px 0; }
a { color: var(--focus); }
.muted { color: var(--soft); } .small { font-size: 12px; } .pad { padding: 16px; }
[hidden] { display: none !important; }

.btn { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--rule); border-radius: 5px; padding: 4px 10px; cursor: pointer; white-space: nowrap; }
.btn:hover:not(:disabled) { border-color: var(--soft); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.sm { padding: 3px 9px; } .btn.xs { padding: 1px 7px; font-size: 12px; }
.btn.on { background: var(--tint); border-color: var(--accent); color: var(--accent); }
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.icon { min-width: 28px; }
.linkish { font: inherit; background: none; border: 0; padding: 0; color: var(--focus); cursor: pointer; text-align: left; }
.tag { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 9px; background: var(--rule2); color: var(--soft); margin-left: 4px; white-space: nowrap; }
.tag.ok { color: var(--ok); } .tag.bad { background: color-mix(in srgb, var(--bad) 15%, transparent); color: var(--bad); } .tag.soft { font-style: italic; }
select, input { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--rule); border-radius: 5px; padding: 3px 6px; }
input[type=checkbox], input[type=radio] { accent-color: var(--accent); }
.chk { display: flex; gap: 6px; align-items: center; padding: 3px 0; cursor: pointer; }
.grow { flex: 1; } .sep { width: 1px; align-self: stretch; background: var(--rule); margin: 0 4px; }

/* header */
.top { height: var(--hdr); display: flex; align-items: center; gap: 18px; padding: 0 16px; background: var(--panel); border-bottom: 1px solid var(--rule); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; flex-direction: column; line-height: 1.2; } .brand b { font-size: 15px; }
.tabs { display: flex; gap: 2px; align-self: stretch; }
.tabs a { display: flex; align-items: center; padding: 0 14px; color: var(--soft); text-decoration: none; border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.hstat { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.hstat .k { font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .04em; }
.hstat b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hstat .small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 440px; }
.huser { margin-left: auto; display: flex; gap: 8px; align-items: center; }
#hdr-user { display: flex; gap: 8px; align-items: center; }

main { height: calc(100vh - var(--hdr)); position: relative; }
.loading { position: absolute; inset: 0; display: grid; place-content: center; gap: 10px; color: var(--soft); text-align: center; }
.loading.err { color: var(--bad); } .loading.err span { color: var(--ink); max-width: 600px; }

/* assembly */
.assembly { display: grid; grid-template-columns: 250px minmax(0, 1fr) 430px; height: 100%; }
.assembly > * { min-width: 0; min-height: 0; }
.layers, .bom { background: var(--panel); overflow: auto; padding: 10px 12px; }
.layers { border-right: 1px solid var(--rule); }
.bom { border-left: 1px solid var(--rule); }
.pane-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin: 2px 0 8px; }
.pane-head.sub { margin-top: 14px; border-top: 1px solid var(--rule2); padding-top: 10px; }
.pane-head .scope { font-size: 12px; color: var(--accent); font-weight: 600; text-align: right; }
.layer-list { list-style: none; margin: 0; padding: 0; }
.layer-list li { display: grid; grid-template-columns: 22px 1fr; gap: 0 6px; padding: 5px 4px; border-radius: 5px; align-items: center; }
.layer-list li.node { background: var(--tint); }
.layer-list li.off .lname { color: var(--soft); }
.layer-list .eye { display: flex; align-items: center; cursor: pointer; position: relative; }
.layer-list .eye input { position: absolute; opacity: 0; }
.layer-list .eye i { width: 16px; height: 16px; border-radius: 3px; display: grid; place-items: center; outline: 1px solid var(--rule); font-style: normal; }
.layer-list .eye i::after { content: "✓"; color: #fff; font: 700 12px/1 system-ui, sans-serif; text-shadow: 0 0 2px rgba(0, 0, 0, .55); }
.layer-list li.off .eye i { background: transparent !important; outline: 1.5px solid var(--soft); }
.layer-list li.off .eye i::after { content: ""; }
.row-btns { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.lact { flex-wrap: wrap; }
.layer-list .eye input:focus-visible + i { outline: 2px solid var(--focus); }
.lname { font-weight: 600; } .lname small { display: block; font-weight: 400; color: var(--soft); font-size: 11px; }
.lact { grid-column: 2; display: flex; gap: 4px; margin-top: 3px; }
.layer-back { margin: 0 0 8px; }

.model { position: relative; display: flex; flex-direction: column; background: radial-gradient(ellipse at 50% 40%, var(--panel2), var(--bg)); }
.model canvas { flex: 1; width: 100%; min-height: 0; display: block; touch-action: none; cursor: grab; }
.model canvas:active { cursor: grabbing; }
.model-bar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--rule2); background: color-mix(in srgb, var(--panel) 85%, transparent); }
.model-hint { position: absolute; bottom: 8px; left: 10px; font-size: 11px; color: var(--soft); pointer-events: none; }
.model-tip { position: absolute; pointer-events: none; max-width: 300px; background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 5px 8px; font-size: 12px; display: flex; flex-direction: column; gap: 1px; box-shadow: 0 4px 14px rgba(0,0,0,.15); z-index: 2; }
.model-note { position: absolute; top: 52px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 4px 10px; font-size: 12px; display: flex; gap: 8px; align-items: center; }

.kv { display: grid; grid-template-columns: 112px 1fr; gap: 3px 10px; margin: 6px 0; }
.kv dt { color: var(--soft); font-size: 12px; } .kv dd { margin: 0; overflow-wrap: anywhere; }
.rowcard { border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; margin: 10px 0; background: var(--panel2); }
.rowcard.focus { border-color: var(--focus); }
.rowcard header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rtitle { font-weight: 600; margin: 3px 0; }
.state { font-size: 11px; padding: 0 7px; border-radius: 9px; background: var(--rule2); white-space: nowrap; }
.state.full, .state.units, .state.priced { color: var(--ok); } .state.pending, .state.unpriced { color: var(--warn); } .state.shared { color: var(--focus); }
.op { font: 12px ui-monospace, monospace; margin-right: 4px; }
.warn { color: var(--warn); }
.tblwrap { overflow: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 12px; }
.tbl th { text-align: left; font-weight: 600; color: var(--soft); border-bottom: 1px solid var(--rule); padding: 4px 6px; position: sticky; top: 0; background: var(--panel); }
.tbl td { border-bottom: 1px solid var(--rule2); padding: 4px 6px; vertical-align: top; }
.tbl tfoot td { font-weight: 650; border-top: 1px solid var(--rule); }
.tbl .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tbl .lbl { max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bomt { table-layout: fixed; }
.bomt th:nth-child(1) { width: 112px; } .bomt th:nth-child(3) { width: 66px; } .bomt th:nth-child(4) { width: 112px; }
.bomt td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bomt td:first-child code { font-size: 11px; }
.bomt td .tag { display: block; margin: 1px 0 0; width: fit-content; }
.bomt td:first-child { white-space: normal; }
.tbl .qty { white-space: nowrap; color: var(--soft); }
.bomt tbody tr { cursor: pointer; } .bomt tbody tr:hover { background: var(--panel2); }
.bomt tr.focus { background: color-mix(in srgb, var(--focus) 12%, transparent); }
.bomt tr.m-shared td, .bomt tr.m-included td, .bomt tr.m-not_in_base td, .bomt tr.m-robot td, .bomt tr.m-software td { color: var(--soft); }
.pend { color: var(--warn); }
.subtotal { border-top: 2px solid var(--ink); margin-top: 10px; padding-top: 6px; }
.subtotal .line { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.subtotal b { font-size: 15px; font-variant-numeric: tabular-nums; }

/* plan */
.plan { height: 100%; overflow: auto; padding: 10px 16px 24px; }
.plan-bar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 6px 0 10px; }
.plan-bar label { display: flex; gap: 6px; align-items: center; color: var(--soft); }
.banner { padding: 8px 12px; border-radius: 6px; margin: 6px 0; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; border: 1px solid var(--rule); background: var(--panel); }
.banner.err { border-color: var(--bad); color: var(--bad); } .banner.warn { border-color: var(--warn); } .banner.info { border-color: var(--focus); }
.draftbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; padding: 8px 12px; margin: 6px 0; border-radius: 6px; background: var(--tint); border: 1px solid var(--accent); position: sticky; top: -10px; z-index: 3; }
.draftbar .bad { color: var(--bad); font-weight: 600; }
.summary { display: grid; grid-template-columns: repeat(2, minmax(150px, 1fr)) minmax(300px, 3fr) minmax(150px, 1fr); gap: 10px; margin: 6px 0 10px; }
.summary > div { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; }
.summary .k { font-size: 11px; color: var(--soft); text-transform: uppercase; letter-spacing: .04em; }
.summary b { font-size: 15px; }
.lists { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.lists section { background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; padding: 8px 10px; max-height: 190px; overflow: auto; }
.lists ul { list-style: none; margin: 0; padding: 0; }
.lists li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; border-bottom: 1px solid var(--rule2); }
.lists li > span { white-space: nowrap; font-size: 12px; }
.lists .buy li { flex-direction: column; gap: 0; }

.gwrap { position: relative; }
.gantt { display: grid; grid-template-columns: 470px minmax(0, 1fr); background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; }
.gleft { border-right: 1px solid var(--rule); }
.ghead { height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--rule); font-weight: 600; position: relative; }
.gl, .gr { height: 28px; border-bottom: 1px solid var(--rule2); }
.gl { display: flex; align-items: center; gap: 4px; padding: 0 8px 0 2px; min-width: 0; }
.gl.sec, .gr.sec { height: 24px; background: var(--panel2); }
.gl.sec span { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--soft); padding-left: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gl.sel, .gr.sel { background: color-mix(in srgb, var(--accent) 9%, transparent); }
.gl.cond .tname, .gl.cond .est { color: var(--soft); }
.gl.part { padding-left: 34px; } .gl.part .pname { flex: 1; color: var(--soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 12px; }
.tog { width: 20px; border: 0; background: none; color: var(--soft); cursor: pointer; padding: 0; }
.tname { flex: 1; min-width: 0; text-align: left; border: 0; background: none; color: var(--ink); font: inherit; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0; }
.est { font-variant-numeric: tabular-nums; color: var(--soft); white-space: nowrap; font-size: 12px; }
.tl { overflow-x: auto; overflow-y: hidden; }
.tlin { position: relative; }
.days { padding: 0; }
.dh { position: absolute; top: 0; width: 112px; height: 44px; border-left: 1px solid var(--rule2); padding: 3px 6px; display: flex; flex-direction: column; font-weight: 400; font-size: 12px; }
.dh b { font-weight: 600; } .dh select { font-size: 11px; padding: 0 2px; width: 56px; }
.dh i { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--bar2); }
.dh.over i { background: var(--bad); } .dh.off { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--rule2) 6px 8px); }
.grid { position: absolute; top: 44px; bottom: 0; pointer-events: none; }
.grid i { position: absolute; top: 0; bottom: 0; width: 1px; background: var(--rule2); }
.gr { position: relative; }
.bar { position: absolute; top: 5px; height: 18px; border-radius: 4px; background: var(--bar); color: #fff; font-size: 11px; display: flex; overflow: hidden; cursor: pointer; white-space: nowrap; }
.gantt:not(.ro) .bar { cursor: grab; } .bar:active { cursor: grabbing; }
.bar span { display: grid; place-items: center; min-width: 0; padding: 0 4px; overflow: hidden; }
.bar span + span { background: var(--bar2); }
.bar.wait { background: repeating-linear-gradient(135deg, var(--wait) 0 6px, color-mix(in srgb, var(--wait) 70%, transparent) 6px 12px); color: var(--ink); }
.bar.purchase { background: #7a6cc4; }
.bar.tent { background: transparent; border: 1.5px dashed var(--bar); color: var(--bar); }
.bar.bad, .bar.over { outline: 2px solid var(--bad); }
.bar.done { opacity: .55; }
.bar.sel { box-shadow: 0 0 0 2px var(--accent); }
.bar.pinned::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); }
.bar.part { background: color-mix(in srgb, var(--bar) 45%, transparent); top: 8px; height: 12px; cursor: default; }
.bar .rz { position: absolute; right: 0; top: 0; bottom: 0; width: 7px; cursor: ew-resize; background: rgba(255, 255, 255, .25); }
.noest { position: absolute; left: 8px; top: 6px; font-size: 11px; color: var(--soft); font-style: italic; }

.card { position: absolute; top: 0; right: 0; width: 400px; max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--rule); border-radius: 6px; box-shadow: 0 8px 30px rgba(0, 0, 0, .18); padding: 10px 12px; z-index: 4; }
.card .grp { border-top: 1px solid var(--rule2); padding-top: 8px; margin-top: 8px; }
.card .grp.row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.card summary { cursor: pointer; color: var(--focus); font-weight: 600; }
.parts { list-style: none; margin: 0 0 6px; padding: 0; }
.parts li { display: flex; justify-content: space-between; gap: 8px; align-items: center; padding: 3px 0; }
.inl { display: flex; gap: 4px; align-items: center; } .inl input { width: 70px; }
.stack { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; } .stack label { display: flex; justify-content: space-between; gap: 8px; align-items: center; } .stack input:not([type=radio]) { width: 160px; }
.problems { color: var(--bad); margin: 4px 0; padding-left: 18px; }

dialog { border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); color: var(--ink); padding: 16px 18px; width: 320px; }
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { display: flex; flex-direction: column; gap: 10px; }
dialog label { display: flex; flex-direction: column; gap: 4px; color: var(--soft); }
dialog .row { display: flex; justify-content: flex-end; gap: 8px; }
dialog .err { color: var(--bad); margin: 0; min-height: 1em; }

/* narrow screens: model, then table below */
@media (max-width: 1100px) {
  .top { flex-wrap: wrap; height: auto; padding: 6px 12px; gap: 6px 14px; }
  #hdr-plan { display: none; }
  main { height: auto; }
  .assembly { grid-template-columns: 1fr; grid-template-rows: 62vh auto auto; height: auto; }
  .model { order: 1; } .layers { order: 2; } .bom { order: 3; }
  .layers { border-right: 0; border-bottom: 1px solid var(--rule); max-height: 38vh; }
  .layer-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
  .layer-list li { grid-template-columns: 22px 1fr auto; padding: 3px 4px; }
  .lact { grid-column: 3; margin-top: 0; } .lname small { display: none; }
  .bom { border-left: 0; }
  .summary, .lists { grid-template-columns: 1fr; }
  .gantt { grid-template-columns: 220px minmax(0, 1fr); }
  .card { position: fixed; inset: auto 0 0 0; width: auto; max-height: 70vh; border-radius: 10px 10px 0 0; }
}
@media (max-width: 600px) {
  .tabs a { padding: 0 8px; } .hstat .small { display: none; }
  .gantt { grid-template-columns: 150px minmax(0, 1fr); }
  .gl .est, .gl .tag { display: none; }
}
@media (pointer: coarse) { .btn.xs { padding: 4px 9px; } .bar { height: 22px; top: 3px; } }
