@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=Outfit:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #07090e; 
  --panel: #0d121f; 
  --panel-light: #161e31;
  --line: rgba(255, 255, 255, 0.07); 
  --line-focus: rgba(255, 255, 255, 0.15);
  
  --txt: #f1f5f9; 
  --mut: #94a3b8;
  --mut-dark: #64748b;
  
  --accent: #3b82f6; 
  --accent-glow: rgba(59, 130, 246, 0.15);
  --ok: #10b981; 
  --ok-glow: rgba(16, 185, 129, 0.15);
  --sugg: #f59e0b; 
  --sugg-glow: rgba(245, 158, 11, 0.15);
  --danger: #ef4444; 
  --danger-glow: rgba(239, 68, 68, 0.15);
  
  --origin: #3b82f6; 
  --dest: #f59e0b; 
  --link: #a855f7;
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  
  --font-title: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;
}

* {
  box-sizing: border-box;
  scrollbar-width: thin;
  scrollbar-color: var(--line) transparent;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--line);
  border-radius: var(--radius-sm);
}
::-webkit-scrollbar-thumb:hover {
  background: var(--mut-dark);
}

body {
  margin: 0;
  font: 13.5px/1.5 var(--font-body);
  background: var(--bg);
  color: var(--txt);
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  letter-spacing: -0.01em;
}

.hidden {
  display: none !important;
}

/* --- Header & Navigation --- */
header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 12px 20px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  z-index: 10;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.brand {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--txt);
}

.tag {
  font-family: var(--font-body);
  font-size: 11px;
  color: var(--accent);
  font-weight: 500;
  background: var(--accent-glow);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 2px 8px;
  border-radius: 20px;
}

.ident {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--mut);
  background: rgba(255, 255, 255, 0.03);
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  max-width: 380px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.spacer {
  flex: 1;
}

/* --- Buttons & Inputs --- */
button, .upload {
  background: var(--panel-light);
  color: var(--txt);
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-body);
  font-size: 12.5px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

button:hover:not(:disabled), .upload:hover {
  border-color: var(--mut);
  background: rgba(255, 255, 255, 0.05);
  transform: translateY(-1px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  box-shadow: none;
}

button.primary, .upload.primary {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  font-weight: 600;
}

button.primary:hover:not(:disabled), .upload.primary:hover {
  background: #2563eb;
  border-color: #2563eb;
  box-shadow: 0 0 14px rgba(59, 130, 246, 0.4);
}

button.danger {
  border-color: rgba(239, 68, 68, 0.4);
  background: var(--danger-glow);
  color: #fca5a5;
}

button.danger:hover:not(:disabled) {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
  box-shadow: 0 0 14px rgba(239, 68, 68, 0.4);
}

button.mini {
  padding: 4px 8px;
  font-size: 11px;
  border-radius: 4px;
}

/* --- Dropdown Actions --- */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  background: var(--panel);
  border: 1px solid var(--line-focus);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  border-radius: var(--radius-md);
  z-index: 100;
  min-width: 180px;
  padding: 6px 0;
  margin-top: 8px;
  backdrop-filter: blur(16px);
}

.dropdown-content.show {
  display: block;
  animation: slideDown 0.15s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 16px;
  color: var(--mut);
  text-align: left;
  border: none;
  background: transparent;
  font-size: 12.5px;
  font-family: var(--font-body);
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: none;
  border-radius: 0;
}

.dropdown-item:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.04);
  color: var(--txt);
  transform: none;
  box-shadow: none;
}

.dropdown-item:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

/* --- Main Layout --- */
main {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--bg);
}

/* --- Collapsible Drawer (Left) --- */
#drawer {
  width: 300px;
  min-width: 300px;
  overflow-y: auto;
  background: #090c15;
  border-right: 1px solid var(--line);
  padding: 16px;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

#drawer.collapsed {
  width: 0;
  min-width: 0;
  padding: 0;
  overflow: hidden;
  border-right: none;
}

#drawerBtn {
  font-size: 16px;
  padding: 6px 12px;
  background: transparent;
  border-color: transparent;
}
#drawerBtn:hover {
  background: var(--panel-light);
  border-color: var(--line);
}

/* --- Schematic Viewer (Center) --- */
#viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 1px solid var(--line);
}

.pagebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}

.pagebar .sheet {
  color: var(--mut);
  font-size: 12px;
}
.pagebar b {
  color: var(--txt);
  font-family: var(--font-mono);
}

