/* ===== PCB RevEng ===== */
:root{
  --bg:#14171c; --bg2:#1c2128; --bg3:#242b35; --line:#2e3742;
  --fg:#d7dde5; --fg-dim:#8b96a5; --accent:#4da3ff; --accent2:#ffb648;
  --danger:#ff5d5d; --ok:#4fd07f;
  --front:#ff4d4d; --back:#4d7dff; --inner1:#37c871; --inner2:#c87de0;
}
*{box-sizing:border-box; margin:0; padding:0;}
html,body,#app{height:100%; overflow:hidden;}
body{
  background:var(--bg); color:var(--fg);
  font:13px/1.45 "Segoe UI",system-ui,sans-serif;
  user-select:none;
}
#app{display:flex; flex-direction:column;}

/* ---------- top bar ---------- */
#topbar{
  display:flex; align-items:center; gap:14px; padding:6px 10px;
  background:var(--bg2); border-bottom:1px solid var(--line); flex:0 0 auto;
  flex-wrap:wrap;
}
#save-status{margin-left:auto; color:var(--fg-dim); font-size:11px; white-space:nowrap;}
#save-status.saving{color:var(--accent2);}

/* loading overlay */
#loading-overlay{
  position:fixed; inset:0; z-index:500; display:none;
  align-items:center; justify-content:center; background:rgba(13,15,18,.86);
}
#loading-overlay.show{display:flex;}
.ld-box{display:flex; flex-direction:column; align-items:center; gap:14px; color:var(--fg);}
.ld-spin{
  width:42px; height:42px; border:4px solid var(--line); border-top-color:var(--accent);
  border-radius:50%; animation:ld-rot .8s linear infinite;
}
@keyframes ld-rot{to{transform:rotate(360deg);}}
#loading-text{font-size:14px; color:var(--fg-dim);}
.brand{font-weight:700; font-size:15px; letter-spacing:.5px; color:var(--fg); text-decoration:none; cursor:pointer;}
.brand:hover{opacity:.85;}
.brand span{color:var(--accent);}
.tb-group{display:flex; align-items:center; gap:4px;}
.tb-group + .tb-group{border-left:1px solid var(--line); padding-left:14px;}
.tb-label{color:var(--fg-dim); margin-right:2px;}
button{
  background:var(--bg3); color:var(--fg); border:1px solid var(--line);
  border-radius:5px; padding:4px 10px; cursor:pointer; font:inherit;
}
button:hover{background:#2e3845; border-color:#3c4856;}
button:active{transform:translateY(1px);}
button.primary{background:var(--accent); border-color:var(--accent); color:#08233f; font-weight:600;}
button.primary:hover{background:#6ab4ff;}
select,input,textarea{
  background:var(--bg); color:var(--fg); border:1px solid var(--line);
  border-radius:4px; padding:3px 6px; font:inherit;
}
select:focus,input:focus,textarea:focus{outline:1px solid var(--accent);}

#toolbar .tool{
  display:flex; flex-direction:column; align-items:center; gap:0;
  min-width:52px; padding:3px 6px; line-height:1.1; font-size:14px;
}
#toolbar .tool span{font-size:10px; color:var(--fg-dim);}
#toolbar .tool.active{background:var(--accent); border-color:var(--accent); color:#08233f;}
#toolbar .tool.active span{color:#08233f;}
#btn-flip.active,#btn-mask.active,#btn-xray.active{background:var(--accent2); border-color:var(--accent2); color:#3a2600;}

/* ---------- layout ---------- */
#main{display:flex; flex:1 1 auto; min-height:0;}
#left-panel,#right-panel{
  width:235px; flex:0 0 auto; background:var(--bg2);
  border-right:1px solid var(--line); overflow-y:auto; padding:8px;
  display:flex; flex-direction:column; gap:6px;
}
#left-panel{min-width:200px;}
#right-panel{border-right:none; border-left:1px solid var(--line); width:265px; min-width:200px;}
#left-resizer,#right-resizer{
  flex:0 0 auto; width:6px; cursor:col-resize; background:transparent;
  touch-action:none; align-self:stretch;
}
#left-resizer:hover, #left-resizer.dragging,
#right-resizer:hover, #right-resizer.dragging{ background:var(--accent); }
.panel-title{
  font-weight:600; color:var(--fg-dim); text-transform:uppercase; font-size:11px;
  letter-spacing:.8px; margin:6px 0 2px; display:flex; justify-content:space-between;
  align-items:center; flex-wrap:wrap; gap:4px;
}
/* the button group beside a panel title wraps onto a new line when it does not
   fit, so the last button (for example "+ Add") is never clipped by the panel */
.panel-title > span{flex-wrap:wrap; justify-content:flex-end;}
.panel-title button{padding:1px 7px; font-size:11px;}
.panel-hint{color:var(--fg-dim); font-size:11px; padding:4px 2px;}

