:root {
  --bg: #0f1216; --panel: #161a20; --panel2: #1c2128; --line: #2a313b; --text: #dfe5ec; --muted: #8b96a5;
  --accent: #5b8cff; --accent2: #7c5cff; --good: #3ecf8e; --warn: #f0b429; --bad: #ff5d5d;
  --canvas: #0c0f13; --sym: #e0665f; --symfill: #2a1d1d; --wire: #3ecf8e; --ref: #7fb0ff; --val: #b9c2cf; --pin: #9aa4b2;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --strong: #ffffff; --hover-bg: #232a33; --hover-line: #3b4552; --chip: #2a313b; --code-bg: #222932; --pre-bg: #0b0e12;
  --user-bub: #26324a; --user-bub-line: #33456a; --toast-bg: #2a313b; --grid-dot: #2a323d; --pin-name: #c9d1db; --wire-sel: #9dffd0;
  --tool-res: #b8f5d6; --float-bg: #1b1f26ee; --float-line: #333b47; --icon: #cfd6df; --on-bg: #2f6bff33; --view3d: #12161c; --view3d-pcb: #0d1015;
  --shadow: #0009; color-scheme: dark;
}
[data-theme="light"] {
  --bg: #eef1f5; --panel: #ffffff; --panel2: #f2f4f8; --line: #d5dbe3; --text: #1b2330; --muted: #667185;
  --accent: #3b6cf2; --accent2: #6d4ff0; --good: #13905a; --warn: #b7791f; --bad: #d43a3a;
  --canvas: #fbfcfd; --sym: #a8202a; --symfill: #fff7e3; --wire: #0b7a3e; --ref: #1d4fa8; --val: #4a5260; --pin: #5b6472;
  --strong: #111827; --hover-bg: #e8ecf2; --hover-line: #b9c2cf; --chip: #e7ebf1; --code-bg: #eef1f5; --pre-bg: #f4f6f9;
  --user-bub: #e3ebff; --user-bub-line: #c4d3fb; --toast-bg: #ffffff; --grid-dot: #cfd6df; --pin-name: #2b3240; --wire-sel: #10b981;
  --tool-res: #0b7a3e; --float-bg: #ffffffee; --float-line: #d5dbe3; --icon: #3b4352; --on-bg: #3b6cf222; --view3d: #e6eaf0; --view3d-pcb: #dfe4ea;
  --shadow: #0002; color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font: 13px/1.45 var(--font); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
button { background: var(--panel2); border: 1px solid var(--line); border-radius: 6px; padding: 4px 10px; cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--hover-line); background: var(--hover-bg); }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: linear-gradient(135deg, var(--accent), var(--accent2)); border-color: transparent; color: #fff; font-weight: 600; }
button.danger { color: var(--bad); }
input, select, textarea { background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); }