.chk {
  font-size: 12px;
  color: var(--mut);
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}

.chk input {
  width: auto;
  margin: 0;
  cursor: pointer;
}

#canvasWrap {
  flex: 1;
  overflow: auto;
  background: #040508;
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: flex-start;
}

#layer {
  position: relative;
  transform-origin: 0 0;
}

#pageImg {
  display: block;
  max-width: none;
}

#overlay {
  position: absolute;
  left: 0;
  top: 0;
  overflow: visible;
  pointer-events: none;
}

/* --- Schematic Interactive Tokens --- */
.tok {
  position: absolute;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: outline 0.1s;
}

.tok.device {
  background: rgba(59, 130, 246, 0.08);
  border-color: rgba(59, 130, 246, 0.3);
}

.tok.pin {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.35);
}

.tok:hover {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 5;
}

.tok.sel {
  outline: 2px solid #ffffff;
  outline-offset: 1px;
}

/* --- Highlights & Anchors --- */
.hl {
  position: absolute;
  border-radius: 4px;
  pointer-events: none;
  box-shadow: 0 0 0 2px #000000;
  z-index: 4;
}

.hl.origin {
  background: rgba(59, 130, 246, 0.2);
  border: 2px solid var(--origin);
}

.hl.dest {
  background: rgba(245, 158, 11, 0.2);
  border: 2px solid var(--dest);
}

.hl.pulse {
  animation: pulse 1s ease-out 2;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.8); }
  100% { box-shadow: 0 0 0 16px rgba(255, 255, 255, 0); }
}

.lnk {
  position: absolute;
  background: rgba(168, 85, 247, 0.12);
  border: 1px solid var(--link);
  border-radius: var(--radius-sm);
  cursor: pointer;
}

.lnk:hover {
  background: rgba(168, 85, 247, 0.3);
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.4);
}

/* --- Right Sidebar (Tabs / Lists) --- */
#side {
  width: 600px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  min-width: 0;
  z-index: 5;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}

.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.1);
}

.tab {
  flex: 1;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--mut);
  padding: 12px;
  font-family: var(--font-title);
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  box-shadow: none;
}

.tab:hover:not(.active) {
  color: var(--txt);
  background: transparent;
  transform: none;
  box-shadow: none;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
  background: transparent;
}

/* VLM sub-tab row: Trace nested one level under Panels(VLM) */
.subtabs {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 0 6px 0 4px;
  background: rgba(0,0,0,0.18);
  border-bottom: 1px solid var(--line);
}
.subtabs.hidden { display: none; }
.subtabs-rail {
  color: var(--mut);
  font-family: var(--font-mono, monospace);
  font-size: 12px;
  padding: 0 4px;
  opacity: 0.6;
}
.tab.subtab {
  flex: 0 0 auto;
  padding: 7px 14px;
  font-size: 12px;
  border-bottom-width: 2px;
}

.tabpane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.filters {
  display: flex;
  align-items: center;
  padding: 12px;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  background: rgba(0,0,0,0.05);
}

/* panel-scope picker — compact dropdown inline in the Wires filter bar */
/* pagebar manual-add toggle: a real on/off mode button, not a checklist item */
.pgsep { width: 1px; align-self: stretch; margin: 2px 6px; background: var(--line, rgba(255,255,255,0.12)); }
.pgtoggle { cursor: pointer; }
.pgtoggle.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.scope-chip {
  display: inline-block; margin: 0 0 8px; padding: 3px 10px;
  font-size: 11px; font-weight: 600; color: var(--accent);
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  border: 1px solid var(--accent); border-radius: 999px;
}
.scope-chip.hidden { display: none; }

