/* 电路仿真工作台（/simlab/native/circuit/）。
 * 三栏 grid + 底部输出条；颜色与圆角沿用 site.css 的 token。
 */

.cwb-head { align-items: flex-start; }

.cwb {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr) 292px;
  gap: 12px;
  align-items: start;
  margin-bottom: 14px;
}

.cwb-left, .cwb-center, .cwb-right { padding: 12px 12px 14px; min-width: 0; }
.cwb-left, .cwb-right { display: flex; flex-direction: column; gap: 10px; }

.cwb-pane-head { display: flex; align-items: center; gap: 8px; }
.cwb-pane-head h2 { margin: 0; font-size: 15px; }
.cwb-pane-head-sub { margin-top: 6px; }
.cwb-step {
  display: inline-grid; place-items: center;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  font-size: 11px; font-weight: 700; line-height: 1;
}

/* --------------------------- 左：元件库 --------------------------- */
.cwb-tabs { display: flex; flex-wrap: wrap; gap: 4px; }
.cwb-tab {
  padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; font: inherit; font-size: 12px; cursor: pointer; color: var(--muted);
}
.cwb-tab.is-on { border-color: var(--accent); background: #eff6ff; color: var(--accent-dark); font-weight: 600; }

.cwb-lib { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.cwb-part {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 7px 4px 6px; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; cursor: pointer; font: inherit; color: var(--text);
  transition: border-color .12s, background .12s, transform .12s;
}
.cwb-part:hover { border-color: var(--accent); background: #f8fbff; transform: translateY(-1px); }
.cwb-part:active { transform: translateY(0); }
.cwb-part svg {
  width: 52px; height: 26px; fill: none; stroke: #0f172a;
  stroke-width: 1.6; stroke-linecap: round;
}
.cwb-part svg .cwb-svg-t { font-size: 11px; font-weight: 700; fill: #0f172a; stroke: none; }
.cwb-part span { font-size: 12.5px; font-weight: 600; }
.cwb-part em { font-style: normal; font-size: 10.5px; color: var(--muted); }
.cwb-part[hidden] { display: none; }

.cwb-left-foot { margin-top: auto; display: grid; gap: 6px; }
.cwb-left-foot .small { margin: 0; }
kbd {
  padding: 0 4px; border: 1px solid var(--line); border-radius: 4px;
  background: #f8fafc; font-size: 11px;
}
.cwb-wide { width: 100%; justify-content: center; }

/* --------------------------- 中：画布 --------------------------- */
.cwb-center { display: flex; flex-direction: column; gap: 8px; }

.cwb-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center;
  justify-content: space-between;
}
.cwb-tools { display: inline-flex; gap: 4px; padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }
.cwb-tool {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border: 0; border-radius: 8px;
  background: transparent; font: inherit; font-size: 12.5px; color: #334155; cursor: pointer;
}
.cwb-tool svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.cwb-tool.is-on { background: #fff; color: var(--accent-dark); box-shadow: 0 1px 3px rgba(15, 23, 42, .12); font-weight: 600; }
.cwb-tool:hover { color: var(--accent-dark); }

.cwb-toolbar-mid { flex: 1 1 180px; min-width: 140px; }
.cwb-hint { font-size: 12px; color: var(--muted); }

.cwb-run { display: inline-flex; align-items: center; gap: 6px; }
.cwb-btn {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 11px; border: 1px solid var(--accent); border-radius: 8px;
  background: var(--accent); color: #fff; font: inherit; font-size: 12.5px; font-weight: 600; cursor: pointer;
}
.cwb-btn svg { width: 14px; height: 14px; fill: currentColor; }
.cwb-btn:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.cwb-btn[data-reset] { background: #fff; color: var(--accent-dark); font-weight: 500; }
.cwb-grid-toggle { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }

.cwb-stage {
  position: relative; border: 1px solid var(--line); border-radius: 12px;
  background: #fff; padding: 4px; overflow: hidden;
}
.cwb-stage canvas { display: block; border-radius: 8px; background:
  linear-gradient(#ffffff, #ffffff); cursor: crosshair; }
.cwb-empty {
  position: absolute; inset: 0; display: grid; place-content: center; gap: 4px;
  text-align: center; color: var(--muted); pointer-events: none;
}
.cwb-empty b { color: #334155; font-size: 15px; }
.cwb-empty p { margin: 0; font-size: 12.5px; max-width: 380px; }
.cwb-empty[hidden] { display: none; }

.cwb-stage-foot {
  display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; justify-content: space-between;
}
.cwb-legend { display: inline-flex; gap: 12px; font-size: 11.5px; color: var(--muted); }
.cwb-legend i { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; }
.cwb-dot-node { background: #94a3b8; }
.cwb-dot-flow { background: #0e7490; }
.cwb-dot-volt { background: #7c3aed; }
.cwb-examples { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.cwb-chip {
  padding: 2px 9px; border: 1px solid var(--line); border-radius: 999px;
  background: #fff; font: inherit; font-size: 11.5px; cursor: pointer; color: #334155;
}
.cwb-chip:hover { border-color: var(--accent); color: var(--accent-dark); }

/* --------------------------- 右：参数 --------------------------- */
.cwb-insp { display: grid; gap: 8px; }
.cwb-insp-empty { margin: 0; font-size: 12.5px; color: var(--muted); }
.cwb-insp-head { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; }
.cwb-insp-head b { font-size: 13.5px; }
.cwb-insp-id { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; color: var(--muted); }

.cwb-field { display: grid; gap: 3px; }
.cwb-field span { font-size: 11.5px; color: var(--muted); }
.cwb-field input, .cwb-field select {
  width: 100%; padding: 4px 7px; border: 1px solid var(--line); border-radius: 8px;
  background: #fff; font: inherit; font-size: 13px; color: var(--text);
}
.cwb-field input[type=checkbox] { width: auto; }
.cwb-field input:focus, .cwb-field select:focus { outline: 2px solid rgba(37, 99, 235, .25); border-color: var(--accent); }

.cwb-ana { display: grid; gap: 8px; }
.cwb-note { margin: 0; line-height: 1.5; }

/* --------------------------- 下：输出 --------------------------- */
.cwb-out { padding: 12px 14px 14px; }
.cwb-audit {
  margin: 8px 0 10px; padding: 9px 12px; border: 1px solid #fde68a; border-radius: 9px;
  background: #fffbeb; color: #92400e; font-size: 12.5px; line-height: 1.65;
}
.cwb-audit[hidden] { display: none; }
.cwb-audit b { display: block; margin-bottom: 2px; color: #92400e; font-size: 12px; }
.cwb-audit ul { margin: 2px 0 0 18px; padding: 0; }
.cwb-audit li + li { margin-top: 2px; }
.cwb-nodes { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 10px; }
.cwb-node {
  display: inline-flex; align-items: baseline; gap: 5px;
  padding: 3px 9px; border: 1px solid #ddd6fe; border-radius: 8px;
  background: #faf5ff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  color: #5b21b6;
}
.cwb-node em { font-style: normal; font-size: 10.5px; color: #7c3aed; opacity: .8; }

.cwb-table th, .cwb-table td { white-space: nowrap; }
.cwb-table td:nth-child(4), .cwb-table td:nth-child(5), .cwb-table td:nth-child(6) {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px;
}
.cwb-row-empty { text-align: center; color: var(--muted); padding: 14px 0; }

.cwb-status { display: flex; align-items: center; gap: 7px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.cwb-status-dot { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; }
.cwb-status-dot.is-ok { background: var(--green); box-shadow: 0 0 0 3px rgba(5, 150, 105, .15); }
.cwb-status-dot.is-warn { background: #d97706; box-shadow: 0 0 0 3px rgba(217, 119, 6, .14); }

.cwb-tip { margin: 10px 2px 24px; line-height: 1.6; }

/* --------------------------- 响应式 --------------------------- */
@media (max-width: 1180px) {
  .cwb { grid-template-columns: 220px minmax(0, 1fr) 250px; }
}
@media (max-width: 980px) {
  .cwb { grid-template-columns: 1fr; }
  .cwb-left, .cwb-right { flex-direction: column; }
  .cwb-lib { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* 仿真页放宽主容器：三栏 + 大画布需要横向空间（其余页面不受影响） */
main.container:has(.cwb) { width: min(1420px, calc(100% - 40px)); }

/* 撤销/重做：次级按钮 */
.cwb-btn-ghost { background: #fff; color: #334155; border-color: var(--line); font-weight: 500; }
.cwb-btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }

/* 瞬态波形 */
.cwb-scope { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.cwb-scope-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cwb-scope-head h3 { margin: 0; font-size: 13.5px; }
.cwb-scope-legend { display: inline-flex; align-items: center; gap: 10px; font-size: 11.5px; color: var(--muted); }
.cwb-scope canvas { display: block; width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #fcfdff; }
.cwb-scope.is-cursor canvas { touch-action: none; cursor: ew-resize; }
.cwb-scope[hidden] { display: none; }

/* 瞬态波形双游标读数 */
.cwb-cursor-readout { margin-top: 8px; }
.cwb-cursor-grid {
  display: grid; grid-template-columns: 30px repeat(3, minmax(0, 1fr));
  overflow: hidden; border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-variant-numeric: tabular-nums;
}
.cwb-cursor-grid > * {
  min-width: 0; padding: 6px 8px; border-bottom: 1px solid #eff3f8;
  text-align: center; font-size: 12px; line-height: 1.45;
}
.cwb-cursor-grid > :nth-child(-n+4) {
  background: #f8fafc; border-bottom-color: #e2e8f0; font-weight: 700;
}
.cwb-cursor-grid > :nth-child(4n+1) {
  text-align: left; color: #64748b; font-style: normal;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
.cwb-cursor-grid > b {
  overflow-wrap: anywhere; color: #0f172a;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600;
}
.cwb-cursor-grid > .is-a { color: #2563eb; }
.cwb-cursor-grid > .is-b { color: #b45309; }
.cwb-cursor-grid > .is-d { color: #475569; }
.cwb-cursor-grid > :nth-child(n+13) { border-bottom: 0; }
.cwb-cursor-hint { margin: 6px 0 0; }
.cwb-cursor-readout[hidden], .cwb-cursor-hint[hidden] { display: none; }

/* 合并后的双模式：连线仿真 / 元件装配器 */
.cwb-mode{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:14px 0 16px}
.cwb-mode-tab{appearance:none;border:1px solid #cbd5e1;background:#fff;color:#475569;border-radius:999px;padding:9px 18px;font:inherit;font-size:14px;font-weight:600;cursor:pointer}
.cwb-mode-tab:hover{border-color:#93c5fd;color:#1d4ed8}
.cwb-mode-tab.is-on{background:#17324d;border-color:#17324d;color:#fff;box-shadow:0 6px 16px rgba(23,50,77,.18)}
.cwb-mode-note{color:#64748b;font-size:12.5px;line-height:1.6}
.cwb-mode-panel[hidden]{display:none!important}
.cwb-builder-intro{display:flex;justify-content:space-between;align-items:flex-start;gap:16px;flex-wrap:wrap;margin-bottom:14px}
.cwb-builder-intro h2{margin:2px 0 6px;font-size:22px;color:#0f172a}
.cwb-builder-intro p{margin:0;max-width:760px}
.cwb-builder-actions{display:flex;gap:8px;flex-wrap:wrap}

/* 装配器里的可信度折叠（与自由装配台同款） */
.model-cred{margin:10px 0 0;border:1px dashed #cbd5e1;border-radius:10px;background:#fbfdff;padding:0 10px}
.model-cred summary{cursor:pointer;padding:8px 0;font-size:12.5px;font-weight:600;color:#475569}
.model-cred[open]{padding-bottom:9px}
.model-cred .cred-body{font-size:12.5px;line-height:1.7;color:#475569}
.model-cred .cred-body b{color:#0f172a}
.model-cred .cred-table{width:100%;border-collapse:collapse;margin-top:6px;font-size:12px}
.model-cred .cred-table th,.model-cred .cred-table td{border-top:1px solid #e2e8f0;padding:5px 4px;text-align:left;vertical-align:top}
.model-cred .cred-table th{color:#64748b;font-weight:600}
.cwb-jumprail{display:none}
@media (max-width:760px){
  .cwb-mode-tab{padding:8px 14px;font-size:13px}
  .cwb-builder-intro{padding:16px}
  .cwb-cursor-grid{grid-template-columns:26px repeat(3,minmax(0,1fr))}
  .cwb-cursor-grid>*{padding:5px 6px;font-size:11.5px}

  /* 长页跳转：手机上一屏只看得到一段，给四个关键段落一条吸顶短导航。 */
  .cwb-jumprail{
    display:flex; align-items:center; gap:6px;
    position:sticky; top:var(--header-h,64px); z-index:8;
    margin:10px 0 8px; padding:6px 8px;
    overflow-x:auto; scrollbar-width:none;
    border:1px solid #dbe5f1; border-radius:12px;
    background:rgba(255,255,255,.96);
    -webkit-backdrop-filter:blur(10px); backdrop-filter:blur(10px);
    box-shadow:0 6px 18px rgba(23,50,77,.06);
  }
  .cwb-jumprail::-webkit-scrollbar{display:none}
  .cwb-jumprail-label{flex:0 0 auto;color:#94a3b8;font-size:11.5px}
  .cwb-jumprail a{
    flex:0 0 auto; padding:4px 10px; border-radius:999px;
    color:#475569; font-size:12px; line-height:1.6; text-decoration:none;
    background:#f1f5f9; border:1px solid transparent;
  }
  .cwb-jumprail a:hover{color:#1d4ed8;background:#eff6ff;border-color:#bfdbfe;text-decoration:none}
  .cwb-jumprail a.is-on{background:#17324d;border-color:#17324d;color:#fff;font-weight:600}
  #cwb-jump-lib,#cwb-jump-canvas,#cwb-jump-params,#cwb-jump-out{
    scroll-margin-top:calc(var(--header-h,64px) + 52px);
  }
}

/* 手机端读数表：不再横向滚动，按元件折成一张张数据卡。
   桌面表格列多，手机上 440px 宽只能看到一半；改成卡片后元件、参数、U/I/P 都能直接读。 */
@media (max-width: 760px) {
  .cwb-out .bench-table-wrap { overflow-x: visible; }
  .cwb-out .native-embed-links {
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px; width: 100%;
  }
  .cwb-out .native-embed-links .btn { justify-content: center; text-align: center; }
  .cwb-table { display: block; width: 100%; font-size: 12.5px; }
  .cwb-table thead { display: none; }
  .cwb-table tbody { display: grid; gap: 8px; }
  .cwb-table tbody tr {
    display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px 8px; padding: 10px 10px 8px;
    border: 1px solid var(--line); border-radius: 12px; background: #fff;
  }
  .cwb-table tbody tr.cwb-row-empty { display: block; padding: 14px 10px; }
  .cwb-table td {
    display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
    padding: 0; border: 0; text-align: left; white-space: normal; overflow-wrap: anywhere;
  }
  .cwb-table td::before {
    content: attr(data-label);
    color: var(--muted); font: 500 10.5px/1.3 ui-monospace, SFMono-Regular, Menlo, monospace;
  }
  .cwb-table td:nth-child(1) { display: none; }
  .cwb-table td:nth-child(2) {
    grid-column: 1 / -1; display: block; padding-bottom: 4px;
    border-bottom: 1px dashed var(--line); color: #0f172a;
    font-size: 14px; font-weight: 700;
  }
  .cwb-table td:nth-child(2)::before { display: none; }
  .cwb-table td:nth-child(3) { grid-column: 1 / -1; color: #475569; }
  .cwb-table td:nth-child(4), .cwb-table td:nth-child(5), .cwb-table td:nth-child(6) {
    padding: 7px 8px; border-radius: 8px; background: #f8fafc;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px;
  }
  .cwb-table td:nth-child(7) {
    grid-column: 1 / -1; padding-top: 5px; border-top: 1px dashed var(--line); color: #64748b;
  }
  .cwb-table td:nth-child(7):empty { display: none; }
  .cwb-table tr.cwb-row-empty td.cwb-row-empty { display: block; text-align: center; color: var(--muted); }
  .cwb-table tr.cwb-row-empty td.cwb-row-empty::before { display: none; }
}

/* --------------------------- 账号电路方案弹窗 --------------------------- */
body.cwb-cloud-open { overflow: hidden; }
.cwb-cloud-modal {
  position: fixed; inset: 0; z-index: 90;
  display: grid; place-items: center; padding: 18px;
  background: rgba(15, 23, 42, .48);
}
.cwb-cloud-modal[hidden] { display: none; }
.cwb-cloud-card {
  width: min(560px, 100%); max-height: min(82vh, 640px); overflow: auto;
  padding: 18px 18px 16px; border: 1px solid var(--line); border-radius: 16px;
  background: #fff; box-shadow: 0 24px 60px rgba(15, 23, 42, .22);
}
.cwb-cloud-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.cwb-cloud-head h2 { margin: 2px 0 0; font-size: 20px; }
.cwb-cloud-name { margin-top: 14px; }
.cwb-cloud-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.cwb-cloud-list { display: grid; gap: 8px; margin-top: 16px; }
.cwb-cloud-item {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: 8px 12px; padding: 10px 11px;
  border: 1px solid var(--line); border-radius: 11px; background: #f8fafc;
}
.cwb-cloud-item-main { display: grid; gap: 2px; min-width: 0; }
.cwb-cloud-item-main b { font-size: 13.5px; overflow-wrap: anywhere; }
.cwb-cloud-item-main small { color: var(--muted); font-size: 11.5px; }
.cwb-cloud-item-actions { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.cwb-cloud-empty { padding: 18px 10px; border: 1px dashed var(--line); border-radius: 11px; text-align: center; color: var(--muted); }

@media (max-width: 760px) {
  .cwb-examples { flex: 1 1 100%; width: 100%; }
  .cwb-cloud-modal { padding: 10px; align-items: end; }
  .cwb-cloud-card { width: 100%; max-height: 88vh; border-radius: 16px 16px 12px 12px; padding: 16px 14px; }
  .cwb-cloud-item { align-items: stretch; }
  .cwb-cloud-item-actions { width: 100%; }
  .cwb-cloud-item-actions .btn { flex: 1 1 auto; justify-content: center; }
}
