/* PCB Assembly Viewer - dark professional theme */
:root {
  --bg: #15181d;
  --bg-2: #1c2027;
  --bg-3: #232833;
  --bg-4: #2b313d;
  --line: #313845;
  --line-2: #3d4554;
  --fg: #e3e7ee;
  --fg-2: #aab2bf;
  --fg-3: #7d8697;
  --accent: #3b8ff2;
  --accent-2: #2b6fc4;
  --sel: #ffd23f;
  --ok: #38c172;
  --teal: #2fbfb0;
  --warn: #f2a33b;
  --amber: #f2a33b;
  --err: #ef5350;
  --grey: #8a93a3;
  --purple: #a678e8;
  --shadow: 0 8px 28px rgba(0,0,0,.45);
  --radius: 6px;
  --panel-w: 380px;
  --toolbar-h: 40px;
  --status-h: 24px;
  --font: 13px/1.35 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
  --mono: 12px/1.3 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--fg);
  font: var(--font);
  display: grid;
  grid-template-rows: var(--toolbar-h) auto 1fr var(--status-h);
  grid-template-areas: "toolbar" "banner" "main" "status";
  overflow: hidden;
  min-width: 900px;
}
body.panel-hidden { --panel-w: 0px; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: .45; cursor: default; }
kbd { font: 11px/1 var(--mono); background: var(--bg-4); border: 1px solid var(--line-2); border-radius: 3px; padding: 1px 4px; color: var(--fg-2); margin-left: 6px; }
.muted { color: var(--fg-3); }
.small { font-size: 12px; }
.spacer { flex: 1; }
.grow { flex: 1; }
[hidden] { display: none !important; }
a { color: var(--accent); }