.scope-picker { position: relative; }
#scopeBtn { white-space: nowrap; }
.scope-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 120;
  width: 250px;
  padding: 10px;
  background: var(--panel);
  border: 1px solid var(--line-focus);
  border-radius: var(--radius-md);
  box-shadow: 0 12px 28px -6px rgba(0,0,0,0.55);
  backdrop-filter: blur(16px);
  animation: slideDown 0.15s ease-out;
}
.scope-pop.hidden { display: none; }
.scope-pop-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}
.scope-pop-acts { display: flex; gap: 6px; flex: 0 0 auto; }
.panel-roots {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 8px;
}
.panel-roots label {
  display: flex;
  align-items: flex-start;       /* checkbox at top-left of multi-line name */
  gap: 8px;
  font-size: 12px !important;    /* beat any inherited filter-bar sizing */
  line-height: 1.35;
  color: var(--txt);
  cursor: pointer;
  text-align: left;
  padding: 4px 6px;
  border-radius: var(--radius-sm, 6px);
}
.panel-roots label:hover { background: var(--line, rgba(255,255,255,0.06)); }
.panel-roots label input[type="checkbox"] {   /* escape global input{width:100%} */
  flex: 0 0 auto; width: auto; min-width: 0; padding: 0; margin: 2px 0 0;
}
.panel-roots label .pname {        /* "+CP1 — DESCRIPTION", wraps, always readable */
  flex: 1 1 auto;
  min-width: 0;
  white-space: normal;
  word-break: break-word;
}
.panel-roots label.foreign { opacity: 0.55; }
.panel-roots label.typed .pcount { color: var(--accent); }
.panel-roots .pcount { color: var(--mut); flex: 0 0 auto; }
.panel-addrow { display: flex; gap: 6px; align-items: center; }

.filters .f {
  padding: 4px 10px;
  font-size: 11px;
  box-shadow: none;
  border-radius: 20px;
  border-color: var(--line);
  background: transparent;
  color: var(--mut);
}

.filters .f:hover {
  background: rgba(255,255,255,0.03);
  border-color: var(--mut-dark);
}

.filters .f.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: rgba(59, 130, 246, 0.4);
  font-weight: 600;
}

.source-filter-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.09);
}

.source-filter-bar .filter-label {
  flex: 0 0 auto;
  font-size: 10px;
  font-weight: 700;
  color: var(--mut);
  text-transform: uppercase;
}

.source-filter-list {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 1px;
}

.source-check {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex: 0 0 auto;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--mut);
  font-size: 11px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.source-check:hover {
  border-color: var(--mut-dark);
  background: rgba(255, 255, 255, 0.03);
}

.source-check input {
  width: auto;
  min-width: 0;
  margin: 0;
  padding: 0;
  accent-color: var(--accent);
}

.source-check:has(input:checked) {
  color: var(--txt);
  border-color: rgba(59, 130, 246, 0.38);
  background: var(--accent-glow);
}

.source-count {
  color: var(--mut);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.search {
  flex: 1;
  min-width: 90px;
  background: rgba(0, 0, 0, 0.25);
  color: var(--txt);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-size: 12px;
  transition: all 0.2s;
}

.search:focus {
  outline: none;
  border-color: var(--accent);
  background: rgba(0, 0, 0, 0.4);
}

/* --- Card Styles (Worklist & Gaps) --- */
#worklist, #suggestionsList, #gaps, #pagesToc, #traceNets {
  overflow-y: auto;
  flex: 1;
  padding: 12px;
}

.wl {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.wl:hover {
  border-color: var(--mut-dark);
  background: rgba(255, 255, 255, 0.03);
  transform: translateX(2px);
}

.wl.active {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 12px rgba(59, 130, 246, 0.15);
}

.wl.confirmed {
  opacity: 0.45;
  border-color: var(--ok);
}

/* duplicate confirmed wire (A→B same as B→A): pull it out of the dimmed state
   and flag it amber so the extra copy is obvious in the list. */
.wl.dupwire {
  opacity: 1;
  border-color: #ffaa00;
  border-left: 3px solid #ffaa00;
  background: rgba(255, 170, 0, 0.06);
}
/* Wiring-list add/edit bar: the manual form re-parented here as an inline strip.
   `hidden` is neutralized for the relocated pane (it's always available in the list);
   visibility is controlled by the wiring tab, not the old drawer toggle. */
#wlAddBar { margin: 8px 12px; }
#wlAddBar #manualPane { display: block; }
/* the inline add/edit bar is always shown in the Wiring List; .hidden carries a
   global `display:none !important`, so this override must also be !important to
   win — without it the edit form fills but stays invisible (pencil "does nothing"). */
#wlAddBar #manualPane.hidden { display: block !important; }
#wlAddBar .inspect-main {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 16px;
  align-items: flex-end;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
}
#wlAddBar.capturing .inspect-main { outline: 2px solid var(--accent); outline-offset: -1px; }
#wlAddBar .inspect-meta h3 { font-size: 12px; margin: 0 0 2px; }
#wlAddBar #pickHint { font-size: 10px; margin: 0; }
#wlAddBar .manual-slots { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
#wlAddBar .slot { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 4px; }
#wlAddBar .slot.picking { background: var(--accent-glow, rgba(74,163,223,0.15)); outline: 1px solid var(--accent); }
#wlAddBar .slot .lbl { font-size: 9px; font-weight: 700; color: var(--mut); }
#wlAddBar .slot input { width: 92px; }
#wlAddBar .slot input.pin { width: 46px; }
#wlAddBar .sugg { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
#wlAddBar .sugg label { font-size: 9px; font-weight: 700; color: var(--mut); display: flex; flex-direction: column; gap: 2px; }
#wlAddBar .actions { display: flex; gap: 6px; align-items: flex-end; }
#wlAddBar .tubing-preview-container { margin-top: 0; }

