:root {
  --ink: #1c1915;
  --muted: #5e584e;
  --paper: #f6f4ee;
  --sheet: #fbfaf6;
  --steel: #d7d4cc;
  --top: #1e242b;
  --brass: #b8893d;
  --contact: #124e78;
  --coil: #9a3412;
  --fb: #1d6a62;
  --ok: #1e6b3a;
  --warn: #8a5a10;
  --bad: #8f2d2d;
  --line: #cfc8b8;
  --gutter: #efece4;
  font-family: "WenQuanYi Micro Hei", "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  color: var(--ink);
  background: #c9c6be;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  min-height: 100%;
  display: flex;
  flex-direction: column;
}

.top {
  background: var(--top);
  color: #f4efe4;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
}
.brand { display: flex; gap: 12px; align-items: center; }
.brand h1 { margin: 0; font-size: 18px; font-weight: 650; letter-spacing: 0.02em; }
.brand p { margin: 2px 0 0; color: #c8c0b2; font-size: 12px; }
.rail-mark {
  width: 18px; height: 36px; border-left: 4px solid var(--brass); position: relative;
}
.rail-mark::before, .rail-mark::after {
  content: ""; position: absolute; left: 0; right: -8px; height: 2px; background: var(--brass);
}
.rail-mark::before { top: 8px; }
.rail-mark::after { bottom: 8px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.btn {
  appearance: none; border: 1px solid #8d8678; background: #f7f4ec; color: var(--ink);
  border-radius: 4px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary { background: var(--brass); border-color: #8d6824; color: #1c1408; font-weight: 650; }
.btn.ghost { background: transparent; color: #f4efe4; border-color: #5c656f; }
.btn.block { width: 100%; margin-top: 8px; }
.top .btn.ghost { color: #f4efe4; }
.search { display: flex; align-items: center; gap: 6px; color: #d9d1c3; font-size: 13px; }
.search input {
  width: min(240px, 46vw); border: 1px solid #5c656f; background: #12171c; color: #f4efe4;
  border-radius: 4px; padding: 6px 8px; font: inherit;
}
.zoom { display: flex; align-items: center; gap: 4px; color: #d9d1c3; font-variant-numeric: tabular-nums; }
.menu { position: relative; }
.menu-pop {
  position: absolute; z-index: 20; top: calc(100% + 4px); left: 0; min-width: 280px;
  background: var(--sheet); color: var(--ink); border: 1px solid #b7b1a4; border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18); padding: 6px;
}
.menu-pop button {
  display: block; width: 100%; text-align: left; background: transparent; border: 0;
  font: inherit; padding: 8px; border-radius: 4px; cursor: pointer;
}
.menu-pop button:hover { background: #efe8d4; }
.menu-pop small { display: block; color: var(--muted); }

.banner {
  background: #f3e2c0; color: #3f2e12; padding: 8px 16px; font-size: 13.5px; line-height: 1.45;
  border-bottom: 1px solid #e0c48a;
}

main { flex: 1; display: flex; min-height: 0; }
.stage { flex: 1; position: relative; min-width: 0; background:
  linear-gradient(#d9d5cb, #d9d5cb) 0 0 / 100% 100%; }
.viewport { position: absolute; inset: 0; overflow: auto; }
.sheet { position: relative; }
.empty {
  position: absolute; inset: 0; display: grid; place-items: center; padding: 24px;
}
.empty-card {
  max-width: 640px; background: var(--sheet); border: 1px solid #d5cec0;
  border-radius: 10px; padding: 28px 28px 22px; box-shadow: 0 12px 40px rgba(40,32,16,.08);
}
.empty-card h2 { margin: 0 0 8px; font-size: 22px; }
.empty-card h2 + h2, .empty-card ul + h2 { margin-top: 18px; }
.empty-card p, .empty-card li { line-height: 1.55; }
.empty-card ul { margin: 0 0 4px; padding-left: 1.2em; }
.empty-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 18px 0 0; }
.fine, .muted { color: var(--muted); font-size: 12.5px; line-height: 1.45; }
code { font-family: "WenQuanYi Micro Hei Mono", ui-monospace, Consolas, monospace; font-size: 0.92em; }
.drop {
  position: absolute; inset: 12px; border: 2px dashed var(--brass); border-radius: 12px;
  background: rgba(251, 250, 246, .92); display: grid; place-items: center;
  font-size: 20px; z-index: 5; pointer-events: none;
}

.row { position: absolute; left: 0; display: flex; align-items: stretch; }
.gutter {
  width: 72px; flex: none; background: var(--gutter); color: #6a6458;
  border-right: 1px solid var(--line); display: flex; align-items: flex-start;
  justify-content: flex-end; padding: 8px 8px 0 0; font-variant-numeric: tabular-nums;
  font-family: "WenQuanYi Micro Hei Mono", ui-monospace, Consolas, monospace; font-size: 12px;
}
.row.rung-b .gutter { background: #e7e3d8; }
.row.comment { background: #e7f3ea; }
.row.comment .gutter { background: #d5eadc; color: var(--ok); }
.comment-body { padding: 8px 12px; color: var(--ok); font-size: 14px; line-height: 1.4; }
.comment-body b { font-weight: 650; margin-right: 8px; color: #14532d; }
.row.search-hit { outline: 2px solid #e6c15a; outline-offset: -2px; }
.row.search-cur { outline: 2px solid #c47b00; background: #fff6d8; }
svg.ladder { display: block; background: var(--sheet); }
.guide { stroke: #ece7dc; stroke-width: 1; }
.rail { stroke: #1c1915; stroke-width: 3; }
.rail.right { stroke-width: 3; }
.wire { stroke: #1c1915; stroke-width: 1.6; fill: none; }
.contact { stroke: var(--contact); fill: none; stroke-width: 1.8; }
.contact text, .coil text { stroke: none; font-size: 12px; }
.contact text.addr { fill: var(--contact); font-weight: 650; }
.coil { stroke: var(--coil); fill: #fffaf7; stroke-width: 1.8; }
.coil text.addr { fill: var(--coil); font-weight: 650; stroke: none; }
.coil text.mark { fill: var(--coil); font-size: 13px; font-weight: 700; stroke: none; }
.fb rect { fill: #f3faf8; stroke: var(--fb); stroke-width: 1.6; }
.fb text { fill: var(--fb); stroke: none; font-size: 12px; }
.fb text.sub { font-size: 11px; fill: #3f5f5b; }
.devc { fill: #6b5420; font-size: 11px; stroke: none; }
.hit { stroke: none; }
.hit:hover { fill: rgba(184, 137, 61, .14); }
.hit.sel { fill: rgba(184, 137, 61, .2); stroke: #a56b16; stroke-width: 1.5; }
.hit.cur { fill: rgba(230, 193, 90, .35); }

.side {
  width: 320px; flex: none; background: #f3f1ea; border-left: 1px solid #c9c2b4;
  overflow: auto; padding: 12px 14px 24px; display: none;
}
.side.open { display: block; }
.xref-panel {
  width: 300px; flex: none; background: #f3f1ea; border-right: 1px solid #c9c2b4;
  overflow: auto; padding: 12px 14px 24px; display: none;
}
.xref-panel.open { display: block; }
.xref-panel h2, .side > .panel-head h2 { margin: 0; font-size: 14px; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 0 0 8px;
}
.panel-head .close-panel { padding: 2px 8px; color: var(--muted); border-color: #c9c2b4; }
.btn.ghost.pressed { background: #f7f4ec; color: var(--ink); border-color: var(--brass); }
.xref-jump {
  display: flex; flex-wrap: wrap; gap: 4px; margin: 8px 0;
}
.xref-jump a, .xref-jump button {
  appearance: none; border: 1px solid #c9c2b4; background: white; color: var(--ink);
  border-radius: 99px; padding: 2px 8px; font: inherit; font-size: 12px; cursor: pointer;
  text-decoration: none;
}
.xref-jump button:hover, .xref-jump a:hover { border-color: var(--brass); background: #f7f1e2; }
.xref-group {
  margin: 12px 0 6px; padding: 6px 0 2px; font-size: 13px; font-weight: 650;
  border-bottom: 1px solid #c9c2b4; background: #f3f1ea; position: sticky; top: 0; z-index: 1;
}
.xref-group .cnt { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 6px; }
.side h2 { margin: 14px 0 6px; font-size: 14px; }
.side section:first-child h2 { margin-top: 0; }
.info { margin: 0; }
.info div { display: flex; justify-content: space-between; gap: 8px; padding: 3px 0; border-bottom: 1px solid #e4dfd4; font-size: 13px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
.badge { background: var(--warn); color: white; border-radius: 99px; padding: 0 7px; font-size: 12px; }
.badge.bad { background: var(--bad); }
.badge.ok { background: var(--ok); }
.v-list p, .dev-list p { margin: 4px 0; font-size: 13px; line-height: 1.4; }
.v-list .err { color: var(--bad); }
.v-list .warn { color: var(--warn); }
.dev-list button, .v-list button {
  display: block; width: 100%; text-align: left; background: white; border: 1px solid #e0dacd;
  border-radius: 4px; margin: 4px 0; padding: 6px 8px; font: inherit; cursor: pointer;
}
.dev-list button strong { font-family: ui-monospace, Consolas, monospace; margin-right: 6px; }
.dev-list button:hover { border-color: var(--brass); }
.inspector label { display: block; margin: 8px 0 2px; font-size: 12px; color: var(--muted); }
.inspector input, .inspector select, .inspector textarea {
  width: 100%; font: inherit; padding: 6px 8px; border: 1px solid #c9c2b4; border-radius: 4px; background: white;
}
.inspector textarea { min-height: 72px; resize: vertical; }
.inspector .row-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.hint { background: #f7f1e2; border-left: 3px solid var(--brass); padding: 6px 8px; font-size: 12.5px; line-height: 1.45; }

.status {
  background: #1e242b; color: #d9d1c3; display: flex; gap: 16px; flex-wrap: wrap;
  padding: 6px 16px; font-size: 12.5px;
}
#st-dirty { color: #f0c36a; }

.modal {
  position: fixed; inset: 0; background: rgba(20, 16, 10, .45);
  display: grid; place-items: center; z-index: 30; padding: 16px;
}
.dialog {
  width: min(560px, 100%); background: var(--sheet); border-radius: 10px; padding: 18px 18px 14px;
  border: 1px solid #d5cec0;
}
.dialog h2 { margin: 0 0 8px; }
.warn-copy { background: #f8ecd4; padding: 8px 10px; border-radius: 6px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 12px; }
.toast {
  position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%);
  background: #1e242b; color: #f4efe4; padding: 8px 14px; border-radius: 6px; z-index: 40;
  max-width: min(560px, 92vw);
}

@media (max-width: 900px) {
  main { flex-direction: column; }
  .side, .xref-panel { width: auto; border-left: 0; border-right: 0; border-top: 1px solid #c9c2b4; max-height: 46vh; }
}

.xref-filter { display: flex; align-items: center; gap: 8px; margin: 8px 0; font-size: 13px; color: var(--muted); }
.xref-filter input {
  flex: 1; font: inherit; padding: 6px 8px; border: 1px solid #c9c2b4; border-radius: 4px; background: white;
}
.xref-list { margin-top: 6px; }
.xref-item {
  background: white; border: 1px solid #e0dacd; border-radius: 4px; margin: 4px 0; overflow: hidden;
}
.xref-item.open { border-color: var(--brass); }
.xref-head {
  display: flex; align-items: baseline; gap: 8px; width: 100%; text-align: left;
  background: transparent; border: 0; font: inherit; padding: 7px 8px; cursor: pointer;
}
.xref-head:hover { background: #f7f1e2; }
.xref-head .addr { font-family: ui-monospace, Consolas, monospace; font-weight: 650; }
.xref-head .cmt { color: var(--muted); flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xref-head .cnt { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.xref-hits { border-top: 1px solid #efe8d8; padding: 4px; background: #fbfaf6; }
.xref-hits button, .rep-hits button, .compare-list button {
  display: block; width: 100%; text-align: left; background: white; border: 1px solid #e0dacd;
  border-radius: 4px; margin: 3px 0; padding: 6px 8px; font: inherit; cursor: pointer;
}
.xref-hits button:hover, .rep-hits button:hover, .compare-list button:hover { border-color: var(--brass); }
.xref-hits button.cur, .compare-list button.cur { border-color: #c47b00; background: #fff6d8; }

.dialog.wide { width: min(680px, 100%); }
.dialog label { display: block; margin: 8px 0 2px; font-size: 12px; color: var(--muted); }
.dialog input[type="text"], .dialog input[type="search"] {
  width: 100%; font: inherit; padding: 6px 8px; border: 1px solid #c9c2b4; border-radius: 4px; background: white;
}
.dialog .check { color: var(--ink); font-size: 13.5px; display: flex; align-items: center; gap: 8px; margin: 10px 0; }
.dialog-actions.left { justify-content: flex-start; }
.rep-result { max-height: 36vh; overflow: auto; margin-top: 8px; }
.rep-result .err { color: var(--bad); }
.rep-result .warn { color: var(--warn); }
.two-files { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 640px) { .two-files { grid-template-columns: 1fr; } }

body.comparing .stage,
body.comparing .side,
body.comparing .xref-panel,
body.workspace-open .stage,
body.workspace-open .side,
body.workspace-open .xref-panel { display: none !important; }
body.workspace-open .workspace.visible { display: flex; }
.compare {
  display: none; flex: 1; min-width: 0; min-height: 0; flex-direction: column; background: #d9d5cb;
}
body.comparing .compare { display: flex; }
.compare-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; background: #f3f1ea; border-bottom: 1px solid #c9c2b4;
}
.compare-summary { font-size: 13.5px; line-height: 1.4; }
.compare-summary b { font-weight: 650; }
.compare-body { flex: 1; min-height: 0; display: flex; }
.compare-list-wrap {
  width: 260px; flex: none; background: #f3f1ea; border-right: 1px solid #c9c2b4;
  overflow: auto; padding: 10px 10px 16px;
}
.compare-list-wrap h2 { margin: 0 0 8px; font-size: 14px; }
.compare-list .tag { font-size: 11px; padding: 1px 6px; border-radius: 99px; margin-right: 6px; color: #fff; }
.compare-list .tag.modify { background: var(--warn); }
.compare-list .tag.insert { background: var(--ok); }
.compare-list .tag.delete { background: var(--bad); }
.compare-panes { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.compare-captions {
  display: grid; grid-template-columns: 1fr 1fr; gap: 0;
  background: #1e242b; color: #f4efe4; font-size: 13px;
}
.compare-captions div { padding: 6px 10px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compare-captions div:first-child { border-right: 1px solid #3a424c; }
.compare-view { flex: 1; min-height: 0; overflow: auto; }
.compare-sheet { position: relative; }
.compare-row {
  position: absolute; left: 0; right: 0; display: grid; grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid #ddd6c8;
}
.compare-row .pane {
  display: flex; min-width: 0; overflow: hidden; background: var(--sheet);
}
.compare-row .pane.right { border-left: 1px solid #c9c2b4; }
.compare-row.tag-insert .pane.right,
.compare-row.tag-insert { background: #e7f3ea; }
.compare-row.tag-insert .pane.right { background: #e7f3ea; }
.compare-row.tag-delete .pane.left,
.compare-row.tag-delete { background: #f8e8e8; }
.compare-row.tag-delete .pane.left { background: #f8e8e8; }
.compare-row.tag-modify { background: #fff6d8; }
.compare-row.tag-modify .pane { background: #fff6d8; }
.compare-row.current { outline: 2px solid #c47b00; outline-offset: -2px; z-index: 1; }
.compare-gap {
  flex: 1; display: grid; place-items: center; color: var(--muted); font-size: 13px;
  background: repeating-linear-gradient(-45deg, #efece4, #efece4 8px, #e4dfd4 8px, #e4dfd4 16px);
}
.compare-row .change-marks {
  position: absolute; left: 50%; top: 4px; transform: translateX(-50%);
  font-size: 11px; background: #8a5a10; color: white; border-radius: 99px; padding: 1px 8px; z-index: 2;
}
@media (max-width: 1100px) {
  .compare-list-wrap { width: 200px; }
}
@media (max-width: 900px) {
  .compare-body { flex-direction: column; }
  .compare-list-wrap { width: auto; max-height: 28vh; border-right: 0; border-bottom: 1px solid #c9c2b4; }
}

.workspace {
  display: none; flex: 1; min-width: 0; min-height: 0; flex-direction: column; background: #ece9e1;
}
.workspace.visible { display: flex; }
.workspace-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 12px; background: #f3f1ea; border-bottom: 1px solid #c9c2b4;
}
.workspace-bar h2 { margin: 0; font-size: 15px; }
.workspace-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-left: auto; }
.workspace-warn {
  background: #f8ecd4; color: #3f2e12; padding: 8px 12px; font-size: 13px; line-height: 1.45;
  border-bottom: 1px solid #e0c48a;
}
.workspace-tools {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center;
  padding: 8px 12px; background: #f3f1ea; border-bottom: 1px solid #e4dfd4;
}
.seg { display: flex; border: 1px solid #c9c2b4; border-radius: 4px; overflow: hidden; }
.seg-btn {
  appearance: none; border: 0; background: white; font: inherit; font-size: 13px;
  padding: 6px 12px; cursor: pointer; color: var(--muted);
}
.seg-btn.active { background: #efe8d4; color: var(--ink); font-weight: 650; }
.workspace-body { flex: 1; min-height: 0; overflow: auto; padding: 8px 12px 24px; }
.params-table { width: 100%; border-collapse: collapse; font-size: 13px; background: white; }
.params-table th, .params-table td { border-bottom: 1px solid #e4dfd4; padding: 5px 8px; text-align: left; vertical-align: top; }
.params-table th { position: sticky; top: 0; background: #f3f1ea; font-weight: 650; }
.params-table tr.dirty { background: #fff6d8; }
.params-table tr.readonly { color: var(--muted); }
.params-table input[type="number"] {
  width: 8em; font: inherit; padding: 3px 6px; border: 1px solid #c9c2b4; border-radius: 4px;
}
.params-table .name { max-width: 28em; }
.params-group-title {
  margin: 14px 0 6px; font-size: 14px; font-weight: 650;
}
.params-group-title .tag { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: 8px; }
.mark-dirty { color: #8a5a10; font-size: 12px; margin-left: 4px; }
.alarms-layout { flex: 1; min-height: 0; display: flex; }
.alarms-lists {
  width: min(420px, 46%); flex: none; overflow: auto; border-right: 1px solid #c9c2b4;
  background: #f3f1ea; padding: 8px 10px 20px;
}
.alarms-lists h3 { margin: 10px 0 6px; font-size: 13px; }
.alarm-list button {
  display: block; width: 100%; text-align: left; background: white; border: 1px solid #e0dacd;
  border-radius: 4px; margin: 4px 0; padding: 6px 8px; font: inherit; cursor: pointer;
}
.alarm-list button:hover, .alarm-list button.cur { border-color: var(--brass); background: #f7f1e2; }
.alarm-list .meta { display: block; color: var(--muted); font-size: 12px; }
.alarm-detail { flex: 1; min-width: 0; overflow: auto; padding: 12px 16px 24px; background: var(--sheet); }
.alarm-detail h3 { margin: 0 0 8px; }
.alarm-detail dt { color: var(--muted); font-size: 12px; margin-top: 10px; }
.alarm-detail dd { margin: 2px 0 0; line-height: 1.45; white-space: pre-wrap; }
.evidence { font-size: 12.5px; color: var(--muted); }
.playbook { margin: 8px 0; padding-left: 18px; }
.insufficient { background: #f8e8e8; color: #8f2d2d; padding: 8px 10px; border-radius: 6px; }
@media (max-width: 900px) {
  .alarms-layout { flex-direction: column; }
  .alarms-lists { width: auto; max-height: 40vh; border-right: 0; border-bottom: 1px solid #c9c2b4; }
}