/* ---------- Toolbar ---------- */
.toolbar {
  grid-area: toolbar;
  display: flex; align-items: center; gap: 4px;
  padding: 0 8px; background: var(--bg-2); border-bottom: 1px solid var(--line);
  white-space: nowrap; overflow: hidden;
}
.brand { font-weight: 600; letter-spacing: .2px; margin-right: 8px; color: var(--fg); }
.brand span { color: var(--fg-3); font-weight: 400; }
.tb, .seg > button, .mini, .primary {
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--fg);
  border-radius: var(--radius); padding: 4px 9px; line-height: 1.2; height: 28px;
}
.tb:hover, .seg > button:hover, .mini:hover { background: var(--bg-4); }
.tb.icon { width: 28px; padding: 0; font-size: 16px; }
.tb.danger, .menu-item.danger { color: #ffb4b2; }
.tb.danger:hover { background: #4a2626; }
.primary { background: var(--accent); border-color: var(--accent-2); color: #fff; font-weight: 600; }
.primary:hover { background: #4d9bf5; }
.mini { height: 24px; padding: 2px 8px; font-size: 12px; }
.seg { display: inline-flex; }
.seg > button { border-radius: 0; margin-left: -1px; }
.seg > button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.seg > button:last-child, .seg > button:nth-last-child(2):has(+ [hidden]) { border-radius: 0 var(--radius) var(--radius) 0; }
.seg > button.on { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
.sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 4px; }
.readout { font: var(--mono); color: var(--fg-2); padding: 0 6px; }
.count { background: var(--bg-4); border-radius: 10px; padding: 0 6px; font-size: 11px; color: var(--fg-2); }
.caret { font-size: 10px; color: var(--fg-3); margin-left: 2px; }
.menu-btn.open { background: var(--bg-4); }

/* ---------- Banner ---------- */
.banner-slot { grid-area: banner; display: flex; flex-direction: column; }
.banner { display: flex; align-items: center; gap: 10px; padding: 5px 12px; font-size: 12.5px; border-bottom: 1px solid var(--line); background: #2d2a1e; color: #f5deb3; }
.banner.error { background: #3a2222; color: #ffc9c7; }
.banner.info { background: #1f2a3a; color: #cfe2ff; }
.banner .close { margin-left: auto; background: none; border: 0; color: inherit; opacity: .7; font-size: 14px; }
.banner .close:hover { opacity: 1; }
.banner button.link { background: none; border: 0; color: var(--accent); text-decoration: underline; padding: 0; }

/* ---------- Main layout ---------- */
#main {
  grid-area: main; position: relative; min-height: 0;
  display: grid; grid-template-columns: 1fr 6px var(--panel-w);
}
body.panel-hidden #main { grid-template-columns: 1fr 0 0; }
body.panel-hidden #splitter, body.panel-hidden #panel { display: none; }
#stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
#canvas-host { position: relative; flex: 1; min-height: 120px; background: #0f1115; overflow: hidden; }
#canvas2d { position: absolute; inset: 0; width: 100%; height: 100%; display: block; outline: none; touch-action: none; }
#view3d-host { position: absolute; inset: 0; }
#view3d-host canvas { display: block; }
.hover-readout { position: absolute; left: 8px; top: 8px; font: var(--mono); color: var(--fg-2); background: rgba(20,24,30,.75); padding: 2px 6px; border-radius: 4px; pointer-events: none; }
.empty-hint { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--fg-3); pointer-events: none; }

/* ---------- Splitter ---------- */
.splitter { background: var(--line); cursor: col-resize; position: relative; }
.splitter:hover, .splitter.drag { background: var(--accent-2); }

/* ---------- Dock ---------- */
.dock { border-top: 1px solid var(--line); background: var(--bg-2); max-height: 42%; display: flex; flex-direction: column; flex: 0 0 auto; }
.dock.collapsed .dock-body { display: none; }
.dock-head { display: flex; align-items: center; gap: 8px; padding: 4px 10px; background: var(--bg-3); border-bottom: 1px solid var(--line); font-weight: 600; }
.dock-body { overflow: auto; padding: 8px 10px; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 12px; align-content: start; }
.dock-body:empty { padding: 0; }
.dock-section { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); min-width: 0; }
.dock-section > summary, .dock-section > .sec-title { padding: 4px 8px; background: var(--bg-3); font-weight: 600; cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; border-radius: var(--radius) var(--radius) 0 0; }
.dock-section > summary::-webkit-details-marker { display: none; }
.dock-section > summary::before { content: "▸"; color: var(--fg-3); font-size: 11px; }
.dock-section[open] > summary::before { content: "▾"; }
.dock-section .sec-body { padding: 6px 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 12.5px; }
.kv dt { color: var(--fg-3); white-space: nowrap; }
.kv dd { margin: 0; min-width: 0; word-break: break-word; font-variant-numeric: tabular-nums; }
.kv dd.mono { font: var(--mono); }
.dock table { border-collapse: collapse; width: 100%; font: var(--mono); }
.dock th, .dock td { border-bottom: 1px solid var(--line); padding: 2px 6px; text-align: left; white-space: nowrap; }
.dock th { color: var(--fg-3); font-weight: 500; }
.dock .scroll-x { overflow: auto; max-height: 180px; }
.dock ul { margin: 4px 0; padding-left: 18px; }
.dock li.conflict { color: var(--warn); }
.decision { display: flex; flex-direction: column; gap: 6px; }
.decision textarea { width: 100%; min-height: 40px; resize: vertical; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 4px 6px; }
.decision .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.multi-list { display: flex; flex-wrap: wrap; gap: 4px; }
.multi-list .chip { cursor: pointer; }
.snapshot-preview { max-width: 100%; border: 1px solid var(--line-2); border-radius: 4px; }

/* ---------- Panel ---------- */
.panel { background: var(--bg-2); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--bg-3); }
.tab-btn { flex: 1; background: none; border: 0; border-bottom: 2px solid transparent; padding: 7px 8px; color: var(--fg-2); }
.tab-btn.on { color: var(--fg); border-bottom-color: var(--accent); }
.tab { display: none; flex: 1; min-height: 0; flex-direction: column; }
.tab.on { display: flex; }
.tab-body { overflow: auto; padding: 8px 10px; flex: 1; }
.side-tabs { display: flex; gap: 2px; padding: 6px 8px 0; }
.side-tabs > button { flex: 1; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 4px 4px 0 0; color: var(--fg-2); padding: 4px; }
.side-tabs > button.on { background: var(--bg-4); color: var(--fg); border-bottom-color: var(--bg-4); }
.side-tabs .n { color: var(--fg-3); font-size: 11px; margin-left: 4px; }
.filters { display: flex; gap: 4px; padding: 6px 8px; }
.filters input, .filters select, .tab-body input[type=text], .tab-body input[type=number], .tab-body select, .fm-table select, .fm-table input {
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 4px; padding: 3px 6px; height: 26px; min-width: 0;
}
.filters input { flex: 2; }
.filters select { flex: 1; max-width: 46%; }
.chips { display: flex; flex-wrap: wrap; gap: 3px; padding: 0 8px 6px; }
.chip { display: inline-flex; align-items: center; gap: 4px; border: 1px solid var(--line-2); border-radius: 10px; padding: 0 7px; height: 20px; font-size: 11px; background: var(--bg-3); color: var(--fg-2); cursor: pointer; user-select: none; }
.chip:hover { background: var(--bg-4); }
.chip.on { border-color: var(--accent); color: var(--fg); background: rgba(59,143,242,.15); }
.chip .n { color: var(--fg); font-weight: 600; }
.chip.zero { opacity: .5; }
.list-tools { display: flex; align-items: center; gap: 4px; padding: 0 8px 6px; }
.list { flex: 1; overflow: auto; border-top: 1px solid var(--line); }
.list .empty { padding: 14px; color: var(--fg-3); text-align: center; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 0 6px; padding: 4px 8px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.row:hover { background: var(--bg-3); }
.row.sel { background: rgba(255,210,63,.13); box-shadow: inset 3px 0 0 var(--sel); }
.row.dnp { opacity: .6; }
.row .l1 { display: flex; align-items: baseline; gap: 6px; min-width: 0; grid-column: 1; grid-row: 1; }
.row .ref { font-weight: 600; font-variant-numeric: tabular-nums; }
.row .val { color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .l2 { color: var(--fg-3); font-size: 11.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; grid-column: 1; grid-row: 2; }
.row .r { display: flex; align-items: center; gap: 4px; grid-column: 2; grid-row: 1 / span 2; }
.row.sub { padding-left: 20px; }
.grp { display: flex; align-items: center; gap: 6px; padding: 5px 8px; background: var(--bg-3); border-bottom: 1px solid var(--line); cursor: pointer; font-weight: 600; position: sticky; top: 0; z-index: 1; }
.grp:hover { background: var(--bg-4); }
.grp .n { color: var(--fg-3); font-weight: 400; font-size: 11px; }
.grp .val { color: var(--fg-2); font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.tag { display: inline-block; font-size: 10px; border: 1px solid var(--line-2); border-radius: 3px; padding: 0 4px; color: var(--fg-3); text-transform: uppercase; letter-spacing: .3px; }
.side-l { display: inline-block; width: 16px; height: 16px; line-height: 16px; text-align: center; border-radius: 3px; font-size: 10px; font-weight: 700; background: var(--bg-4); color: var(--fg-2); }
.side-l.bottom { background: #3a2f4f; color: #d7c5f5; }

/* ---------- Badges ---------- */
.badge { display: inline-block; font-size: 10.5px; font-weight: 600; border-radius: 3px; padding: 1px 5px; line-height: 14px; border: 1px solid transparent; white-space: nowrap; }
.badge.tiny { font-size: 9px; padding: 0 4px; line-height: 12px; }
.badge.st-ok { background: rgba(56,193,114,.2); color: var(--ok); }
.badge.st-ok-geometry { background: rgba(47,191,176,.2); color: var(--teal); }
.badge.st-ok-user-verified { background: transparent; color: var(--ok); border-color: var(--ok); }
.badge.st-offset { background: rgba(242,163,59,.2); color: var(--warn); }
.badge.st-missing { background: rgba(138,147,163,.2); color: var(--grey); }
.badge.st-not-in-bom { background: rgba(166,120,232,.22); color: var(--purple); }
.badge.st-outside, .badge.st-side { background: rgba(239,83,80,.2); color: var(--err); }
.badge.st-unverified, .badge.st-no-pnp { background: rgba(138,147,163,.15); color: var(--grey); border-color: var(--line-2); }
.badge.st-unknown { background: var(--bg-4); color: var(--fg-2); }
.badge.dnp { background: var(--bg-4); color: var(--fg-3); }
.obadge { display: inline-flex; align-items: center; gap: 2px; font: 600 10.5px/14px var(--mono); border-radius: 3px; padding: 0 4px; border: 1px solid var(--line-2); color: var(--fg-3); background: var(--bg-3); white-space: nowrap; }
.obadge.pass { color: var(--ok); border-color: rgba(56,193,114,.5); }
.obadge.warning { color: var(--amber); border-color: rgba(242,163,59,.5); }
.obadge.fail { color: var(--err); border-color: rgba(239,83,80,.6); background: rgba(239,83,80,.12); }
.obadge.unknown { color: var(--grey); }
.obadge.na { opacity: .45; }
.verdict { font-weight: 700; }
.verdict.PASS { color: var(--ok); } .verdict.WARNING { color: var(--amber); } .verdict.FAIL { color: var(--err); } .verdict.UNKNOWN, .verdict.NA { color: var(--grey); }
.conf-high { color: var(--ok); } .conf-medium { color: var(--amber); } .conf-low { color: var(--fg-3); }

/* ---------- Layers / Align tabs ---------- */
.layer-row { display: grid; grid-template-columns: 18px 26px 1fr auto; gap: 6px; align-items: center; padding: 3px 0; border-bottom: 1px solid var(--line); }
.layer-row input[type=color] { width: 26px; height: 20px; padding: 0; border: 1px solid var(--line-2); border-radius: 3px; background: none; }
.layer-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-row .meta { color: var(--fg-3); font-size: 11px; }
.layer-row.active { background: rgba(59,143,242,.12); }
.layer-row.hidden-layer { opacity: .55; }
.field { display: grid; grid-template-columns: 1fr auto; gap: 6px; align-items: center; padding: 3px 0; }
.field > label { color: var(--fg-2); }
.field input[type=number] { width: 84px; text-align: right; }
.field select { max-width: 200px; }
.field.wide { grid-template-columns: 1fr; }
.field .pair { display: flex; gap: 4px; }
h3.sec { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--fg-3); margin: 12px 0 4px; }
h3.sec:first-child { margin-top: 0; }
.sugg { border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 8px; margin-bottom: 6px; background: var(--bg); }
.sugg .head { display: flex; align-items: center; gap: 6px; }
.sugg .label { flex: 1; font-weight: 600; }
.sugg .ev { color: var(--fg-3); font-size: 11.5px; margin: 4px 0 0; padding-left: 14px; }
.conf { font-size: 10px; border-radius: 3px; padding: 0 4px; text-transform: uppercase; }
.conf.high { background: rgba(56,193,114,.2); color: var(--ok); }
.conf.medium { background: rgba(242,163,59,.2); color: var(--amber); }
.conf.low { background: var(--bg-4); color: var(--fg-3); }
.sugg.applied { border-color: rgba(56,193,114,.4); }
.origin-pt { font: var(--mono); color: var(--fg-2); }

/* ---------- Status bar ---------- */
.statusbar { grid-area: status; display: flex; align-items: center; gap: 16px; padding: 0 10px; background: var(--bg-2); border-top: 1px solid var(--line); font-size: 12px; color: var(--fg-2); white-space: nowrap; overflow: hidden; }
.statusbar span { overflow: hidden; text-overflow: ellipsis; }
.statusbar .progress { color: var(--accent); }
#st-cursor { font: var(--mono); min-width: 170px; text-align: right; }

/* ---------- Menus ---------- */
.menu { position: fixed; z-index: 60; min-width: 220px; max-width: 420px; background: var(--bg-3); border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow); padding: 4px 0; display: none; max-height: calc(100vh - 60px); overflow: auto; }
.menu.open { display: block; }
.menu-title { padding: 4px 12px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--fg-3); }
.menu-item { display: flex; align-items: center; gap: 8px; width: 100%; text-align: left; padding: 5px 12px; background: none; border: 0; color: var(--fg); cursor: pointer; }
.menu-item:hover { background: var(--bg-4); }
.menu-item.range { flex-wrap: wrap; }
.menu-item.range > span { flex: 1; color: var(--fg-2); }
.menu-item.range input[type=range] { width: 120px; }
.menu-item.range output { font: var(--mono); color: var(--fg-2); min-width: 32px; text-align: right; }
.menu-item.range select { background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 4px; padding: 2px 4px; }
.menu-item kbd { margin-left: auto; }
.menu-sep { height: 1px; background: var(--line-2); margin: 4px 0; }
.menu-info { padding: 2px 12px 6px; font-size: 12px; }
.menu-info .kv { margin: 2px 0; }
.menu-list { max-height: 260px; overflow: auto; }
.menu-file { display: grid; grid-template-columns: 1fr auto; gap: 2px 8px; padding: 3px 12px; font-size: 12px; }
.menu-file .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu-file .err { grid-column: 1 / -1; color: var(--err); font-size: 11px; }

/* ---------- Overlays ---------- */
.overlay { position: fixed; inset: var(--toolbar-h) 0 0 0; z-index: 40; }
.overlay.start { background: var(--bg); overflow: auto; }
.overlay.drop { background: rgba(59,143,242,.18); border: 3px dashed var(--accent); z-index: 80; display: flex; align-items: center; justify-content: center; pointer-events: none; }
.drop-msg { background: var(--bg-3); border: 1px solid var(--accent); border-radius: 8px; padding: 14px 24px; font-size: 16px; }
.start-inner { max-width: 1040px; margin: 0 auto; padding: 28px 24px 40px; }
.start-head { position: relative; margin-bottom: 18px; }
.start-head h1 { margin: 0 0 6px; font-size: 22px; font-weight: 600; }
.start-head p { margin: 0; max-width: 780px; }
#start-close { position: absolute; right: 0; top: 0; }
.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.card { background: var(--bg-2); border: 1px dashed var(--line-2); border-radius: 8px; padding: 12px; min-height: 170px; display: flex; flex-direction: column; gap: 8px; outline: none; }
.card:focus { border-color: var(--accent); }
.card.over { border-color: var(--accent); background: rgba(59,143,242,.12); border-style: solid; }
.card.has { border-style: solid; border-color: var(--line-2); }
.card-title { font-weight: 600; display: flex; flex-direction: column; gap: 2px; }
.card-hint { color: var(--fg-3); font-weight: 400; font-size: 11.5px; }
.card-list { flex: 1; font-size: 12px; display: flex; flex-direction: column; gap: 2px; max-height: 220px; overflow: auto; }
.card-file { display: flex; align-items: center; gap: 6px; padding: 2px 4px; border-radius: 3px; background: var(--bg-3); }
.card-file .name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-file .size { color: var(--fg-3); font-size: 11px; }
.card-file .x { background: none; border: 0; color: var(--fg-3); padding: 0 2px; }
.card-file .x:hover { color: var(--err); }
.card-file.err { outline: 1px solid var(--err); }
.card-actions { display: flex; gap: 6px; }
.start-actions { display: flex; align-items: center; gap: 8px; margin-top: 16px; }
.start-actions .primary { height: 32px; padding: 0 18px; }
#start-status { margin-top: 10px; min-height: 18px; }

/* ---------- Dialogs ---------- */
.dialog { background: var(--bg-2); color: var(--fg); border: 1px solid var(--line-2); border-radius: 8px; padding: 0; box-shadow: var(--shadow); max-width: min(96vw, 560px); width: 100%; }
.dialog.wide { max-width: min(96vw, 1080px); }
.dialog::backdrop { background: rgba(0,0,0,.55); }
.dialog-form { display: flex; flex-direction: column; max-height: 86vh; }
.dialog-head { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--line); }
.dialog-head h2 { margin: 0; font-size: 15px; }
.dialog-body { padding: 12px 14px; overflow: auto; }
.dialog-foot { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.fm-table table { width: 100%; border-collapse: collapse; font-size: 12px; }
.fm-table th, .fm-table td { text-align: left; padding: 4px 6px; border-bottom: 1px solid var(--line); vertical-align: middle; white-space: nowrap; }
.fm-table th { color: var(--fg-3); font-weight: 500; font-size: 11px; text-transform: uppercase; }
.fm-table td.name { max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.fm-table td.err { color: var(--err); white-space: normal; font-size: 11px; }
.fm-table tr.ignored { opacity: .55; }
.fm-table input[type=number] { width: 70px; text-align: right; }
.fm-table .x { background: none; border: 0; color: var(--fg-3); }
.fm-table .x:hover { color: var(--err); }

/* ---------- Snapshot box ---------- */
#snapshot-box { position: fixed; left: -2000px; top: 0; width: 600px; height: 400px; overflow: hidden; pointer-events: none; }
#snapshot-canvas { width: 600px; height: 400px; display: block; }

/* ---------- Responsive ---------- */
@media (max-width: 1250px) {
  .brand span { display: none; }
  #btn-clear { font-size: 12px; padding: 4px 6px; }
  .cards { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 1100px) {
  :root { --panel-w: 320px; }
  .toolbar .readout { display: none; }
  .filters select { max-width: 40%; }
  .dock-body { grid-template-columns: 1fr; }
}