/* off-page connector references (cross-page wires the auto-pairer can't complete)
   — collapsed by default so it never buries the wiring list. */
#offpageBlock, #vlmOffpage {
  margin: 8px 12px;
  border: 1px solid #4aa3df;
  border-left: 3px solid #4aa3df;
  border-radius: 6px;
  background: rgba(74, 163, 223, 0.06);
  padding: 6px 10px;
}
#vlmOffpage { margin: 0 0 6px; flex: 0 0 auto; }
#vlmOffpage .offpage-list { max-height: 120px; }
.offpage-head {
  font-size: 11px;
  font-weight: 700;
  color: #4aa3df;
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.offpage-toggle { flex: 0 0 auto; width: 10px; }
#offpageBlock.collapsed .offpage-list,
#vlmOffpage.collapsed .offpage-list { display: none; }
.offpage-list {
  margin-top: 6px;
  max-height: 180px;
  overflow-y: auto;
}
.offpage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 0;
  border-top: 1px solid rgba(74, 163, 223, 0.18);
}
.offpage-row .pair {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  flex: 0 0 auto;
}
.offpage-row .src { flex: 1; font-size: 10px; color: var(--mut); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.offpage-row .rowbtn { flex: 0 0 auto; }
.dupflag {
  flex: 0 0 auto;
  font-size: 9px;
  font-weight: 700;
  color: #ffaa00;
  background: rgba(255, 170, 0, 0.14);
  border: 1px solid rgba(255, 170, 0, 0.35);
  padding: 1px 5px;
  border-radius: 4px;
  white-space: nowrap;
}

/* multi-select: per-row checkbox + selected state + bulk action bar */
.wl .wl-sel {
  width: auto;
  min-width: 0;
  flex: 0 0 auto;
  margin: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.wl.selected {
  opacity: 1;
  border-color: var(--accent);
  background: var(--accent-glow);
}

.bulk-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  margin: 0;
  background: var(--accent-glow);
  border-bottom: 1px solid rgba(59, 130, 246, 0.4);
}

.bulk-bar .bulk-count {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

.bulk-bar .spacer {
  flex: 1;
}

.wl.confirmed:hover {
  opacity: 0.7;
}

.wl .pair {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: var(--font-mono);
  font-size: 12.5px;
  color: var(--txt);
}

.wl .src {
  font-size: 9.5px;
  color: var(--mut);
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  border-radius: 4px;
  padding: 1px 6px;
  text-transform: uppercase;
}

.wl .gc {
  font-size: 11px;
  color: var(--sugg);
  font-weight: 500;
}

/* per-row inline actions: edit (✎) + flip (⇄), revealed on hover */
.wl .rowacts {
  display: flex;
  gap: 4px;
  flex: 0 0 auto;
  opacity: 0;
  transition: opacity 0.15s;
}
.wl:hover .rowacts { opacity: 1; }
.wl .rowbtn {
  padding: 2px 6px;
  font-size: 12px;
  line-height: 1;
  border-radius: 4px;
  box-shadow: none;
  background: transparent;
  border: 1px solid var(--line);
  color: var(--mut);
}
.wl .rowbtn:hover {
  color: var(--accent);
  border-color: rgba(59, 130, 246, 0.4);
  background: var(--accent-glow);
  transform: none;
}

/* inline-edit: four tiny inputs replace the .pair span */
.wl .pair.editing {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow: visible;
}
.wl .ed-inp {
  width: 62px;
  background: rgba(0,0,0,0.3);
  color: var(--txt);
  border: 1px solid var(--line-focus);
  border-radius: 4px;
  padding: 2px 5px;
  font-family: var(--font-mono);
  font-size: 11.5px;
}
.wl .ed-inp.pin { width: 40px; }
.wl .ed-inp:focus { outline: none; border-color: var(--accent); }
.wl .ed-arrow { color: var(--mut); font-size: 11px; }

/* --- Coverage Heatmap (Canvas Underlines) --- */
.cmark {
  position: absolute;
  height: 3px;
  border-radius: 2px;
  pointer-events: none;
  opacity: 0.85;
}

.cmark.gap {
  background: var(--sugg);
  box-shadow: 0 0 4px var(--sugg);
}

.cmark.done {
  background: var(--ok);
  box-shadow: 0 0 4px var(--ok);
}

/* --- Gaps Terminal Cards --- */
.gp {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin-bottom: 6px;
  cursor: pointer;
  font-size: 12px;
  transition: all 0.2s;
}

.gp:hover {
  border-color: var(--mut-dark);
  background: rgba(255, 255, 255, 0.03);
}

.gp.st-gap:hover { border-color: rgba(245, 158, 11, 0.5); }
.gp.st-partial:hover { border-color: rgba(245, 158, 11, 0.5); }
.gp.st-full:hover { border-color: rgba(16, 185, 129, 0.5); }

.gp .pair {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 12px;
}

.gp .occ {
  color: var(--mut);
  font-size: 10.5px;
}

.gp .st {
  font-size: 13px;
  width: 16px;
  display: flex;
  align-items: center;
}

.gp.st-full .st { color: var(--ok); }
.gp.st-partial .st { color: var(--sugg); }
.gp.st-gap .st { color: var(--mut-dark); }

.gp.st-full {
  opacity: 0.5;
}
.gp.st-full:hover {
  opacity: 0.8;
}

.tally {
  font-size: 9.5px;
  font-family: var(--font-mono);
  font-weight: bold;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
}
.st-partial .tally {
  color: var(--sugg);
  border-color: rgba(245, 158, 11, 0.3);
  background: var(--sugg-glow);
}
.st-full .tally {
  color: var(--ok);
  border-color: rgba(16, 185, 129, 0.3);
  background: var(--ok-glow);
}
.st-gap .tally {
  color: var(--mut);
}

.nosugg {
  font-size: 9px;
  color: var(--sugg);
  border: 1px solid rgba(245, 158, 11, 0.4);
  background: var(--sugg-glow);
  border-radius: 4px;
  padding: 1px 5px;
  font-weight: 500;
  text-transform: uppercase;
}

/* --- Panel & Group Expansion (TOC / Library) --- */
.gp .occ {
  font-size: 10.5px;
}

.subhead {
  margin: 16px 0 8px;
  font-family: var(--font-title);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--mut);
}

.hint {
  font-size: 11px;
  color: var(--mut);
  line-height: 1.4;
  margin: 4px 0 8px;
}

/* --- Library Table --- */
.libtbl {
  border-collapse: collapse;
  font-family: var(--font-mono);
  font-size: 10px;
  width: 100%;
  margin: 6px 0 10px;
}

.libtbl th {
  text-align: left;
  color: var(--mut);
  font-size: 9px;
  font-weight: 600;
  padding: 4px 6px;
  background: rgba(255, 255, 255, 0.02);
  border-bottom: 1px solid var(--line-focus);
}

.libtbl td {
  padding: 4px 6px;
  border-top: 1px solid var(--line);
  color: var(--txt);
}

.del {
  margin-left: auto;
  background: transparent;
  border: none;
  color: var(--mut-dark);
  opacity: 0;
  padding: 0 4px;
  font-size: 12px;
  cursor: pointer;
  box-shadow: none;
}

.wl:hover .del, .gp:hover .del {
  opacity: 0.6;
}
.del:hover {
  color: var(--danger) !important;
  opacity: 1 !important;
  transform: none !important;
  box-shadow: none !important;
}

/* --- Active Inspector Tray (Bottom under canvas) --- */
#inspector-tray {
  position: relative;
  background: var(--panel);
  border-top: 1px solid var(--line);
  display: none;
}

