/* ============================================================
   电工电路模拟与故障诊断系统 —— 界面样式
   浅色工程制图风格，适合教学投影与打印
   ============================================================ */

:root {
  --bg: #eef2f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --line: #dbe3ec;
  --line-strong: #c3cfdd;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #7b8a9c;
  --accent: #0d7a6f;
  --accent-2: #0f766e;
  --accent-soft: #e6f5f2;
  --live: #dc2626;
  --live-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --ok: #15803d;
  --ok-soft: #f0fdf4;
  --blue: #1d4ed8;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 4px 12px rgba(15, 23, 42, .05);
  --mono: ui-monospace, "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", sans-serif;
  font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, select, input { font-family: inherit; font-size: 13px; color: inherit; }
kbd {
  font-family: var(--mono); font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--line-strong); border-bottom-width: 2px;
  border-radius: 4px; background: #fff;
}

/* ---------------- 总体布局 ---------------- */
.app {
  display: grid;
  height: 100vh;
  grid-template-columns: 214px 1fr 336px;
  grid-template-rows: auto 1fr 30px;
  grid-template-areas:
    "top top top"
    "palette canvas inspector"
    "status status status";
}

/* ---------------- 顶栏 ---------------- */
.topbar {
  grid-area: top;
  display: flex; align-items: center; gap: 16px;
  padding: 8px 14px;
  background: linear-gradient(180deg, #ffffff, #f7fafc);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .04);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; flex: 0 0 34px;
  display: grid; place-items: center; font-size: 19px;
  background: linear-gradient(135deg, #0f766e, #0e7490); color: #fff;
  box-shadow: 0 2px 6px rgba(13, 122, 111, .3);
}
.brand h1 { margin: 0; font-size: 15px; font-weight: 700; letter-spacing: .2px; }
.brand p { margin: 0; font-size: 11px; color: var(--ink-3); }

.topTools { display: flex; align-items: center; gap: 10px; margin-left: auto; flex-wrap: wrap; }
.btnGroup { display: flex; gap: 0; }
.btnGroup > button { border-radius: 0; margin-left: -1px; }
.btnGroup > button:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btnGroup > button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

button {
  padding: 6px 11px; border: 1px solid var(--line-strong);
  background: #fff; border-radius: var(--radius); cursor: pointer;
  transition: background .12s, border-color .12s, transform .06s;
  white-space: nowrap;
}
button:hover { background: var(--panel-2); border-color: #a9b8c9; }
button:active { transform: translateY(1px); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover { background: #0b6a60; }
button.danger { color: #b91c1c; border-color: #f0b6b6; }
button.danger:hover { background: var(--live-soft); }
button.wide { width: 100%; }
button.on { background: var(--accent-soft); border-color: var(--accent-2); color: var(--accent-2); font-weight: 600; }

select {
  padding: 6px 8px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); background: #fff; cursor: pointer;
}
label.sel { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
label.sel.wide { width: 100%; }
label.sel.wide select { flex: 1; }

/* ---------------- 元件库 ---------------- */
.palette {
  grid-area: palette; background: var(--panel);
  border-right: 1px solid var(--line);
  overflow-y: auto; padding: 10px;
}
.palette h2 {
  margin: 2px 0 8px; font-size: 12px; text-transform: uppercase;
  letter-spacing: .08em; color: var(--ink-3); font-weight: 700;
}
.palGroup { margin-bottom: 12px; }
.palGroup > h3 {
  margin: 0 0 5px; font-size: 11px; color: var(--ink-3);
  font-weight: 600; letter-spacing: .04em;
}
.palItem {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px; margin-bottom: 4px;
  border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel-2); cursor: grab; user-select: none;
  transition: all .12s;
}
.palItem:hover { border-color: var(--accent-2); background: var(--accent-soft); }
.palItem.active { border-color: var(--accent); background: var(--accent-soft); box-shadow: inset 0 0 0 1px var(--accent); }
.palItem svg { flex: 0 0 40px; }
.palItem .nm { font-size: 12px; font-weight: 600; }
.palItem .ds { font-size: 10px; color: var(--ink-3); line-height: 1.3; }

.paletteTip {
  margin-top: 10px; padding: 9px 10px; font-size: 11px; line-height: 1.7;
  background: var(--panel-2); border: 1px dashed var(--line-strong);
  border-radius: 6px; color: var(--ink-2);
}
.paletteTip b { color: var(--ink); }
.paletteTip p { margin: 3px 0; }

/* ---------------- 画布 ---------------- */
.canvasWrap {
  grid-area: canvas; position: relative; overflow: hidden;
  background: #fbfdff;
}
#canvas { width: 100%; height: 100%; display: block; cursor: default; touch-action: none; }
#canvas.placing { cursor: copy; }
#canvas.wiring { cursor: crosshair; }
#canvas.panning { cursor: grabbing; }

.canvasBar {
  position: absolute; left: 12px; top: 12px;
  display: flex; align-items: center; gap: 4px;
  padding: 5px 7px; background: rgba(255,255,255,.94);
  border: 1px solid var(--line); border-radius: 9px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px);
  font-size: 12px;
}
.canvasBar button { padding: 4px 9px; font-size: 12px; }
.canvasBar .sep { width: 1px; height: 18px; background: var(--line); margin: 0 4px; }
.canvasBar #zoomLabel { min-width: 40px; text-align: center; font-family: var(--mono); font-size: 11px; color: var(--ink-2); }
.chk { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; color: var(--ink-2); cursor: pointer; user-select: none; }

.hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%);
  padding: 6px 14px; font-size: 12px; color: var(--ink-2);
  background: rgba(255,255,255,.95); border: 1px solid var(--line);
  border-radius: 20px; box-shadow: var(--shadow); pointer-events: none;
  opacity: 0; transition: opacity .2s;
}
.hint.show { opacity: 1; }

.meterBox {
  position: absolute; right: 14px; top: 14px; width: 250px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 11px 12px; font-size: 12px;
}
.meterBox h4 { margin: 0 0 7px; font-size: 12px; display: flex; align-items: center; gap: 6px; }
.meterBox .disp {
  font-family: var(--mono); font-size: 22px; font-weight: 700;
  color: var(--accent-2); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 6px 10px; text-align: right; margin-bottom: 6px;
}
.meterBox .disp small { font-size: 12px; font-weight: 500; color: var(--ink-3); }
.meterBox .mtxt { color: var(--ink-2); line-height: 1.6; font-size: 11px; }
.meterBox .pts { font-family: var(--mono); font-size: 11px; color: var(--ink-3); margin-bottom: 5px; }
.meterBox button { width: 100%; margin-top: 7px; }

/* ---------------- SVG 元件样式 ---------------- */
.comp { cursor: move; }
.comp.sel .boxOutline { stroke: var(--blue); stroke-width: 2; stroke-dasharray: 5 3; }
.comp.hl .boxOutline { stroke: #f59e0b; stroke-width: 3; }
.comp .boxOutline { fill: none; stroke: transparent; stroke-width: 1.5; }
.pin-dot { cursor: crosshair; }
.pin-dot:hover { r: 7; stroke: var(--blue); }
.pinLabel { font-family: var(--mono); font-size: 10px; fill: #64748b; pointer-events: none; }
.wire { fill: none; stroke: #64748b; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.wire.sel { stroke: var(--blue); stroke-width: 3.4; }
.wire.live { stroke: var(--live); }
.wire.hot { stroke-dasharray: 7 5; animation: flow .55s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -12; } }
.wire.hit { stroke: transparent; stroke-width: 14; cursor: pointer; }
.measurePt { fill: #f59e0b; stroke: #fff; stroke-width: 2; }
.shortPath { stroke: #f59e0b !important; stroke-width: 4 !important; }

/* ---------------- 右侧面板 ---------------- */
.inspector {
  grid-area: inspector; background: var(--panel);
  border-left: 1px solid var(--line);
  display: flex; flex-direction: column; overflow: hidden;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); background: var(--panel-2); }
.tabs button {
  flex: 1; border: none; background: none; border-radius: 0;
  padding: 9px 4px; font-size: 12px; color: var(--ink-2);
  border-bottom: 2px solid transparent; font-weight: 500;
}
.tabs button.active { color: var(--accent-2); border-bottom-color: var(--accent-2); background: #fff; font-weight: 700; }
.tabBody { display: none; padding: 12px; overflow-y: auto; flex: 1; }
.tabBody.active { display: block; }

.empty { color: var(--ink-3); font-size: 12px; line-height: 1.8; }
.row { display: flex; gap: 6px; margin-bottom: 8px; align-items: center; }
.row > * { flex: 1; }
.note { font-size: 11px; color: var(--ink-3); line-height: 1.7; }
hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
h3 { font-size: 12px; margin: 0 0 8px; color: var(--ink-2); letter-spacing: .03em; }

/* 属性表单 */
.field { margin-bottom: 9px; }
.field > label { display: block; font-size: 11px; color: var(--ink-3); margin-bottom: 3px; }
.field input, .field select {
  width: 100%; padding: 6px 8px; border: 1px solid var(--line-strong);
  border-radius: 6px; background: #fff;
}
.field .unit { font-size: 11px; color: var(--ink-3); margin-left: 4px; }
.field .hintTxt { font-size: 10px; color: var(--ink-3); margin-top: 2px; }
.compTitle { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.compTitle .tag {
  font-family: var(--mono); font-size: 11px; padding: 2px 7px;
  background: var(--accent-soft); color: var(--accent-2);
  border-radius: 5px; font-weight: 700;
}
.compTitle .nm { font-weight: 700; font-size: 13px; }

.statusList { font-size: 12px; }
.statusList .si { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed var(--line); }
.statusList .si span:first-child { color: var(--ink-3); }
.statusList .si span:last-child { font-family: var(--mono); font-weight: 600; }
.on-txt { color: var(--live); }
.off-txt { color: var(--ink-3); }
.ok-txt { color: var(--ok); }

/* 诊断报告 */
.report { font-size: 12px; }
.finding {
  padding: 7px 9px; margin-bottom: 6px; border-radius: 6px;
  border-left: 3px solid var(--line-strong); background: var(--panel-2);
  line-height: 1.6;
}
.finding.fault { border-left-color: var(--live); background: var(--live-soft); }
.finding.protect { border-left-color: var(--warn); background: var(--warn-soft); }
.finding.operate { border-left-color: var(--blue); background: #eff6ff; }
.finding.chain { border-left-color: #7c3aed; background: #f5f3ff; }
.finding.interlock { border-left-color: #0891b2; background: #ecfeff; }
.finding.warn { border-left-color: var(--warn); background: var(--warn-soft); }
.finding.ok { border-left-color: var(--ok); background: var(--ok-soft); }
.finding.info { border-left-color: #64748b; }
.finding b { display: block; margin-bottom: 2px; font-size: 11px; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3); }
.chainBox { margin: 5px 0 0 12px; padding-left: 9px; border-left: 2px dotted var(--line-strong); }
.reportTitle { font-weight: 700; margin: 10px 0 6px; font-size: 12px; color: var(--ink-2); }
.reportTitle:first-child { margin-top: 0; }

/* 故障面板 */
.faultBox { margin-bottom: 8px; }
.faultCard {
  padding: 10px 11px; border-radius: 8px; font-size: 12px; line-height: 1.7;
  border: 1px solid var(--line-strong); background: var(--panel-2);
}
.faultCard.armed { border-color: #f59e0b; background: var(--warn-soft); }
.faultCard.revealed { border-color: var(--accent-2); background: var(--accent-soft); }
.faultCard .t { font-weight: 700; margin-bottom: 4px; display: flex; align-items: center; gap: 6px; }
.faultCard .sym { color: var(--ink-2); }
.faultCard .ans { margin-top: 7px; padding-top: 7px; border-top: 1px dashed var(--line-strong); }
.faultCard .ans b { color: var(--accent-2); }

/* 练习：计时与诊断次数 */
.faultCard .meta {
  display: flex; gap: 14px; margin: 7px 0 0;
  padding: 5px 8px; border-radius: 6px;
  background: rgba(255, 255, 255, .7); border: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-2);
}
.faultCard .meta b { font-family: var(--mono); color: var(--ink); }

/* 练习：作答表单 */
.faultCard .ansForm { margin-top: 9px; padding-top: 9px; border-top: 1px dashed var(--line-strong); }
.faultCard .ansForm .row { margin-bottom: 6px; }
.faultCard .ansForm button { width: 100%; }

/* 练习：判定结果 */
.verdict {
  margin-top: 8px; padding: 7px 10px; border-radius: 6px;
  font-weight: 700; font-size: 13px;
}
.verdict.good { background: var(--ok-soft); border: 1px solid #86efac; color: var(--ok); }
.verdict.bad { background: var(--live-soft); border: 1px solid #fecaca; color: var(--live); }

/* 练习：成绩记录 */
.recSummary {
  padding: 7px 9px; border-radius: 6px; margin-bottom: 7px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: 12px; color: var(--ink-2);
}
.recSummary b { color: var(--accent-2); font-family: var(--mono); }
.recTable { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.recTable th {
  text-align: left; padding: 4px 5px; font-weight: 600; color: var(--ink-2);
  border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
.recTable td { padding: 4px 5px; border-bottom: 1px solid var(--line); color: var(--ink-2); }
.recTable tr.okRow td:first-child { color: var(--ok); }
.recTable tr.badRow td:first-child { color: var(--live); }
.recTable td:nth-child(4), .recTable td:nth-child(5) { font-family: var(--mono); }

button.mini {
  padding: 2px 7px; font-size: 11px; font-weight: 500;
  border-radius: 5px; margin-left: 4px;
}
button.mini.danger { color: var(--live); border-color: #fecaca; }

/* ---------------- 打印：只保留接线图 ---------------- */
@media print {
  @page { size: A4 landscape; margin: 8mm; }
  html, body { overflow: visible !important; height: auto !important; background: #fff !important; }
  .topbar, .palette, .inspector, .statusbar, .canvasBar, .hint, .meterBox { display: none !important; }
  .app { display: block !important; height: auto !important; }
  .canvasWrap {
    position: static !important; height: auto !important; overflow: visible !important;
    background: #fff !important; border: 0 !important;
  }
  #canvas { width: 100% !important; height: 92vh !important; }
  .comp .boxOutline { stroke: transparent !important; }
}

/* 说明页 */
.help h3 { margin-top: 14px; }
.help h3:first-child { margin-top: 0; }
.help ul { margin: 0; padding-left: 17px; font-size: 12px; line-height: 1.85; color: var(--ink-2); }
.help li b { color: var(--ink); }

/* ---------------- 状态栏 ---------------- */
.statusbar {
  grid-area: status; display: flex; align-items: center; gap: 10px;
  padding: 0 12px; font-size: 11.5px; color: var(--ink-2);
  background: var(--panel-2); border-top: 1px solid var(--line);
}
.statusbar .grow { flex: 1; }
.pill {
  padding: 2px 9px; border-radius: 10px; font-size: 11px; font-weight: 700;
}
.pill.off { background: #e2e8f0; color: var(--ink-2); }
.pill.on { background: #dcfce7; color: var(--ok); }
.pill.err { background: #fee2e2; color: #b91c1c; }
.statusbar .log { font-family: var(--mono); font-size: 11px; color: var(--ink-3); max-width: 46%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------------- 窄屏 ---------------- */
@media (max-width: 1180px) {
  .app { grid-template-columns: 176px 1fr 300px; }
}
@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto 1fr auto auto;
    grid-template-areas: "top" "palette" "canvas" "inspector" "status";
    height: auto; min-height: 100vh; overflow: auto;
  }
  body { overflow: auto; }
  .palette { max-height: 190px; }
  .canvasWrap { height: 62vh; }
  .inspector { max-height: 62vh; }
}
