:root {
  --bg: #1b1e24;
  --bg2: #22262e;
  --fg: #d8dbe2;
  --dim: #8a90a0;
  --accent: #4da3ff;
  --line: #343a46;
  --hl: #ffcc00;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--fg);
  font: 13px/1.5 "Segoe UI", "Microsoft YaHei", sans-serif;
  overflow: hidden;
}

#topbar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: var(--bg2); border-bottom: 1px solid var(--line);
  flex: none;
}
#logo { font-size: 15px; letter-spacing: 1px; color: var(--dim); margin-right: 6px; }
#logo b { color: var(--accent); }
button {
  background: #2c313b; color: var(--fg); border: 1px solid var(--line);
  border-radius: 4px; padding: 4px 12px; cursor: pointer; font: inherit;
}
button:hover { border-color: var(--accent); color: #fff; }
select {
  background: #2c313b; color: var(--fg); border: 1px solid var(--line);
  border-radius: 4px; padding: 3px 6px; font: inherit; max-width: 260px;
}
#fmt-badge {
  background: #244; color: #7fd7c4; border: 1px solid #366;
  padding: 2px 8px; border-radius: 10px; font-size: 12px;
}
#stats { color: var(--dim); font-size: 12px; }
.spacer { flex: 1; }

#warnbar {
  flex: none; background: #4a3c14; color: #ffd97a; border-bottom: 1px solid #6b581e;
  padding: 4px 12px; font-size: 12px; max-height: 72px; overflow-y: auto; white-space: pre-line;
}

#layout { flex: 1; display: flex; min-height: 0; }
#viewer { flex: 1; position: relative; overflow: hidden; background: #14161a; }
#sidebar {
  width: 380px; flex: none; display: flex; flex-direction: column;
  border-left: 1px solid var(--line); background: var(--bg2); min-height: 0;
}
#tabs { display: flex; flex: none; border-bottom: 1px solid var(--line); }
#tabs button {
  flex: 1; border: none; border-radius: 0; background: transparent;
  padding: 7px 0; color: var(--dim); border-bottom: 2px solid transparent;
}
#tabs button.active { color: #fff; border-bottom-color: var(--accent); }
.panel { display: none; flex: 1; overflow: auto; padding: 6px; min-height: 0; }
.panel.active { display: block; }