.close-btn {
  position: absolute;
  top: 12px;
  right: 16px;
  background: transparent;
  border: none;
  color: var(--mut-dark);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  z-index: 10;
  box-shadow: none;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--txt);
  background: transparent;
  transform: none;
  box-shadow: none;
}

#inspector-tray:has(#detail:not(.hidden)),
#inspector-tray:has(#manualPane:not(.hidden)) {
  display: block;
  padding: 16px 20px;
}

.inspect-main {
  display: flex;
  gap: 32px;
  width: 100%;
  align-items: stretch;
}

.inspect-wire-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid var(--line);
  padding-right: 24px;
}

.inspect-action-section {
  flex: 1.3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.inspect-meta h3 {
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: 600;
  color: var(--txt);
  text-transform: none;
  letter-spacing: normal;
  display: flex;
  align-items: center;
  gap: 8px;
}

.inspect-meta .src {
  font-size: 10px;
  color: var(--accent);
  background: var(--accent-glow);
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid rgba(59, 130, 246, 0.2);
  font-family: var(--font-body);
}

.wire {
  display: flex;
  align-items: center;
  gap: 16px;
  margin: 12px 0;
  font-family: var(--font-mono);
  font-size: 14px;
}

.ep {
  padding: 8px 16px;
  border-radius: var(--radius-md);
  cursor: pointer;
  flex: 1;
  text-align: center;
  border: 2px solid transparent;
  font-weight: 600;
  transition: all 0.2s;
}

.ep.origin {
  background: var(--accent-glow);
  border-color: rgba(59, 130, 246, 0.4);
  color: var(--txt);
}
.ep.origin:hover {
  border-color: var(--origin);
  box-shadow: 0 0 10px var(--accent-glow);
}

.ep.dest {
  background: var(--sugg-glow);
  border-color: rgba(245, 158, 11, 0.4);
  color: var(--txt);
}
.ep.dest:hover {
  border-color: var(--dest);
  box-shadow: 0 0 10px var(--sugg-glow);
}

.arrow {
  color: var(--mut);
  font-weight: bold;
}

.occnav {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--mut);
}