#top { height: 46px; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 15px; color: var(--strong); margin-right: 8px; }
.brand svg { color: var(--accent); }
.menu { display: flex; gap: 6px; align-items: center; }
.spacer { flex: 1; }
#projName { width: 200px; text-align: center; background: transparent; border-color: transparent; font-weight: 600; }
#projName:hover { border-color: var(--line); }
.dd { position: relative; }
.ddm { display: none; position: absolute; top: 100%; left: 0; z-index: 20; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px; min-width: 220px; box-shadow: 0 10px 30px #0008; }
.dd:hover .ddm, .dd:focus-within .ddm { display: block; }
.ddm button { display: block; width: 100%; text-align: left; border: 0; background: none; padding: 6px 10px; }
.ddm button:hover { background: var(--chip); }

main { display: grid; grid-template-columns: 230px 1fr 400px; height: calc(100% - 46px); }
#left, #right { background: var(--panel); display: flex; flex-direction: column; min-height: 0; }
#left { border-right: 1px solid var(--line); }
#right { border-left: 1px solid var(--line); }
.sec-h { padding: 10px 12px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
#partSearch { margin: 0 10px 6px; }
#partList { flex: 1 1 50%; overflow: auto; padding: 0 8px 8px; min-height: 120px; }
.pcat { font-size: 11px; color: var(--muted); margin: 8px 4px 4px; }
.part { display: flex; align-items: center; gap: 8px; width: 100%; margin-bottom: 3px; padding: 3px 6px; text-align: left; background: transparent; border-color: transparent; }
.part svg { width: 38px; height: 24px; flex: none; }
.part:hover { background: var(--panel2); }
#props { flex: 1 1 50%; overflow: auto; padding: 0 12px 12px; border-top: 1px solid var(--line); }
#props label { display: block; font-size: 11px; color: var(--muted); margin: 6px 0; }
#props label input, #props label select, #props label textarea { display: block; width: 100%; margin-top: 3px; color: var(--text); font-size: 13px; }
.ph { font-weight: 700; margin: 10px 0 4px; } .ph.small { font-size: 11px; color: var(--muted); text-transform: uppercase; }
.row { display: flex; gap: 8px; align-items: center; margin-top: 8px; } .row.end { justify-content: flex-end; }
table.pins { width: 100%; border-collapse: collapse; font-size: 12px; }
table.pins td { padding: 2px 4px; border-bottom: 1px solid var(--line); }
.netpins { font-size: 12px; word-break: break-word; }
.help { margin-top: 12px; line-height: 1.8; }
ul.erc { padding-left: 16px; font-size: 12px; } ul.erc .error { color: var(--bad); } ul.erc .warn { color: var(--warn); } ul.erc .info { color: var(--muted); }

#center { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#bar { display: flex; align-items: center; gap: 12px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
#tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 2px; }
.tab { border: 0; background: transparent; padding: 4px 14px; border-radius: 6px; }
.tab.active { background: var(--panel2); color: var(--strong); box-shadow: 0 0 0 1px var(--line); }
.tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tools label { display: flex; align-items: center; gap: 4px; color: var(--muted); font-size: 12px; }
.tools input[type=number] { width: 58px; padding: 3px 5px; }
.chk { display: flex; align-items: center; gap: 4px; cursor: pointer; }
#views { position: relative; flex: 1; min-height: 0; background: var(--canvas); }
#views > svg { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; cursor: default; }
#status { padding: 5px 12px; font-size: 12px; color: var(--muted); background: var(--panel); border-top: 1px solid var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status .good { color: var(--good); } #status .warn { color: var(--warn); } #status .bad { color: var(--bad); }
#ercLink { cursor: pointer; text-decoration: underline dotted; }

/* schematic */
.griddot { fill: var(--grid-dot); }
.comp path, .comp rect, .comp circle { stroke: var(--sym); stroke-width: 1.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.comp .body { fill: var(--symfill); }
.comp .fill { fill: var(--sym); }
.comp .thick { stroke-width: 2.5; }
.comp rect.hit { fill: transparent; stroke: none; cursor: move; }
.comp.sel rect.hit { fill: #5b8cff18; stroke: var(--accent); stroke-width: .8; stroke-dasharray: 3 2; }
.comp.mini path, .comp.mini rect, .comp.mini circle { stroke-width: 2.2; }
text { font-family: var(--font); }
.ref { font-size: 8px; font-weight: 700; fill: var(--ref); }
.val { font-size: 7.5px; fill: var(--val); }
.pinname { font-size: 6px; fill: var(--pin-name); }
.pinnum { font-size: 5px; fill: var(--muted); }
.pinhit { fill: transparent; stroke: none; cursor: crosshair; }
.pinhit:hover, .pinhit.pend { fill: #5b8cff88; stroke: var(--accent) !important; stroke-width: 1 !important; }
.pinhit.open { fill: #ff5d5d22; }
.wire { stroke: var(--wire); stroke-width: 1.5; fill: none; stroke-linejoin: round; }
.hitw { stroke: transparent; stroke-width: 7; fill: none; cursor: pointer; }
.sel .wire { stroke: var(--wire-sel); stroke-width: 2.4; }
.junc { fill: var(--wire); }
.dangle { fill: var(--bad); }
.netlabel, .netname, .pwrtxt { font-size: 7px; font-weight: 700; fill: var(--wire); }
.pwr { cursor: pointer; }
.rubber { stroke: var(--accent); stroke-width: 1.2; stroke-dasharray: 4 3; fill: none; pointer-events: none; }
.empty { fill: var(--muted); font-size: 9px; }

/* footprint preview in the part editor */
#edFp .board { fill: #0d3b22; stroke: #e8e8b0; stroke-width: .15; }
#edFp .pad { fill: #d4a72c; }
#edFp .drill { fill: #0a0d10; }
#edFp .silk { fill: none; stroke: #e9e9e9; stroke-width: .12; opacity: .85; }
/* copilot */
.cp-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.cp-head .title { font-weight: 700; font-size: 14px; }
.spark { color: var(--accent2); }
.cp-ctrl { display: flex; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.seg { display: flex; background: var(--bg); border-radius: 8px; padding: 2px; }
.seg button { border: 0; background: transparent; padding: 4px 10px; border-radius: 6px; }
.seg button.on { background: var(--panel2); color: var(--strong); box-shadow: 0 0 0 1px var(--line); }
#modelSel { flex: 1; min-width: 0; }
#chat { flex: 1; overflow: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.welcome { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }
.welcome .wt { font-size: 18px; font-weight: 700; }
.sugg { text-align: left; padding: 8px 10px; border-radius: 8px; line-height: 1.35; }
.msg.user { align-self: flex-end; max-width: 88%; }
.msg.user .bub { background: var(--user-bub); border: 1px solid var(--user-bub-line); padding: 8px 10px; border-radius: 10px 10px 2px 10px; }
.msg .meta { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: 11px; color: var(--muted); margin-top: 3px; }
.msg.ai .meta { justify-content: flex-start; }
.mtag { text-transform: uppercase; font-size: 10px; letter-spacing: .06em; padding: 0 5px; border-radius: 4px; background: var(--chip); }
.mtag.agent { color: var(--accent); } .mtag.plan { color: var(--warn); } .mtag.ask { color: var(--good); }
.restore { font-size: 11px; padding: 0 6px; background: none; border-color: transparent; color: var(--muted); }
.restore:hover { color: var(--text); }
.msg.ai { max-width: 100%; }
.md p { margin: 4px 0 8px; } .md h3, .md h4, .md h5 { margin: 12px 0 4px; } .md ul, .md ol { margin: 4px 0 8px; padding-left: 20px; }
.md code { background: var(--code-bg); padding: 1px 4px; border-radius: 4px; font-size: 12px; }
.md pre { background: var(--pre-bg); padding: 8px; border-radius: 6px; overflow: auto; }
.tw { overflow-x: auto; } .md table { border-collapse: collapse; font-size: 12px; margin: 6px 0; }
.md th, .md td { border: 1px solid var(--line); padding: 3px 6px; text-align: left; } .md th { background: var(--panel2); }
details.tool { border: 1px solid var(--line); border-radius: 7px; margin: 4px 0; background: var(--bg); font-size: 12px; }
details.tool summary { padding: 4px 8px; cursor: pointer; list-style: none; display: flex; gap: 6px; align-items: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
details.tool .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); flex: none; }
details.tool.ok .dot { background: var(--good); } details.tool.err .dot { background: var(--bad); } details.tool.run .dot { background: var(--warn); animation: pulse 1s infinite; }
details.tool pre { margin: 0; padding: 6px 8px; border-top: 1px solid var(--line); max-height: 220px; overflow: auto; white-space: pre-wrap; word-break: break-word; font-size: 11px; }
details.tool pre.res { color: var(--tool-res); } details.tool.err pre.res { color: var(--bad); }
.exec { margin-top: 6px; background: linear-gradient(135deg, var(--accent), var(--accent2)); color: #fff; border: 0; font-weight: 600; }
.msg.err { color: var(--bad); background: #ff5d5d14; border: 1px solid #ff5d5d55; padding: 8px; border-radius: 8px; }
.typing { display: flex; gap: 4px; padding: 6px 0; } .typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1s infinite; }
.typing span:nth-child(2) { animation-delay: .2s; } .typing span:nth-child(3) { animation-delay: .4s; }
@keyframes pulse { 50% { opacity: .25; } }
.cp-input { border-top: 1px solid var(--line); padding: 10px 12px; }
.cp-input textarea { width: 100%; resize: vertical; min-height: 60px; }
.cp-input .row { justify-content: space-between; margin-top: 6px; }
#modeHint { font-size: 11px; margin-top: 4px; }
.cp-chips { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.chip { padding: 3px 8px; font-size: 12px; border-radius: 999px; }
.chip.on { border-color: var(--accent); color: var(--strong); background: var(--on-bg); }
#btnFolder.on { border-color: var(--good); color: var(--good); }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; }
.attach-list:not(:empty) { margin-bottom: 6px; }
.att { display: inline-flex; align-items: center; gap: 6px; max-width: 100%; padding: 3px 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel2); font-size: 12px; }
.att img { width: 28px; height: 28px; object-fit: cover; border-radius: 4px; }
.att .an { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.att .x { border: 0; background: none; padding: 0 2px; color: var(--muted); cursor: pointer; }
.att.err { border-color: var(--bad); color: var(--bad); }
.att .spin { width: 12px; height: 12px; }
.msg .atts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; margin-top: 4px; }
.msg .atts img { max-width: 160px; max-height: 120px; border-radius: 6px; border: 1px solid var(--line); cursor: zoom-in; }
.cp-input.drop { outline: 2px dashed var(--accent); outline-offset: -4px; }
.ctx { display: flex; align-items: center; gap: 8px; margin-top: 6px; font-size: 11px; flex-wrap: wrap; }
.ctx-track { flex: 1; min-width: 60px; height: 6px; border-radius: 3px; background: var(--panel2); overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.ctx-fill { height: 100%; width: 0; background: var(--good); transition: width .3s; }
.ctx-fill.mid { background: var(--warn, #e0a030); } .ctx-fill.high { background: var(--bad); }
.ctx .chip { font-size: 11px; padding: 2px 7px; }
.msg.summary { align-self: stretch; max-width: 100%; }
.msg.summary details { border: 1px dashed var(--line); border-radius: 8px; padding: 6px 8px; }
.msg.summary summary { cursor: pointer; color: var(--muted); }
.msg .atts img.big { max-width: 100%; max-height: none; cursor: zoom-out; }
.msg.info { color: var(--muted); font-size: 12px; }
#btnSend.stop { background: var(--bad); }

/* modal & toast */
#modal, .modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 50; }
.dlg { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; width: min(560px, 94vw); max-height: 90vh; overflow: auto; }
.dlg h2 { margin: 0 0 4px; } .dlg fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 10px 0; }
.dlg legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.dlg label { display: block; font-size: 12px; color: var(--muted); margin: 6px 0; }
.dlg label input:not([type=checkbox]) { display: block; width: 100%; margin-top: 3px; color: var(--text); }
.dlg label.chk { display: flex; color: var(--text); }
.dlg .good { color: var(--good); } .dlg .bad { color: var(--bad); }
.presets { display: flex; flex-wrap: wrap; gap: 4px; } .presets button { font-size: 11px; padding: 2px 8px; }
#toast { position: fixed; bottom: 40px; left: 50%; transform: translate(-50%, 20px); background: var(--toast-bg); border: 1px solid var(--hover-line); box-shadow: 0 6px 20px var(--shadow); padding: 8px 14px; border-radius: 8px; opacity: 0; transition: .2s; pointer-events: none; z-index: 60; max-width: 70vw; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 1100px) { main { grid-template-columns: 190px 1fr 330px; } }
@media (max-width: 800px) {
  html, body { overflow: auto; }
  main { grid-template-columns: 1fr; grid-template-rows: auto 60vh auto; height: auto; }
  #left { max-height: 260px; } #right { height: 80vh; }
  .menu button:not(#btnUndo):not(#btnRedo), #projName { display: none; }
}

/* database parts */
.dbpart { display: block; width: 100%; text-align: left; margin-bottom: 4px; padding: 6px 8px; background: var(--bg); }
.dbpart .dbt { display: flex; justify-content: space-between; gap: 6px; font-size: 12px; overflow: hidden; }
.dbpart .dbt b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbpart .dbs { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dbpart .good { color: var(--good); } .dbpart .bad { color: var(--bad); }
.badge { font-size: 10px; padding: 0 5px; border-radius: 4px; flex: none; } .badge.basic { background: #3ecf8e22; color: var(--good); }
.dberr { font-size: 11px; color: var(--warn); margin: 2px 4px 6px; }
.small { font-size: 11px; margin: 2px 4px; }
.spin { display: inline-block; width: 9px; height: 9px; border: 2px solid var(--muted); border-top-color: transparent; border-radius: 50%; animation: rot .8s linear infinite; vertical-align: -1px; }
@keyframes rot { to { transform: rotate(360deg); } }
.attrib { font-size: 10px; color: var(--muted); padding: 4px 12px 8px; line-height: 1.4; } .attrib a { color: var(--muted); }
.lcscinfo { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 6px 0; }
.lcscinfo a { color: var(--accent); }

/* design rules, DRC, routing */
.rgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 16px; margin: 8px 0; }
.rgrid label, .dlg .rgrid label { display: flex; align-items: center; gap: 6px; margin: 2px 0; color: var(--text); font-size: 12px; }
.dlg .rgrid label input:not([type=checkbox]), .dlg .rgrid select { width: 86px !important; margin: 0 0 0 auto; display: inline-block; }
.rgrid label span { color: var(--muted); width: 22px; }
.rh { grid-column: 1 / -1; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-top: 8px; }
#rNets .nr { display: flex; gap: 8px; align-items: center; padding: 3px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
#rNets .nr b { flex: 1; }
#routeBusy { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; display: flex; gap: 8px; align-items: center; box-shadow: 0 6px 20px #0008; z-index: 5; font-size: 12px; }
.drcmark circle { fill: #ff3b3b33; stroke: #ff3b3b; stroke-width: .12; }
.drcmark path { stroke: #ff3b3b; stroke-width: .14; }
.drcmark.warning circle { fill: #f0b42922; stroke: #f0b429; } .drcmark.warning path { stroke: #f0b429; }
ul.drc li { cursor: pointer; } ul.drc li:hover { text-decoration: underline; }
/* knowledge */
#knowFiles { margin-top: 8px; max-height: 50vh; overflow: auto; font-size: 12px; }
#knowFiles .kf { display: flex; justify-content: space-between; gap: 8px; padding: 3px 6px; border-bottom: 1px solid var(--line); }
#btnKnow.on { border-color: var(--good); color: var(--good); }
/* projects & part editor */
.row-h { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sec-h.row-h button { font-size: 11px; padding: 1px 8px; text-transform: none; letter-spacing: 0; }
#saveState { font-size: 12px; white-space: nowrap; } #saveState.good { color: var(--good); } #saveState.warn { color: var(--warn); } #saveState.bad { color: var(--bad); }
.dlg.wide { width: min(720px, 96vw); }
#projList { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; }
.proj { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.proj.cur { border-color: var(--accent); }
.proj .pinfo { flex: 1; min-width: 0; } .proj .pname { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj .pact { display: flex; gap: 4px; flex: none; }
.dlg .bad { color: var(--bad); } .warn { color: var(--warn); }
.dlg.editor { width: min(1180px, 98vw); height: min(860px, 96vh); display: flex; flex-direction: column; gap: 8px; }
.edmeta { display: grid; grid-template-columns: 2fr 1fr 2fr; gap: 10px; }
.edmeta label { margin: 0; }
.edbody { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(300px, 2fr) 3fr; gap: 12px; }
.edcol { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.edpins { flex: 1; min-height: 120px; overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.edpins table { width: 100%; border-collapse: collapse; font-size: 12px; }
.edpins th { position: sticky; top: 0; background: var(--panel2); text-align: left; padding: 4px; font-weight: 600; }
.edpins td { padding: 2px 3px; border-top: 1px solid var(--line); }
.edpins input, .edpins select { width: 100%; padding: 2px 5px; font-size: 12px; }
.edpins td:first-child { width: 64px; } .edpins td:nth-child(3) { width: 54px; }
.edpins .pbtn { white-space: nowrap; width: 84px; } .edpins .pbtn button { padding: 0 6px; font-size: 11px; }
input.warnin { border-color: var(--warn); }
.edsym { height: 34%; min-height: 140px; background: var(--canvas); border-radius: 8px; border: 1px solid var(--line); }
.edfp { flex: 1; min-height: 220px; background: var(--canvas); border-radius: 8px; border: 1px solid var(--line); cursor: crosshair; user-select: none; }
.edaxis { stroke: var(--muted); stroke-opacity: .4; fill: none; }
.pad.padsel { fill: #7fb0ff; stroke: #fff; stroke-width: .04; }
.pad.padorphan { fill: #a0782a; }
.padnum { fill: #1a1a1a; font-weight: 700; }
.edpad { display: flex; flex-wrap: wrap; gap: 6px; align-items: flex-end; font-size: 12px; min-height: 44px; }
.edpad label { display: flex; flex-direction: column; font-size: 11px; color: var(--muted); }
.edpad input, .edpad select { width: 70px; padding: 3px 5px; }
.libpart { display: flex; align-items: center; gap: 4px; }
.libpart .dbpart { flex: 1; min-width: 0; margin-bottom: 0; }
.libpart .mini-btn { padding: 2px 6px; font-size: 11px; }
@media (max-width: 800px) { .edbody { grid-template-columns: 1fr; overflow: auto; } .edmeta { grid-template-columns: 1fr 1fr; } .dlg.editor { height: 96vh; } }
.dlg .edpad label input, .dlg .edpad label select { width: 72px; display: block; }
.dlg .edmeta label input { width: 100%; }

.edgebtns button.on { border-color: var(--accent); color: var(--strong); background: var(--on-bg); }
#gbList { max-height: 45vh; overflow: auto; }
/* enclosure */
#encView { position: absolute; inset: 0; background: var(--view3d); }
#encView canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.encinfo { position: absolute; left: 10px; bottom: 8px; background: var(--float-bg); border: 1px solid var(--float-line); padding: 5px 10px; border-radius: 6px; font-size: 12px; pointer-events: none; }
.encmsg { position: absolute; top: 40%; left: 50%; transform: translate(-50%, -50%); color: var(--muted); font-size: 14px; display: none; text-align: center; max-width: 80%; }
.encgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8px; }
.encgrid label { margin: 3px 0 !important; }
ul.cutl { padding-left: 4px; list-style: none; font-size: 12px; margin: 4px 0; }
ul.cutl li { padding: 2px 0; }
#encTools button.on { border-color: var(--accent); color: var(--strong); background: var(--on-bg); }
/* PCB editor */
#pcbSvg { background: #000; }
.tsep { width: 1px; align-self: stretch; background: var(--line); margin: 0 4px; }
#pcbOverlay { position: absolute; inset: 0; pointer-events: none; }
.fpanel { position: absolute; pointer-events: auto; background: var(--float-bg); border: 1px solid var(--float-line); border-radius: 8px; box-shadow: 0 6px 20px var(--shadow); font-size: 12px; user-select: none; }
.fph { display: flex; align-items: center; justify-content: space-between; gap: 6px; padding: 5px 8px; font-weight: 700; font-size: 11px; color: var(--muted); border-bottom: 1px solid var(--float-line); text-transform: uppercase; letter-spacing: .05em; }
#pcbPalette { top: 10px; left: 10px; display: flex; flex-direction: column; width: 64px; }
#pcbPalette .fph { justify-content: center; font-size: 9px; padding: 4px; }
.tbtn { display: flex; align-items: center; gap: 4px; margin: 3px; padding: 5px 6px; background: transparent; border-color: transparent; }
.tbtn svg { width: 20px; height: 20px; fill: var(--icon); stroke: var(--icon); }
.tbtn span { font-size: 10px; color: var(--muted); font-weight: 700; }
.tbtn.on { background: var(--on-bg); border-color: var(--accent); }
.tbtn.on svg { fill: var(--accent); stroke: var(--accent); }
#layerPanel { top: 10px; right: 10px; width: 236px; }
.lq button { font-size: 10px; padding: 0 5px; margin-left: 2px; text-transform: none; letter-spacing: 0; }
.lrow { display: flex; align-items: center; gap: 6px; padding: 3px 8px; cursor: pointer; }
.lrow:hover { background: #ffffff0d; }
.lrow.act { background: #ffffff14; }
.lrow.off .lname { color: #6b7380; }
.lact { width: 12px; color: #fff; font-size: 11px; }
.lsw { width: 16px; height: 12px; border-radius: 2px; border: 1px solid #0008; position: relative; overflow: hidden; cursor: pointer; flex: none; }
.lsw input { position: absolute; inset: -4px; opacity: 0; cursor: pointer; }
.lname { flex: 1; font-family: ui-monospace, Consolas, monospace; font-size: 11.5px; }
.leye { width: 18px; text-align: center; font-size: 12px; }
.ldim { display: flex; gap: 6px; align-items: center; padding: 5px 8px; border-top: 1px solid var(--float-line); color: var(--muted); font-size: 11px; }
#pcbCoord { position: absolute; left: 10px; bottom: 8px; pointer-events: none; background: #000a; padding: 3px 8px; border-radius: 6px; font-size: 11px; color: #ccd; font-family: ui-monospace, Consolas, monospace; max-width: calc(100% - 270px); }
#pcbCoord .bad { color: #ff6b6b; font-weight: 700; }
#pcbSvg .trk { stroke-linecap: round; cursor: pointer; }
#pcbSvg .pad, #pcbSvg .via { cursor: pointer; }
#pcbSvg .hl { filter: brightness(1.8) saturate(1.2); }
#pcbSvg .fphit { fill: transparent; cursor: move; }
#pcbSvg .selbox { fill: none; stroke: #ffffff; stroke-width: 0.08; stroke-dasharray: 0.3 0.2; pointer-events: none; }
#pcbSvg .selline { fill: none; stroke: #ffffff; opacity: 0.35; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
#pcbSvg .rprev { fill: none; stroke-linecap: round; stroke-linejoin: round; opacity: 0.85; pointer-events: none; }
#pcbSvg #pcbLive { pointer-events: none; }
@media (max-width: 800px) { #layerPanel { width: 180px; } #pcbPalette { width: 54px; } }
#layerPanel .fph .ltitle { cursor: pointer; }
#layerPanel.collapsed #layerRows, #layerPanel.collapsed .ldim { display: none; }
#pcbPalette.collapsed .tbtn span { display: none; }
.edgebtns button { flex: 1; padding: 3px 4px; font-size: 11px; }
#updBar { position: fixed; top: 54px; left: 50%; transform: translateX(-50%); z-index: 80; background: #2f6bff; color: #fff; padding: 8px 14px; border-radius: 8px; box-shadow: 0 6px 20px #0008; font-weight: 600; }
#updBar button { margin-left: 10px; background: #fff; color: #1b2a55; border: 0; font-weight: 700; }
#pcb3dView { position: absolute; inset: 0; background: var(--view3d-pcb); z-index: 3; }
#pcb3dView canvas { display: block; width: 100%; height: 100%; cursor: grab; }
.p3bar { position: absolute; top: 10px; left: 10px; display: flex; gap: 4px; z-index: 2; }
.p3bar button, .p3bar select { font-size: 12px; padding: 3px 9px; }
.p3bar button.on, #btn3d.on { border-color: var(--accent); color: var(--strong); background: var(--on-bg); }
.part .jlc { margin-left: auto; font-style: normal; font-size: 9.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; }

/* theme switch */
#btnTheme { min-width: 34px; }
.lrow:hover { background: var(--on-bg); } .lrow.act { background: var(--chip); }
.lrow.off .lname { color: var(--muted); }
.lact { color: var(--strong); }
[data-theme="light"] #pcbCoord { background: #000c; }
[data-theme="light"] .rgrid label, [data-theme="light"] .dlg label.chk { color: var(--text); }

/* custom 3D enclosure: script editor panel */
.enc-code { position: absolute; top: 0; right: 0; bottom: 0; width: min(46%, 560px); display: flex; flex-direction: column; background: var(--panel); border-left: 1px solid var(--line); z-index: 2; }
.enc-code.hidden { display: none; }
.ecp-head { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ecp-head b { margin-right: auto; }
.ecp-head select { max-width: 180px; }
#encCode { flex: 1; min-height: 120px; resize: none; border: 0; border-radius: 0; padding: 8px 10px; font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--bg); color: var(--text); white-space: pre; overflow: auto; tab-size: 2; }
.ecp-out { max-height: 38%; overflow: auto; padding: 6px 10px; border-top: 1px solid var(--line); font-size: 12px; }
.ecp-out pre { white-space: pre-wrap; font-size: 11px; margin: 4px 0; }
.ecp-out .ecp-help { max-height: none; }
.ecp-out table td { padding: 1px 6px 1px 0; }
.encmodeseg { margin: 4px 0 8px; display: inline-flex; }
#encMode { margin-right: 6px; }
@media (max-width: 700px) { .enc-code { width: 100%; top: 40%; border-left: 0; border-top: 1px solid var(--line); } }

/* documentation tab: datasheet preview */
#docView { position: absolute; inset: 0; overflow: auto; background: var(--view3d, #1b1f27); }
.docstatus { position: sticky; top: 0; z-index: 2; text-align: center; font-size: 12px; color: var(--muted); padding: 4px; }
.docstatus:empty { display: none; }
.docpages { padding: 12px 16px 40px; display: flex; flex-direction: column; align-items: center; gap: 18px; }
.dpage { background: #fff; color: #1f2937; width: min(794px, 100%); padding: 32px 40px; box-shadow: 0 4px 24px #0006; border-radius: 3px; font: 13px/1.5 system-ui, sans-serif; border-top: 5px solid #2563eb; }
.dpage h1 { font-size: 28px; margin: 18px 0 4px; color: #111827; }
.dpage h2 { font-size: 17px; margin: 22px 0 10px; color: #111827; border-bottom: 2px solid #2563eb; display: inline-block; padding-bottom: 2px; }
.dpage h3 { font-size: 13.5px; margin: 14px 0 6px; color: #1f2937; }
.dpage .dsub { font-size: 16px; color: #4b5563; margin-bottom: 12px; }
.dpage .dhead { display: flex; justify-content: space-between; font-size: 11px; color: #6b7280; border-bottom: 1px solid #e5e7eb; padding-bottom: 4px; }
.dpage .muted { color: #6b7280; }
.dpage ul { margin: 4px 0 8px 18px; padding: 0; }
.dimg { display: block; max-width: 100%; max-height: 520px; margin: 8px auto; border-radius: 3px; }
.dimg.hero { max-height: 380px; }
.dgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.dgrid .dimg { max-height: 300px; }
.dcap { display: flex; justify-content: space-around; font-size: 11px; color: #6b7280; margin-bottom: 6px; }
.dtab { width: 100%; border-collapse: collapse; font-size: 12px; margin: 4px 0 10px; }
.dtab th { background: #2563eb; color: #fff; text-align: left; padding: 4px 6px; font-weight: 600; }
.dtab td { border-bottom: 1px solid #e5e7eb; padding: 3px 6px; vertical-align: top; }
.dtab tr:nth-child(even) td { background: #f8fafc; }
.dfield { display: block; margin: 6px 0; font-size: 12px; }
.dfield input, .dfield textarea { width: 100%; box-sizing: border-box; margin-top: 2px; }
@media (max-width: 700px) { .dpage { padding: 18px 16px; } .dgrid { grid-template-columns: 1fr; } }
/* datasheet tables: fixed layout, long part numbers wrap, never wider than the page */
.dpage { overflow: hidden; }
.dtab { table-layout: fixed; }
.dtab th, .dtab td { overflow-wrap: anywhere; word-break: break-word; }
@media (max-width: 700px) { .dtab { font-size: 10.5px; } .dtab th, .dtab td { padding: 3px 4px; } }

/* schematic drawing frame + title block, sheet tabs */
#schSvg .frame { pointer-events: none; }
#schSvg .frame .fo, #schSvg .frame .fi, #schSvg .frame .tb { fill: none; stroke: var(--frame, #8a94a6); stroke-width: 1; }
#schSvg .frame .fo { stroke-width: 1.6; }
#schSvg .frame .ft { stroke: var(--frame, #8a94a6); stroke-width: 0.7; }
#schSvg .frame text { font-family: system-ui, sans-serif; fill: var(--frame-text, #b9c1cf); }
#schSvg .frame .fz { font-size: 8px; }
#schSvg .frame .tbl { font-size: 6px; opacity: .75; }
#schSvg .frame .tbv { font-size: 10px; }
#schSvg .frame .tbt { font-size: 16px; font-weight: 700; }
[data-theme="light"] #schSvg .frame { --frame: #555; --frame-text: #222; }
.sheetbar { position: absolute; left: 8px; bottom: 30px; display: flex; gap: 4px; flex-wrap: wrap; z-index: 3; max-width: calc(100% - 16px); }
.sheetbar button { padding: 3px 9px; font-size: 12px; border-radius: 6px 6px 0 0; background: var(--panel2); }
.sheetbar button.on { border-color: var(--accent); color: var(--strong); background: var(--on-bg); }
.sheetbar .sfr { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 3px; margin-left: 6px; }

/* box selection + right-click menu */
.boxsel { fill: #5b8cff22; stroke: var(--accent); stroke-dasharray: 4 3; pointer-events: none; }
#schSvg .boxsel { stroke-width: 0.8; }
#pcbSvg .boxsel { stroke-width: 0.06; stroke-dasharray: 0.3 0.2; fill: #ffffff14; stroke: #fff; }
.ctxmenu { position: fixed; z-index: 1000; min-width: 210px; padding: 4px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px #0006; font-size: 13px; }
.ctxmenu button { display: flex; width: 100%; justify-content: space-between; gap: 16px; align-items: center; border: 0; background: none; padding: 6px 10px; border-radius: 5px; text-align: left; color: var(--text); }
.ctxmenu button:hover:not([disabled]) { background: var(--accent); color: #fff; }
.ctxmenu button[disabled] { opacity: .4; cursor: default; }
.ctxmenu kbd { font: 11px system-ui; color: var(--muted); }
.ctxmenu button:hover:not([disabled]) kbd { color: #fff; }
.ctxmenu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 2px; }
.ctxmenu .cm-h { padding: 4px 10px 6px; font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px; }
#props.flash { animation: propflash 1s; }
@keyframes propflash { 0% { box-shadow: inset 0 0 0 2px var(--accent); } 100% { box-shadow: inset 0 0 0 2px transparent; } }
/* highlighted net on the PCB: the rest of the copper is dimmed */
#pcbSvg.hlmode .trk:not(.hl), #pcbSvg.hlmode .pad:not(.hl), #pcbSvg.hlmode .via:not(.hl), #pcbSvg.hlmode .pour:not(.hl) { opacity: .28; }
#pcbSvg .netlabel-pcb { fill: #fff; font-weight: 700; paint-order: stroke; stroke: #000; stroke-width: 0.15px; pointer-events: none; }
#props .pnet { color: var(--accent); font-size: 15px; font-weight: 700; }
#props .pinlist { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; }
#props .pinlist span { font-size: 11px; padding: 1px 6px; border-radius: 4px; background: var(--panel2); border: 1px solid var(--line); }
/* web version (no server.py): hide features that read files on this computer */
body.static-web #btnKnow, body.static-web #btnFolder { display: none !important; }
body:not(.static-web) #modal .webonly { display: none; }
/* connect an AI model (first run) */
#aiSetup .dlg.setup { max-width: 560px; }
.as-safe { background: color-mix(in srgb, var(--good, #2e9e6a) 12%, transparent); border: 1px solid color-mix(in srgb, var(--good, #2e9e6a) 40%, transparent); border-radius: 8px; padding: 10px 12px; font-size: 13px; line-height: 1.5; margin: 6px 0 12px; }
.as-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.as-tabs button { display: inline-flex; align-items: center; gap: 6px; }
.as-tabs button.on { border-color: var(--accent); color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.as-tabs .tag { font-size: 10px; padding: 1px 6px; border-radius: 999px; border: 1px solid currentColor; opacity: .8; }
.as-tabs .tag.free { color: var(--good, #2e9e6a); opacity: 1; }
.as-guide ol { margin: 4px 0 8px 18px; padding: 0; display: grid; gap: 6px; font-size: 13px; line-height: 1.45; }
.as-guide a { color: var(--accent); }
.as-guide p { margin: 4px 0 10px; line-height: 1.45; }
#asStatus { font-size: 12px; line-height: 1.4; }
#btnConnect { white-space: nowrap; }
.welcome .connect-cta { margin: 10px 0 6px; }