/* 表格 */
table { border-collapse: collapse; width: 100%; font-size: 12px; }
th, td { border-bottom: 1px solid var(--line); padding: 3px 6px; text-align: left; vertical-align: top; }
th { color: var(--dim); position: sticky; top: 0; background: var(--bg2); font-weight: 600; }
tr:hover td { background: #2a2f39; }
td.num { text-align: right; color: var(--dim); }

/* BOM 导出属性选择 */
.bom-options {
  margin-bottom: 7px; padding: 7px; border: 1px solid var(--line); border-radius: 5px;
  background: #1e2229;
}
.bom-options-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.bom-options-head b { color: var(--accent); font-weight: 500; }
.bom-actions { display: flex; gap: 4px; }
.bom-actions button { padding: 2px 7px; font-size: 11px; }
.bom-columns { display: flex; flex-wrap: wrap; gap: 3px 10px; margin-top: 6px; }
.bom-columns label { white-space: nowrap; color: var(--fg); font-size: 12px; cursor: pointer; }
.bom-columns label.custom { color: #9fd0ff; }
.bom-columns input { margin: 0 3px 0 0; vertical-align: -1px; }
.bom-options-note { margin-top: 5px; color: var(--dim); font-size: 11px; }

/* 网络列表 */
.netrow { padding: 3px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.netrow:hover { background: #2a2f39; }
.netrow.sel { background: #34405a; }
.netrow .nname { color: var(--accent); }
.netrow .npins { color: var(--dim); font-size: 11px; word-break: break-all; }
.net-sec { color: var(--dim); padding: 8px 6px 2px; font-weight: 600; }

/* 拖放提示 */
#drop-hint {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
}
.hint-box { text-align: center; color: var(--fg); }
.hint-box .dim { color: var(--dim); font-size: 12px; }
body.dragover #viewer { outline: 3px dashed var(--accent); outline-offset: -8px; }

/* 骨架 SVG 视图: 浅色"图纸"风(对齐 EDA 打印观感), 文字/引脚随缩放同步缩放 */
#skel-wrap { position: absolute; inset: 0; display: flex; flex-direction: column; }
#skel-tabs { flex: none; display: flex; gap: 4px; padding: 4px 8px; background: rgba(34,38,46,.9); overflow-x: auto; }
#skel-tabs button { padding: 2px 10px; font-size: 12px; }
#skel-tabs button.active { border-color: var(--accent); color: #fff; }
#skel-svg-box { flex: 1; min-height: 0; cursor: grab; background: #fcfbf4; }
#skel-svg-box:active { cursor: grabbing; }
#skel-svg-box svg { width: 100%; height: 100%; display: block; }
.sk-ghost { fill: #fdf3c2; stroke: #a08c3c; stroke-width: 1; vector-effect: non-scaling-stroke; }
.sk-seg { stroke: #007a2f; stroke-width: 1.2; vector-effect: non-scaling-stroke; }
.sk-seg.sk-bus { stroke: #8b7800; stroke-width: 4; stroke-linecap: round; }
.sk-seg.nonet { stroke: #9aa2ac; }
.sk-seg.hl { stroke: #e69500; stroke-width: 3; }
.sk-drawing { fill: none; stroke: #a42626; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.sk-drawing.fill { fill: #a42626; stroke: none; }
.sk-pin { fill: #c0392b; }
.sk-pin.hl { fill: #e69500; stroke: #a56a00; stroke-width: 1; vector-effect: non-scaling-stroke; }
/* 符号级模式: 引脚点隐形只留悬停; 描点=导线交叉(TIEDOTS), 与导线同色 */
.sk-pin.ghost { fill: transparent; pointer-events: all; }
.sk-pin.ghost.hl { fill: #e69500; }
.sk-dot { fill: #007a2f; }
.sk-ref { fill: #000080; font-family: "Times New Roman", serif; }
.sk-lbl { fill: #4a6ea8; font-family: "Times New Roman", serif; }
.sk-symlabel { fill: #4c3a13; font-family: "Times New Roman", serif; }
/* 符号级(PADS CAEDECAL): 真实符号外形 + 引脚号 + 型号 */
.sk-sym { fill: none; stroke: #7a1f1f; stroke-width: 1.4; vector-effect: non-scaling-stroke; stroke-linejoin: round; stroke-linecap: round; }
.sk-sym.fill { fill: #7a1f1f; stroke: none; }
.sk-pinno { fill: #6a4a00; font-family: "Times New Roman", serif; }
.sk-parttype { fill: #5a2d00; font-family: "Times New Roman", serif; }

/* Altium canvas 容器: 实时渲染视口 */
#alt-wrap { position: absolute; inset: 0; overflow: hidden; cursor: grab; }
#alt-wrap:active { cursor: grabbing; }
#alt-wrap canvas.rt { width: 100%; height: 100%; display: block; }

/* 点击详情卡片 */
.detail-card {
  position: absolute; z-index: 10; max-width: 300px; max-height: 62%;
  overflow: auto; padding: 8px 10px;
  background: rgba(28, 31, 38, .96); border: 1px solid var(--accent); border-radius: 6px;
  font-size: 12px; color: var(--fg); box-shadow: 0 4px 16px rgba(0,0,0,.5);
  cursor: default;
}
.detail-card .dc-title { font-size: 13px; font-weight: 600; color: var(--accent); margin-bottom: 4px; }
.detail-card .dc-sec { color: var(--dim); margin: 6px 0 2px; font-weight: 600; }
.detail-card table { width: 100%; }
.detail-card td { border-bottom: 1px solid var(--line); padding: 2px 4px; vertical-align: top; }
.detail-card td:first-child { color: var(--dim); white-space: nowrap; }
.detail-card .dc-net { color: var(--hl); cursor: pointer; text-decoration: underline; }
.detail-card .dc-pins { word-break: break-all; }

/* KiCanvas */
kicanvas-embed { position: absolute; inset: 0; width: 100%; height: 100%; }

.viewer-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--dim); text-align: center; padding: 30px;
}

/* 触摸设备: 阻止浏览器抢占手势, 交给应用的拖拽/捏合 */
#alt-wrap, #skel-svg-box, kicanvas-embed { touch-action: none; }

/* 侧栏收合 */
body.side-collapsed #sidebar { display: none; }
body.side-collapsed #btn-side { border-color: var(--accent); color: #fff; }

/* 手机/窄屏: 上下布局, 侧栏变底部抽屉 */
@media (max-width: 820px) {
  #topbar { flex-wrap: wrap; gap: 4px; padding: 4px 6px; }
  #logo { display: none; }
  #stats { order: 10; width: 100%; }
  #main-select { max-width: 46vw; }
  button { padding: 5px 10px; }
  #layout { flex-direction: column; }
  #sidebar {
    width: 100%; height: 42%; flex: none;
    border-left: none; border-top: 1px solid var(--line);
  }
  .detail-card { max-width: 86vw; max-height: 46%; }
  .hint-box { padding: 0 14px; }
  .hint-box .dim { font-size: 11px; }
}

/* 解析加载遮罩: transform 动画由合成器驱动, 主线程解析阻塞时仍旋转 */
#loading-mask {
  position: fixed; inset: 0; z-index: 99;
  display: none; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  background: rgba(20, 22, 26, .55); backdrop-filter: blur(1px);
}
#loading-mask .spin {
  width: 42px; height: 42px; border-radius: 50%;
  border: 4px solid rgba(255,255,255,.25); border-top-color: #6cf;
  animation: ldspin .8s linear infinite;
}
#loading-mask .loading-text { color: #dfe6ee; font-size: 14px; letter-spacing: .5px; }
@keyframes ldspin { to { transform: rotate(360deg); } }

/* 导出清晰度弹窗 */
.pick-mask { position: fixed; inset: 0; z-index: 100; display: flex; align-items: center; justify-content: center;
  background: rgba(18,20,24,.55); backdrop-filter: blur(2px); }
.pick-box { background: #23272e; color: #e6ebf1; border: 1px solid #3a4048; border-radius: 10px;
  padding: 18px 20px; min-width: 320px; box-shadow: 0 12px 40px rgba(0,0,0,.5); }
.pick-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.pick-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pick-opts button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: 10px 12px; border: 1px solid #3a4048; border-radius: 8px; background: #2b3039; color: #e6ebf1;
  cursor: pointer; text-align: left; }
.pick-opts button:hover { border-color: #6cf; background: #313945; }
.pick-opts button b { font-size: 14px; }
.pick-opts button span { font-size: 11px; color: #9aa4b0; }
.pick-cancel { margin-top: 14px; width: 100%; padding: 8px; border: 1px solid #3a4048; border-radius: 8px;
  background: transparent; color: #9aa4b0; cursor: pointer; }
.pick-cancel:hover { color: #e6ebf1; border-color: #556; }

/* 最近打开列表 */
.rec-box { min-width: 420px; max-width: 560px; }
.rec-list { max-height: 46vh; overflow: auto; display: flex; flex-direction: column; gap: 6px; }
.rec-item { display: flex; align-items: center; gap: 10px; padding: 8px 10px; cursor: pointer;
  border: 1px solid #3a4048; border-radius: 8px; background: #2b3039; }
.rec-item:hover { border-color: #6cf; background: #313945; }
.rec-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.rec-info b { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rec-info span { font-size: 11px; color: #9aa4b0; }
.rec-del { flex: none; width: 24px; height: 24px; line-height: 1; border: 0; border-radius: 6px;
  background: transparent; color: #8b949e; cursor: pointer; font-size: 16px; }
.rec-del:hover { background: #4a2b2b; color: #ff9d9d; }
.rec-clear { margin-top: 8px; width: 100%; padding: 6px; border: 1px solid #3a4048; border-radius: 8px;
  background: transparent; color: #8b949e; cursor: pointer; font-size: 12px; }
.rec-clear:hover { color: #e6ebf1; }
.rec-empty { color: #8b949e; font-size: 12px; padding: 10px 0; }
/* 首屏拖入提示里的最近列表 */
.rec-onhint { margin-top: 16px; text-align: left; }