.occnav b {
  color: var(--txt);
  font-family: var(--font-mono);
  margin: 0 6px;
}

.sugg {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
}

.sugg label {
  font-size: 11px;
  font-weight: 500;
  color: var(--mut);
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

input, select {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--line);
  color: var(--txt);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 12.5px;
  width: 100%;
  transition: border-color 0.2s;
  box-sizing: border-box;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--accent);
}

input.pin, select.pin {
  flex: 0 0 75px;
}

/* Verify interactive dropdown values */
.sugg input, .sugg select {
  background: rgba(0, 0, 0, 0.35);
  border-color: var(--line-focus);
}

.locmsg {
  font-size: 12px;
  color: var(--mut);
  min-height: 20px;
  margin: 4px 0 8px;
}

.locmsg .jump {
  color: var(--link);
  cursor: pointer;
  text-decoration: underline;
  margin-left: 8px;
  font-weight: 500;
}

.locmsg i {
  color: var(--mut-dark);
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* --- Manual Add Mode Panel --- */
.manual-slots {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}

.slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: rgba(255, 255, 255, 0.015);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  cursor: pointer;
  flex: 1;
  transition: all 0.2s;
}

.slot.active {
  border-color: var(--accent);
  background: var(--accent-glow);
}

/* current capture stage (FROM/TO) in one-click manual add */
.slot.picking {
  border-color: var(--accent);
  background: var(--accent-glow);
  box-shadow: 0 0 0 1px var(--accent) inset;
}

.slot .lbl {
  font-weight: bold;
  font-size: 11px;
  color: var(--mut);
  width: 44px;
}

.slot input {
  background: rgba(0,0,0,0.2);
}

.manual-actions-wrapper {
  display: flex;
  height: 100%;
  align-items: flex-end;
}

/* --- Global Progress & Status Indicators --- */
#busy {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
  overflow: hidden;
}

#busy.on {
  opacity: 1;
}

#busy.on::before {
  content: "";
  position: absolute;
  height: 100%;
  width: 35%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: busyslide 1.2s infinite ease-in-out;
}

@keyframes busyslide {
  0% { left: -35%; }
  100% { left: 100%; }
}

/* --- Premium Loading Modal Overlay --- */
#loadingModal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(4, 5, 8, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 9999;
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

#loadingModal.on {
  opacity: 1;
  pointer-events: auto;
  visibility: visible;
}

.loading-content {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 30px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  max-width: 320px;
  text-align: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(59, 130, 246, 0.1);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}

#loadingText {
  font-family: var(--font-title);
  font-size: 14px;
  font-weight: 500;
  color: var(--txt);
  letter-spacing: -0.01em;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.cov {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--accent);
  background: var(--accent-glow);
  border: 1px solid rgba(59, 130, 246, 0.3);
  padding: 4px 12px;
  border-radius: 20px;
  font-weight: 600;
}

#covSummary {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--line);
  padding: 10px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 10px;
  font-size: 11.5px;
}