/* ---------- layer cards ---------- */
.layer-card{
  background:var(--bg3); border:1px solid var(--line); border-radius:6px;
  padding:6px; display:flex; flex-direction:column; gap:4px; cursor:pointer;
}
.layer-card.active{border-color:var(--accent);}
.layer-head{display:flex; align-items:center; gap:6px;}
.layer-head .vis{width:22px; text-align:center; padding:1px 0;}
.layer-head .name{flex:1; font-weight:600; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.layer-head .del{color:var(--danger); padding:1px 6px;}
.layer-card input[type=range]{width:100%;}
.layer-side{font-size:10px; padding:1px 6px; border-radius:3px; align-self:flex-start;}
.side-front{background:#5a1f1f; color:#ffb3b3;}
.side-back{background:#1f2c5a; color:#b3c4ff;}
.side-inner1{background:#1f4a2e; color:#a9eec2;}
.side-inner2{background:#42215a; color:#e4bdf5;}
.layer-row{display:flex; gap:4px; align-items:center; font-size:11px; color:var(--fg-dim);}
.layer-row select{flex:1; font-size:11px; padding:1px 3px;}
.layer-row .align2,.layer-row .crop2{font-size:11px; padding:1px 6px; white-space:nowrap;}

/* ---------- net list ---------- */
#layer-list{flex:0 0 auto; max-height:42%; overflow-y:auto;}
#left-panel{overflow:hidden;}
#parts-dialog{min-width:340px;}
#part-list{
  max-height:50vh; min-height:120px; overflow-y:auto;
  border:1px solid var(--line); border-radius:6px; padding:3px; background:rgba(0,0,0,.15);
}
.part-item{display:flex; align-items:center; gap:6px; padding:3px 5px; border-radius:4px; cursor:pointer;}
.part-item:hover{background:var(--bg3);}
.part-item.active{background:#1c3a5e;}
.part-item.dup{background:rgba(196,84,72,.14);}
.part-item.dup:hover{background:rgba(196,84,72,.24);}
.part-item .pref{font-weight:600; flex:0 0 auto; display:flex; align-items:center; gap:5px;}
.part-item .pval{flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--fg-dim); font-size:11px;}
.part-item .pside{color:var(--fg-dim); font-size:10px; flex:0 0 auto;}
.dup-badge{display:inline-block; background:#c45448; color:#fff; font-size:9px; font-weight:700;
  line-height:1; padding:2px 4px; border-radius:3px; text-transform:uppercase; letter-spacing:.3px;}
#net-list{
  flex:1 1 auto; min-height:80px; overflow-y:auto;
  border:1px solid var(--line); border-radius:6px; padding:3px; background:rgba(0,0,0,.15);
}
.net-item{
  display:flex; align-items:center; gap:6px; padding:2px 4px; border-radius:4px; cursor:pointer;
}
.net-item:hover{background:var(--bg3);}
.net-item.active{background:#1c3a5e;}
/* net of the pad/via/trace selected on the board — softer than .active (which is the
   list-clicked, focus-dimming net) but clearly picked out, with an accent bar */
.net-item.sel{background:#1b2a3a; box-shadow:inset 2px 0 0 #4f8fd0;}
.net-item.sel .nname{color:#eaf2fb; font-weight:600;}
.net-swatch{width:10px; height:10px; border-radius:2px; flex:0 0 auto;}
.net-color{width:16px; height:16px; flex:0 0 auto; padding:0; border:1px solid var(--line); border-radius:3px; background:none; cursor:pointer;}
.net-color::-webkit-color-swatch-wrapper{padding:1px;}
.net-color::-webkit-color-swatch{border:none; border-radius:2px;}
.nprot{
  flex:0 0 auto; padding:0; width:18px; height:18px; line-height:18px; font-size:11px;
  background:none; border:none; border-radius:3px; cursor:pointer; opacity:0.25;
  filter:grayscale(1); transition:opacity .1s, filter .1s;
}
.nprot:hover{opacity:0.7; background:var(--bg2);}
.nprot.on{opacity:1; filter:none;}
.net-item .nname{flex:1; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
.net-item .ncount{color:var(--fg-dim); font-size:10px;}

/* ---------- settings ---------- */
#settings-panel{display:flex; flex-direction:column; gap:7px;}
.set-row{display:flex; flex-direction:column; gap:2px;}
.set-row label{font-size:11px; color:var(--fg-dim);}
.set-row label span{color:var(--fg);}
.set-row select{font-size:12px;}
.set-row input[type=range]{width:100%;}
/* options tabs (Board / Display / Input & snap / General) */
.dlg-tabs{display:flex; gap:4px; margin-bottom:10px; border-bottom:1px solid var(--line); padding-bottom:0;}
.dlg-tab{
  padding:5px 12px; font-size:12px; background:transparent; border:1px solid transparent;
  border-bottom:none; border-radius:6px 6px 0 0; color:var(--fg-dim); cursor:pointer;
}
.dlg-tab:hover{color:var(--fg);}
.dlg-tab.active{background:var(--bg3); border-color:var(--line); color:var(--fg); font-weight:600;}
.set-tab{display:none; flex-direction:column; gap:9px;}
.set-tab.active{display:flex;}
.set-hint{font-size:10.5px; color:#6b7684; line-height:1.4;}
.set-tab > .set-hint:first-child{margin-bottom:2px; padding-bottom:5px; border-bottom:1px dashed #232b35;}
.opt-io-btns{display:flex; gap:6px;}
.opt-io-btns button{flex:1; font-size:12px;}

/* ---------- canvas ---------- */
#canvas-wrap{flex:1 1 auto; position:relative; min-width:0; background:#0d0f12;}
#canvas{position:absolute; inset:0; width:100%; height:100%; display:block; touch-action:none;}
#status-bar{
  position:absolute; left:0; right:0; bottom:0; display:flex; gap:18px; align-items:center;
  background:rgba(20,23,28,.92); border-top:1px solid var(--line);
  padding:3px 12px; font-size:12px; color:var(--fg-dim); pointer-events:none; overflow:hidden;
}
#status-bar > span{ min-width:0; }   /* let the middle items shrink so the Hide group stays visible */
#status-pad{ overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#status-tool{color:var(--accent); font-weight:600;}
#status-pad{color:#ffd24d; font-weight:600;}
/* compact "hide X" checkboxes on the far right of the status bar (status bar itself is
   pointer-events:none, so re-enable them here) */
#status-hide{margin-left:auto; flex-shrink:0; display:flex; align-items:center; gap:10px; pointer-events:auto;}
#status-hide .sh-label{color:var(--fg-dim);}
#status-hide label{display:inline-flex; align-items:center; gap:3px; cursor:pointer; color:#aeb7c2; user-select:none;}
#status-hide label:hover{color:#e6ecf3;}
#status-hide input{margin:0; cursor:pointer; width:12px; height:12px;}
#drop-hint{
  position:absolute; inset:0; display:flex; flex-direction:column; gap:6px;
  align-items:center; justify-content:center; color:var(--fg-dim);
  font-size:20px; text-align:center; pointer-events:none;
  transition:opacity 1.1s ease;
}
/* recede once the user is actively working without adding photos; comes back when idle */
#drop-hint.faded{opacity:.08;}
#drop-hint small{font-size:13px;}
#canvas-wrap.dragover::after{
  content:""; position:absolute; inset:8px; border:2px dashed var(--accent);
  border-radius:10px; pointer-events:none;
}

/* ---------- inspector ---------- */
#inspector{display:flex; flex-direction:column; gap:8px;}
.insp-section{background:var(--bg3); border:1px solid var(--line); border-radius:6px; padding:8px; display:flex; flex-direction:column; gap:6px;}
.insp-row{display:flex; align-items:center; gap:6px;}
.insp-row label{width:74px; flex:0 0 auto; color:var(--fg-dim); font-size:11px;}
.insp-row input,.insp-row select{flex:1; min-width:0;}
.insp-title{font-weight:700; font-size:14px;}
.pin-table{width:100%; border-collapse:collapse; font-size:11px;}
.pin-table th{color:var(--fg-dim); text-align:left; padding:2px 4px; border-bottom:1px solid var(--line); font-weight:600;}
.pin-table td{padding:1px 2px; border-bottom:1px solid #1d242d;}
.pin-table input{width:100%; font-size:11px; padding:1px 4px; border:none; background:transparent;}
.pin-table input:hover{background:var(--bg);}
.pin-table select{width:100%; font-size:11px; padding:1px 2px;}
/* hide native number spinners in the cramped pad-size cell so arrows don't overlap the digits */
.pin-table input[type=number]{-moz-appearance:textfield; appearance:textfield;}
.pin-table input[type=number]::-webkit-outer-spin-button,
.pin-table input[type=number]::-webkit-inner-spin-button{-webkit-appearance:none; margin:0;}
.pin-table tr.sel{background:#1c3a5e;}
.insp-actions{display:flex; gap:6px; flex-wrap:wrap;}

/* BOM editor */
.dlg-sub{color:var(--fg-dim); font-size:11px; font-weight:400;}
#bom-table-wrap{max-height:62vh; min-width:680px; overflow:auto; border:1px solid var(--line); border-radius:6px;}
.bom-table{width:100%; border-collapse:collapse; font-size:12px; white-space:nowrap;}
.bom-table th{position:sticky; top:0; z-index:1; background:var(--bg2); color:var(--fg-dim);
  text-align:left; padding:4px 6px; border-bottom:1px solid var(--line); font-weight:600;
  border-right:1px solid rgba(255,255,255,.07);}
.bom-table td{padding:1px 3px; border-bottom:1px solid #1d242d; border-right:1px solid rgba(255,255,255,.055);}
.bom-table th:last-child, .bom-table td:last-child{border-right:none;}
.bom-table tbody tr:hover{background:var(--bg3);}
.bom-table .bom-idx,.bom-table .bom-qty{color:var(--fg-dim); text-align:right; padding-right:8px;}
.bom-table input.bom-refs{min-width:200px; color:var(--fg-dim);}
.bom-table input.bom-refs:focus{color:var(--fg);}
.bom-table input{width:100%; min-width:90px; font-size:12px; padding:2px 5px; border:1px solid transparent;
  border-radius:4px; background:transparent; color:var(--fg);}
.bom-table input:hover{border-color:var(--line);}
.bom-table input:focus{border-color:var(--accent); background:var(--bg); outline:none;}
.bom-delcol{background:none; border:none; color:var(--fg-dim); cursor:pointer; padding:0 2px; font-size:12px;}
.bom-delcol:hover{color:#ff6b6b;}
.bom-table input.bom-badfp{color:#ff8a6a; border-color:#7a3a2a; background:rgba(255,90,60,0.08);}
.bom-table input.bom-badfp:focus{border-color:#ff8a6a;}
/* drag the right edge of a BOM header cell to resize that column */
.bom-resize{position:absolute; top:0; right:0; width:7px; height:100%;
  cursor:col-resize; user-select:none; touch-action:none;}
.bom-resize:hover, .bom-resize.dragging{background:rgba(77,163,255,.45);}
.insp-actions button{font-size:11px; padding:3px 8px;}
button.danger{color:var(--danger); border-color:#5a2828;}

/* ---------- dialogs ---------- */
dialog{
  background:var(--bg2); color:var(--fg); border:1px solid var(--line);
  border-radius:10px; padding:16px; max-width:860px;
  position:fixed; top:50%; left:50%; transform:translate(-50%,-50%); margin:0;
}
#options-dialog #settings-panel{width:340px; min-height:380px;}
dialog::backdrop{background:rgba(0,0,0,.55);}
#export-warn{
  background:#3a2a16; border:1px solid #7a5a24; color:#ffce8a;
  border-radius:6px; padding:8px 10px; margin-bottom:8px; font-size:12px;
  max-height:160px; overflow-y:auto; line-height:1.5;
}
#export-warn .export-warn-hint{color:#c9a76a; font-size:11px;}
.dlg-title{font-weight:700; font-size:15px; margin-bottom:12px;}
.dlg-buttons{display:flex; gap:8px; justify-content:flex-end; margin-top:12px;}
.dlg-row{display:flex; align-items:center; gap:8px; margin-bottom:8px;}

/* quick-add popup (experimental) */
#qa-dialog{ width:840px; max-width:96vw; }
#qa-dialog .qa-wrap{display:flex; gap:12px; align-items:stretch;}
#qa-dialog .qa-body{display:flex; flex-direction:column; gap:8px; flex:1 1 auto; min-width:0;}
.qa-side{width:170px; flex:0 0 auto; display:flex; flex-direction:column; gap:6px; min-height:0;}
.qa-side-h{font-size:10px; text-transform:uppercase; letter-spacing:.04em; color:#8b96a5;}
.qa-side-list{display:flex; flex-direction:column; gap:3px; overflow-y:auto; max-height:520px;}
.qa-side-list button{text-align:left; padding:3px 6px; font-size:10px; line-height:1.3;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.qa-side-h{display:flex; align-items:center; justify-content:space-between;}
.qa-side-clear{font-size:9.5px; padding:0 5px; color:#8b96a5; background:transparent;
  border:1px solid #38424f; border-radius:3px; text-transform:none; letter-spacing:0; cursor:pointer;}
.qa-side-clear:hover{color:#e0e6ee; border-color:#5a6673;}
#qa-preview{width:100%; height:340px; border:1px solid #38424f; border-radius:5px; background:#0d0f12;}
#qa-input{font-size:14px; padding:6px 8px;}
.qa-info{min-height:16px; font-size:12px; color:#8b96a5;}
.qa-info.ok{color:#7fd48a; font-weight:600;}
.qa-keys{font-size:10.5px; color:#6b7684;}
/* structured facts grid (footprint / pins / pitch / body / value / part …) */
.qa-facts{
  display:grid; grid-template-columns:max-content 1fr max-content 1fr;
  gap:4px 10px; padding:8px 10px; font-size:12px;
  background:#151a21; border:1px solid #2a3240; border-radius:6px;
}
.qa-k{color:#8b96a5; font-size:11px; padding-top:1px; white-space:nowrap;}
.qa-v{color:#d7dde5; min-width:0; overflow-wrap:anywhere;}
.qa-dim{color:#6b7684; font-size:10.5px;}

/* split-view per-pane layer dropdowns (overlaid on the canvas panes) */
.split-layer-sel{
  position:absolute; top:8px; z-index:5; max-width:44%;
  background:rgba(16,20,26,.9); color:#d7dde5; border:1px solid #38424f;
  border-radius:5px; padding:3px 6px; font-size:11px;
}
#split-layer-left{ left:8px; }
#split-layer-right{ left:calc(50% + 8px); }

/* footprint dialog — sized 1.5× wide / 2.5× tall vs. its natural content box; the
   category list and the preview grow to fill the extra room */
#fp-dialog[open]{
  max-width:96vw; width:1061px; height:1044px; max-height:96vh;
  box-sizing:border-box; display:flex; flex-direction:column;
}
#fp-dialog .fp-body{flex:1 1 auto; min-height:0;}
#fp-dialog .fp-left{width:248px;}
#fp-dialog #fp-cats{max-height:none; flex:1 1 auto; min-height:0;}
#fp-dialog .fp-mid{width:405px;}
#fp-dialog #fp-preview{width:100%; flex:1 1 auto; min-height:0;}
#fp-dialog .fp-right{width:315px;}
.fp-body{display:flex; gap:14px;}
.fp-left{display:flex; flex-direction:column; gap:6px; width:165px;}
#fp-search{width:100%; font-size:12px;}
#fp-cats{display:flex; flex-direction:column; gap:3px; width:100%; max-height:350px; overflow-y:auto;}
#fp-cats button{text-align:left; padding:4px 8px;}
#fp-cats button.active{background:var(--accent); border-color:var(--accent); color:#08233f;}
.fp-rcl-note{margin-top:8px; padding:7px 9px; font-size:11px; color:#aab4c2;
  background:#1c222b; border:1px solid #38424f; border-left:3px solid var(--accent2); border-radius:4px;
  display:flex; flex-direction:column; gap:4px;}
.fp-rcl-note span{color:#d7dde5;}
.fp-rcl-note b{color:#ffd479;}
.fp-rcl-note kbd{padding:0 4px; font-size:10px; color:#cfd6df; background:#2a323c; border:1px solid #44505d; border-radius:3px;}
#fp-cats kbd.catkey{display:inline-block; min-width:20px; margin-right:7px; padding:0 3px; text-align:center;
  font-size:10px; line-height:15px; color:#9aa6b4; background:#222a34; border:1px solid #38424f; border-radius:3px;}
#fp-cats button.active kbd.catkey{color:#08233f; background:#bfe0ff; border-color:#9fcdf5;}
.fp-mid{display:flex; flex-direction:column; gap:8px; width:270px;}
#fp-params{display:flex; flex-direction:column; gap:6px;}
#fp-params label{display:flex; align-items:center; gap:6px; font-size:12px; color:var(--fg-dim);}
#fp-params input,#fp-params select{flex:1;}
#fp-params label.fp-check{cursor:pointer;}
#fp-params label.fp-check input{flex:0 0 auto; width:auto;}
.fp-pad-tune{margin-top:6px; padding:7px 9px; display:flex; flex-direction:column; gap:6px;
  background:#1c222b; border:1px solid #38424f; border-left:3px solid var(--accent2); border-radius:4px;}
.fp-pad-tune-h{font-size:10px; text-transform:uppercase; letter-spacing:.04em; color:#8b96a5;}
.fp-pad-tune label{display:flex; align-items:center; gap:6px; font-size:12px; color:var(--fg-dim);}
.fp-pad-tune input{flex:1;}
#fp-preview{background:#0d0f12; border:1px solid var(--line); border-radius:6px;}
/* Custom (imported) footprints + placed-freestyle quick-select */
.fp-custom-box{margin-top:6px; padding:7px 9px; display:flex; flex-direction:column; gap:4px;
  background:#1c222b; border:1px solid #38424f; border-left:3px solid var(--accent2); border-radius:4px;
  max-height:260px; overflow-y:auto;}
.fp-custom-box>button{text-align:left; padding:4px 8px;}
.fp-custom-row{display:flex; gap:4px;}
.fp-custom-row button:first-child{flex:1 1 auto; text-align:left; padding:3px 8px; min-width:0;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.fp-custom-row button.active{background:var(--accent); border-color:var(--accent); color:#08233f;}
.fp-custom-del{flex:0 0 auto; padding:3px 7px; color:#e08585;}

/* 3D layer-stack viewer */
#stack3d-dialog{max-width:none;}
#stack3d-canvas{
  display:block; width:78vw; max-width:1000px; height:64vh; max-height:720px;
  background:#0d0f12; border:1px solid var(--line); border-radius:6px;
  touch-action:none; cursor:grab;
}
#stack3d-canvas:active{cursor:grabbing;}
#stack3d-controls{
  display:flex; flex-wrap:wrap; align-items:center; gap:6px 16px;
  margin:8px 0 2px; font-size:11px; color:var(--fg-dim);
}
#stack3d-controls .s3d-chk{display:flex; align-items:center; gap:5px; cursor:pointer; color:var(--fg);}
#stack3d-controls .s3d-rng{display:flex; align-items:center; gap:6px;}
#stack3d-controls .s3d-rng>span{min-width:42px;}
#stack3d-controls input[type=range]{width:96px; accent-color:var(--accent);}
.fp-right{display:flex; flex-direction:column; gap:8px; width:210px;}
.fp-right label{display:flex; flex-direction:column; gap:2px; font-size:11px; color:var(--fg-dim);}

/* export dialog */
#export-preview{width:640px; height:340px; font:11px/1.4 Consolas,monospace; white-space:pre; resize:vertical;}
#export-svg{width:640px; height:300px; background:#12161c; border:1px solid #2a3240; border-radius:6px; margin-bottom:8px; overflow:hidden;}
#export-svg svg{width:100%; height:100%; display:block;}

/* help */
#help-body{display:grid; grid-template-columns:1fr 1fr; gap:4px 28px; max-height:60vh; overflow-y:auto;}
#help-body h3{grid-column:1/-1; margin:10px 0 4px; font-size:12px; color:var(--accent); text-transform:uppercase; letter-spacing:.8px;}
.hk{display:flex; justify-content:space-between; gap:14px; padding:2px 0; border-bottom:1px solid #1d242d;}
.hk kbd{
  background:var(--bg3); border:1px solid var(--line); border-bottom-width:2px;
  border-radius:4px; padding:0 6px; font:11px Consolas,monospace; white-space:nowrap;
}
.hk span{color:var(--fg-dim);}

/* checker grouped sections — side by side */
#checker-list{display:flex; gap:12px; align-items:flex-start; flex-wrap:nowrap; width:720px; max-width:88vw;}
.chk-group{
  flex:1 1 0; min-width:0; max-height:62vh; display:flex; flex-direction:column;
  border:1px solid var(--line); border-radius:6px; overflow:hidden;
}
.chk-group-head{
  flex:0 0 auto; padding:5px 9px; font-weight:600; font-size:12px; display:flex; align-items:center; gap:7px;
  border-bottom:1px solid var(--line); border-left:3px solid var(--fg-dim);
}
.chk-group-body{padding:3px 9px; overflow-y:auto;}
.chk-group-body .hk:last-child{border-bottom:none;}
.chk-count{background:var(--bg3); border-radius:9px; padding:1px 7px; font-size:11px; font-weight:700;}
.chk-group.missing .chk-group-head{color:#ff7b6b; border-left-color:#c45448; background:rgba(196,84,72,.10);}
.chk-group.issues  .chk-group-head{color:#ffb648; border-left-color:#d99320; background:rgba(217,147,32,.10);}

/* history dialog */
#history-list{display:flex; flex-direction:column; gap:2px; max-height:55vh; overflow-y:auto; min-width:420px;}
.hist-row{display:flex; align-items:flex-start; gap:10px; padding:4px 4px; border-bottom:1px solid #1d242d;}
.hist-time{color:var(--fg-dim); font:11px Consolas,monospace; padding-top:1px;}
.hist-main{flex:1; display:flex; flex-direction:column; gap:1px; min-width:0;}
.hist-label{}
.hist-detail{font-size:11px; color:var(--fg-dim); line-height:1.35; word-break:break-word;}
.hist-undo{font-size:11px; padding:2px 8px; flex:0 0 auto;}

/* right-click context menu */
#ctx-menu{
  position:fixed; z-index:600; min-width:170px; padding:4px;
  background:var(--bg2); border:1px solid var(--line); border-radius:8px;
  box-shadow:0 6px 24px rgba(0,0,0,.5); font-size:12px;
}
.ctx-item{padding:5px 12px; border-radius:5px; cursor:pointer; white-space:nowrap;}
.ctx-item:hover{background:var(--accent); color:#08233f;}
.ctx-item.danger{color:var(--danger);}
.ctx-item.danger:hover{background:var(--danger); color:#fff;}
.ctx-sep{height:1px; background:var(--line); margin:4px 0;}

/* trace width quick picker (Shift+W) */
#tracew-menu{
  position:fixed; z-index:600; padding:8px; min-width:200px;
  background:var(--bg2); border:1px solid var(--line); border-radius:8px;
  box-shadow:0 6px 24px rgba(0,0,0,.5); font-size:12px;
}
.tracew-title{color:var(--accent); font-weight:600; margin-bottom:6px;}
.tracew-inputs{display:flex; gap:4px; align-items:center; margin-bottom:6px;}
.tracew-inputs input{width:0; flex:1; min-width:0;}
.tracew-inputs span{color:var(--fg-dim); font-size:10px;}
.tracew-presets{display:grid; grid-template-columns:repeat(4,1fr); gap:4px;}
.tracew-presets button{padding:3px 0; font-size:11px;}

/* net name popup */
#netname-quick{display:flex; flex-wrap:wrap; gap:5px; max-width:300px;}
#netname-quick button{font-size:12px; padding:3px 9px;}
#netname-quick button.prot{border-color:#3a6a44;}

/* value resolver */
.res-out{color:var(--accent2); font-weight:600; margin-left:8px;}
#res-band-row{display:flex; gap:6px; flex-wrap:wrap;}
.band-sel{font-size:12px;}

/* hotkey editor */
#keys-list{display:grid; grid-template-columns:1fr 1fr; gap:2px 28px; max-height:60vh; overflow-y:auto; min-width:560px;}
.keys-group-h{grid-column:1/-1; margin:10px 0 3px; font-size:11px; color:var(--accent);
  text-transform:uppercase; letter-spacing:.8px; border-bottom:1px solid #232b35; padding-bottom:2px;}
.keys-group-h:first-child{margin-top:0;}
.key-row{align-items:center;}
.key-btn{padding:1px 4px; background:transparent; border:none;}
.key-btn kbd{
  display:inline-block; min-width:64px; text-align:center;
  background:var(--bg3); border:1px solid var(--line); border-bottom-width:2px;
  border-radius:4px; padding:2px 8px; font:11px Consolas,monospace; cursor:pointer;
}
.key-btn:hover kbd{border-color:var(--accent);}
.key-btn.listening kbd{background:var(--accent); color:#08233f; border-color:var(--accent);}

::-webkit-scrollbar{width:9px; height:9px;}
::-webkit-scrollbar-thumb{background:#323c49; border-radius:5px;}
::-webkit-scrollbar-track{background:transparent;}

/* ---- editor tabs (Visual / Schematic / BOM) — slim line ABOVE the topbar ---- */
#editor-tabs{
  display:flex; gap:2px; padding:3px 10px 0; flex:0 0 auto;
  background:#0f1216; border-bottom:1px solid var(--line); font-size:12px;
}
.ed-tab{
  background:transparent; border:1px solid transparent; border-bottom:none;
  color:var(--fg-dim); padding:3px 16px 5px; margin-bottom:-1px;
  border-radius:6px 6px 0 0; cursor:pointer; font-size:12px; line-height:1.4;
}
.ed-tab:hover{color:var(--fg); background:var(--bg3);}
.ed-tab.active{
  background:var(--bg2); border-color:var(--line); border-bottom:1px solid var(--bg2);
  color:var(--fg); font-weight:600;
}
#active-project{
  margin-left:auto; align-self:center; padding:2px 8px 4px; cursor:pointer;
  color:var(--fg-dim); font-size:11px; white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis; max-width:320px;
}
#active-project:hover{color:var(--fg);}

/* ---- schematic editor pane ---- */
#schematic-pane{flex:1 1 auto; min-height:0; display:flex; flex-direction:column; background:#0d0f12;}
#sch-toolbar{
  display:flex; align-items:center; gap:6px; padding:6px 10px; flex:0 0 auto;
  background:var(--bg2); border-bottom:1px solid var(--line); font-size:12px;
}
#sch-toolbar .panel-hint{margin:0; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;}
#sch-toolbar .sch-chk{display:flex; align-items:center; gap:4px; color:var(--fg-dim); cursor:pointer; white-space:nowrap;}
#sch-toolbar .sch-chk input{margin:0;}
#sch-canvas-wrap{flex:1 1 auto; position:relative; min-height:0;}
#sch-canvas{position:absolute; inset:0; width:100%; height:100%; cursor:default;}

/* ---- BOM pane ---- */
#bom-pane{flex:1 1 auto; min-height:0; display:flex; flex-direction:column; padding:8px 12px;}
#bom-toolbar{display:flex; align-items:center; gap:8px; flex:0 0 auto;}
#bom-pane #bom-table-wrap{flex:1 1 auto; max-height:none; min-width:0;}

/* ---- Nets pane ---- */
#nets-pane{flex:1 1 auto; min-height:0; display:flex; flex-direction:column; padding:8px 12px;}
#nets-toolbar{display:flex; align-items:center; gap:8px; flex:0 0 auto;}
#nets-search{width:220px; padding:4px 7px; background:#1c222b; border:1px solid #2e3742;
  border-radius:5px; color:#d7dde5; font-size:12px;}
#nets-search:focus{border-color:var(--accent); outline:none;}
#nets-table-wrap{flex:1 1 auto; min-height:0; overflow:auto;
  border:1px solid var(--line); border-radius:6px;}
.nets-table{width:100%; border-collapse:collapse; font-size:12px;}
.nets-table thead th{position:sticky; top:0; z-index:1; background:var(--bg2); color:var(--fg-dim);
  text-align:left; padding:4px 6px; border-bottom:1px solid var(--line); font-weight:600; white-space:nowrap;}
.nets-table td{padding:2px 6px; border-bottom:1px solid #1d242d; vertical-align:middle;}
.nets-table tbody tr.nt-row:hover{background:var(--bg3);}
.nets-table tr.nt-row.open{background:var(--bg3);}
.nt-expcell,.nt-colcell,.nt-protcell{width:1%; padding-right:0 !important;}
.nt-exp{background:none; border:none; color:var(--fg-dim); cursor:pointer; font-size:11px; padding:0 2px;}
.nt-exp:hover{color:var(--fg);}
.nt-color{width:22px; height:18px; padding:0; border:1px solid var(--line); border-radius:3px;
  background:none; cursor:pointer;}
.nt-prot{background:none; border:none; cursor:pointer; font-size:12px; padding:0 2px;
  filter:grayscale(1); opacity:.4;}
.nt-prot:hover{opacity:.8;}
.nt-prot.on{filter:none; opacity:1;}
.nt-namecell{min-width:150px;}
.nets-table input.nt-name{width:100%; min-width:120px; font-size:12px; padding:2px 5px;
  border:1px solid transparent; border-radius:4px; background:transparent; color:var(--fg);}
.nets-table input.nt-name:hover{border-color:var(--line);}
.nets-table input.nt-name:focus{border-color:var(--accent); background:var(--bg); outline:none;}
.nets-table input.nt-name.prot{color:var(--fg-dim); cursor:default;}
.nt-num{color:var(--fg-dim); text-align:right; width:1%; padding-right:12px !important; white-space:nowrap;}
.nt-gauge{color:var(--fg-dim); white-space:nowrap;}
/* expanded net → its connection list */
.nets-table tr.nt-detailrow > td{padding:0 0 6px 26px; background:#12161b;}
.nt-sub{width:100%; border-collapse:collapse; font-size:11px;}
.nt-sub th{text-align:left; color:var(--fg-dim); font-weight:600; padding:3px 6px;
  border-bottom:1px solid #232b35;}
.nt-sub td{padding:1px 6px; border-bottom:1px solid #1a2029;}
.nt-sub tr:hover{background:#181d24;}
.nt-kind{text-transform:uppercase; font-size:9px; letter-spacing:.05em; width:1%;
  color:#8892a0; white-space:nowrap;}
.nt-k-pad{color:#ffd24d;} .nt-k-via{color:#7da0ff;} .nt-k-trace{color:#66d96f;}
.nt-what{white-space:nowrap; color:var(--fg);}
.nt-detail{color:var(--fg-dim); white-space:nowrap;}
.nt-netcell{width:150px; color:var(--fg-dim);}
.nets-table input.nt-net{width:100%; min-width:100px; font-size:11px; padding:1px 4px;
  border:1px solid transparent; border-radius:4px; background:transparent; color:var(--fg);}
.nets-table input.nt-net:hover{border-color:var(--line);}
.nets-table input.nt-net:focus{border-color:var(--accent); background:var(--bg); outline:none;}
.nt-focus{font-size:10px; padding:1px 7px; background:#232b35; color:#cdd5df;
  border:1px solid #3a4553; border-radius:4px; cursor:pointer; white-space:nowrap;}
.nt-focus:hover{background:#2f3a47; color:#fff; border-color:#4a5766;}

/* ---- Projects pane ---- */
#projects-pane{flex:1 1 auto; min-height:0; display:flex; flex-direction:column; padding:8px 12px;}
#projects-toolbar{display:flex; align-items:center; gap:8px; flex:0 0 auto;}
#projects-pane.dragover{outline:2px dashed var(--accent); outline-offset:-6px;}
#projects-grid{flex:1 1 auto; min-height:0; overflow:auto; display:flex; flex-wrap:wrap;
  gap:12px; align-content:flex-start; padding:4px 2px;}
.proj-card{width:300px; background:var(--bg2); border:1px solid var(--line); border-radius:8px;
  padding:10px; display:flex; flex-direction:column; gap:7px;}
.proj-card.active{border-color:var(--accent);}
/* the autosave slot + built-in example: visibly NOT ordinary saved projects */
.proj-card.special{border-style:dashed; background:rgba(255,255,255,.025);}
.proj-badge.special{color:var(--fg-dim); border-color:var(--fg-dim);}
.proj-name-static{flex:1; min-width:0; font-size:13px; font-weight:600; padding:2px 5px;
  color:var(--fg); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.proj-sep{flex-basis:100%; width:100%; color:var(--fg-dim); font-size:11px;
  text-transform:uppercase; letter-spacing:.6px; border-bottom:1px solid var(--line);
  padding-bottom:3px; margin-top:4px;}
.proj-thumb{width:100%; height:150px; object-fit:cover; border-radius:5px;
  background:#10141a; border:1px solid #1d242d;}
.proj-thumb.empty,.proj-ver-thumb.empty{display:flex; align-items:center; justify-content:center;
  color:var(--fg-dim); font-size:11px;}
.proj-name-row{display:flex; align-items:center; gap:6px;}
.proj-name{flex:1; min-width:0; font-size:13px; font-weight:600; padding:2px 5px;
  border:1px solid transparent; border-radius:4px; background:transparent; color:var(--fg);}
.proj-name:hover{border-color:var(--line);}
.proj-name:focus{border-color:var(--accent); background:var(--bg); outline:none;}
.proj-badge{flex:0 0 auto; font-size:10px; color:var(--accent); border:1px solid var(--accent);
  border-radius:8px; padding:0 7px; line-height:15px;}
.proj-meta{font-size:11px; color:var(--fg-dim); line-height:1.5;}
.proj-actions{display:flex; gap:5px; flex-wrap:wrap;}
.proj-actions button{font-size:11px; padding:3px 8px;}
.proj-versions{border-top:1px solid #1d242d; padding-top:6px; display:flex;
  flex-direction:column; gap:4px;}
.proj-ver-toggle{align-self:flex-start; background:none; border:none; color:var(--fg-dim);
  cursor:pointer; font-size:11px; padding:0 2px;}
.proj-ver-toggle:hover{color:var(--fg);}
.proj-ver{display:flex; align-items:center; gap:6px; font-size:11px;}
.proj-ver-thumb{flex:0 0 auto; width:44px; height:28px; object-fit:cover; border-radius:3px;
  background:#10141a; border:1px solid #1d242d;}
.proj-ver .grow{flex:1; min-width:0; overflow:hidden;}
.proj-ver-label{color:var(--fg); white-space:nowrap; overflow:hidden; text-overflow:ellipsis;}
.proj-ver-sub{color:var(--fg-dim); font-size:10px; white-space:nowrap; overflow:hidden;
  text-overflow:ellipsis;}
.proj-ver button{font-size:10px; padding:1px 6px;}

/* ---- multi-PCB page tabs (bottom row, boards.js) ---- */
#board-tabs{
  display:flex; gap:2px; padding:0 10px 3px; flex:0 0 auto; align-items:flex-end;
  background:#0f1216; border-top:1px solid var(--line); font-size:12px;
}
.board-tab{
  background:transparent; border:1px solid transparent; border-top:none;
  color:var(--fg-dim); padding:3px 14px 3px; margin-top:-1px;
  border-radius:0 0 6px 6px; cursor:pointer; line-height:1.4; user-select:none;
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis; max-width:180px;
}
.board-tab:hover{color:var(--fg); background:var(--bg3);}
.board-tab.active{
  background:var(--bg2); border-color:var(--line); border-top:1px solid var(--bg2);
  color:var(--fg); font-weight:600;
}
.board-tab-add{padding:3px 10px; font-weight:700; color:var(--fg-dim);}
.board-tab-add:hover{color:#7ee787;}
#xlink-dialog{background:var(--bg2); color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:14px;}
#xlink-dialog select{background:var(--bg3); color:var(--fg); border:1px solid var(--line); border-radius:4px; font-size:12px;}

/* ---------- first-run guided tour (js/tour.js) ---------- */
#tour-root{position:fixed; inset:0; z-index:100000; pointer-events:none;}
#tour-block{position:absolute; inset:0; pointer-events:auto; background:transparent;}   /* swallow clicks on the app while touring */
#tour-dim{position:absolute; inset:0; width:100%; height:100%; pointer-events:none;}
#tour-path{fill:rgba(8,10,14,.68);}
#tour-rings{position:absolute; inset:0; pointer-events:none;}
.tour-ring{
  position:absolute; border:2px solid var(--accent2); border-radius:6px;
  box-shadow:0 0 0 3px rgba(255,182,72,.25), 0 0 18px rgba(255,182,72,.45);
  animation:tour-pulse 1.4s ease-in-out infinite;
}
@keyframes tour-pulse{50%{box-shadow:0 0 0 6px rgba(255,182,72,.12), 0 0 26px rgba(255,182,72,.6);}}
#tour-card{
  position:absolute; width:340px; max-width:calc(100vw - 16px); pointer-events:auto;
  background:var(--bg2); border:1px solid var(--accent2); border-radius:10px;
  padding:14px 16px 12px; box-shadow:0 10px 40px rgba(0,0,0,.55); user-select:text;
}
#tour-title{font-size:15px; font-weight:700; margin-bottom:6px; color:var(--accent2);}
#tour-text{font-size:13px; line-height:1.5; color:var(--fg);}
#tour-text b{color:#fff;}
#tour-text code{background:var(--bg3); padding:0 4px; border-radius:3px; font-size:12px;}
#tour-foot{display:flex; align-items:center; gap:10px; margin-top:12px;}
#tour-prog{color:var(--fg-dim); font-size:11px; margin-left:auto;}
#tour-skip{background:transparent; border:none; color:var(--fg-dim); cursor:pointer; padding:4px 2px; font-size:12px; text-decoration:underline;}
#tour-skip:hover{color:var(--fg);}
.tour-nav{display:flex; gap:6px;}