#tab-coverage {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 12px;
}

#tab-coverage #gaps {
  overflow: visible;
  flex: none;
  padding: 0;
}

/* --- Toast Notification --- */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel);
  border: 1px solid var(--accent);
  box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  color: var(--txt);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  transform: translate(-50%, 10px);
  pointer-events: none;
  z-index: 1000;
  font-weight: 500;
  backdrop-filter: blur(12px);
}

#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* --- Fullscreen Mode --- */
/* Fullscreen hides only the header + drawer chrome; the side panel STAYS so the
   PDF sits left and the active tab (Wiring List, Panels VLM, Coverage, …) sits
   right — a focused two-pane view for every tab, not just VLM. */
body.fs #drawer, body.fs header {
  display: none !important;
}

body.fs #viewer {
  border-right: none;
}

body.fs #side {
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.15);
}
/* VLM fullscreen keeps the crop left + Extracted Wires right at a slightly
   narrower panel so the schematic gets more room. */
body.fs.vlm-active #side {
  width: 560px;
}

/* --- VLM focused layout: Extracted Wires dominates, controls dock at bottom --- */
#tab-vlm {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
#vlmResults {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 12px;
  gap: 10px;
  min-height: 0;
}
/* Per-crop prefill panel (VLM tab): deterministic + typical candidates for the
   current panel/page, above the extracted-wires grid. */
#vlmPrefillHost {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: 8px;
  padding: 6px;
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: 6px;
  background: rgba(16, 185, 129, 0.05);
}
.vlm-prefill-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 2px 2px 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}
.vlm-prefill-src-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  padding: 0 2px 6px;
  line-height: 1.6;
}
/* Colour-coded source badge (provenance at a glance). --badge is set inline per
   source; hover shows the full src_detail via the element title. */
.src-badge {
  display: inline-flex;
  align-items: center;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  padding: 1px 6px;
  border-radius: 999px;
  white-space: nowrap;
  color: var(--badge, #94a3b8);
  border: 1px solid color-mix(in srgb, var(--badge, #94a3b8) 48%, transparent);
  background: color-mix(in srgb, var(--badge, #94a3b8) 15%, transparent);
}
#vlmGridWrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  background: var(--bg-hover);
  min-height: 120px;
}
#vlmGridHead {
  padding: 8px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
#vlmGridHost {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  outline: none;
}

/* Controls dock (collapsible) */
#vlmControlsDock {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  background: var(--panel-light, var(--bg-hover));
  display: flex;
  flex-direction: column;
  max-height: 48%;
  min-height: 0;
}
#vlmDockHeader {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  cursor: pointer;
  user-select: none;
}
#vlmDockHeader h3 { font-size: 13px; }
#vlmDockBody {
  padding: 0 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 0;
}
#vlmControlsDock.collapsed #vlmDockBody { display: none; }
#vlmControlsDock.collapsed #vlmDockCollapseBtn { transform: rotate(180deg); }
#vlmDockRow {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
#vlmDockActions {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 220px;
}
/* narrow side panel: stack panel list above the action buttons */
@media (max-width: 720px) {
  #vlmDockRow { flex-direction: column; }
  #vlmDockActions { width: 100%; }
}

/* --- Excel-style Extracted Wires grid --- */
table.vlm-grid {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-family: var(--font-mono);
  font-size: 11px;
  table-layout: fixed;
}
table.vlm-grid th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--bg-hover);
  color: var(--mut);
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  text-align: left;
  padding: 5px 6px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  user-select: none;
}
table.vlm-grid td {
  padding: 0;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  height: 26px;
}
table.vlm-grid td.vlm-cell {
  cursor: cell;
}
table.vlm-grid td.vlm-cell > .vlm-cell-text {
  display: block;
  padding: 5px 6px;
  min-height: 16px;
  overflow: hidden;
  text-overflow: ellipsis;
}
table.vlm-grid td.sel {
  background: color-mix(in srgb, var(--accent) 18%, transparent);
}
table.vlm-grid td.active {
  box-shadow: inset 0 0 0 2px var(--accent);
}
table.vlm-grid tr.imported td {
  opacity: 0.6;
  background: rgba(45, 164, 78, 0.08);   /* imported = green tint */
}
table.vlm-grid tr.imported td:first-child { box-shadow: inset 3px 0 0 #2da44e; }
/* VLM review verdicts: left-edge tint per row + colored # marker */
table.vlm-grid tr.rev-ok    td.vlm-rownum { color: #2da44e; font-weight: 700; }
table.vlm-grid tr.rev-wrong  td { background: rgba(207, 34, 46, 0.08); }
table.vlm-grid tr.rev-wrong  td.vlm-rownum { color: #cf222e; font-weight: 700; }
table.vlm-grid tr.rev-unsure td { background: rgba(255, 170, 0, 0.08); }
table.vlm-grid tr.rev-unsure td.vlm-rownum { color: #ffaa00; font-weight: 700; }
table.vlm-grid tr.rev-added  td { background: rgba(74, 163, 223, 0.08); }
table.vlm-grid tr.rev-added  td.vlm-rownum { color: #4aa3df; font-weight: 700; }
table.vlm-grid .vlm-grid-edit {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 2px solid var(--accent);
  box-sizing: border-box;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 4px 5px;
  background: var(--bg);
  color: inherit;
  z-index: 3;
}
table.vlm-grid td.vlm-rownum,
table.vlm-grid th.vlm-rownum {
  width: 30px;
  text-align: center;
  color: var(--mut);
  background: var(--bg-hover);
  font-size: 9px;
  cursor: default;
  user-select: none;
}
table.vlm-grid td.vlm-act {
  width: 34px;
  text-align: center;
}
/* source badge column + prefill-row tint (deterministic prefill vs VLM-read) */
table.vlm-grid td.vlm-src,
table.vlm-grid th.vlm-src {
  width: 62px;
  text-align: center;
  padding: 3px 4px;
  background: var(--bg-hover);
}
table.vlm-grid tr.prefill-row td {
  background: color-mix(in srgb, #8b5cf6 8%, transparent);
}
table.vlm-grid tr.prefill-row td.vlm-rownum {
  box-shadow: inset 3px 0 0 color-mix(in srgb, #8b5cf6 60%, transparent);
}
.vlm-fill-handle {
  position: absolute;
  right: -3px;
  bottom: -3px;
  width: 7px;
  height: 7px;
  background: var(--accent);
  border: 1px solid var(--bg);
  cursor: crosshair;
  z-index: 4;
}
.vlm-del-btn, .vlm-imp-btn {
  cursor: pointer;
  background: none;
  border: none;
  font-size: 12px;
  padding: 2px 3px;
  line-height: 1;
}
.vlm-del-btn { color: var(--danger, #cf222e); }
.vlm-imp-btn { color: #2da44e; font-weight: 700; }
table.vlm-grid td.vlm-act { width: 50px; white-space: nowrap; }
table.vlm-grid th.trace-act,
table.vlm-grid td.trace-act {
  width: 232px;
  min-width: 232px;
  overflow: visible;
  text-align: right;
  padding: 0 4px;
}
table.vlm-grid td.trace-act {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}
table.vlm-grid td.trace-act .rowbtn,
table.vlm-grid td.trace-act .vlm-imp-btn,
table.vlm-grid td.trace-act .vlm-del-btn {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  background: var(--panel-light);
  border-radius: 4px;
  padding: 2px 5px;
  font-size: 10px;
  line-height: 1.2;
}

/* --- GSPE Tubing Marker Preview Styles --- */
.tubing-preview-container {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px dashed var(--line);
  padding: 8px 14px;
  border-radius: var(--radius-md);
  margin-top: 8px;
}

.tubing-preview-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--mut-dark);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.tubing-code {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--txt);
}

.tubing-code .t-origin {
  color: var(--origin);
}

.tubing-code .t-dest {
  color: var(--dest);
}

.tubing-code .t-sep {
  color: var(--mut-dark);
  margin: 0 6px;
}


/* Modal overlay and structure */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 10000;
  backdrop-filter: blur(3px);
}
.modal.hidden {
  display: none !important;
}
.modal-content {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Library type-filter chips (Projects tab) — organise typicals by OHL/TRAFO/… */
.libtype-filter { display: flex; flex-wrap: wrap; gap: 4px; margin: 2px 0 8px; }
.libtype-chip {
  font-size: 11px; padding: 2px 9px; border: 1px solid var(--line-focus);
  border-radius: 12px; background: transparent; color: var(--fg, #cbd5e1);
  cursor: pointer; transition: background .12s, border-color .12s, color .12s;
}
.libtype-chip:hover { border-color: var(--accent); }
.libtype-chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.libtype-chip b { opacity: .65; font-weight: 600; margin-left: 1px; }
