:root {
  color-scheme: light;
  --bg: #eef2f6;
  --paper: #fffdf8;
  --surface: #ffffff;
  --surface-2: #f4f7fa;
  --ink: #182231;
  --muted: #617087;
  --line: #c8d3df;
  --line-dark: #334155;
  --brand: #17456f;
  --accent: #0b756f;
  --danger: #b42330;
  --live: #e9a900;
  --hot: #c9362c;
  --neutral: #2563eb;
  --closed: #0b756f;
  --connected: #2563eb;
  --state-on: #138a43;
  --state-on-fill: #e8f8ee;
  --state-off: #c62828;
  --state-off-fill: #fde8e8;
  --shadow: 0 14px 36px rgba(24, 34, 49, 0.14);
  --radius: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--ink); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button, label.file-action { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.logo-variant-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.logo-variant-sprite symbol path, .logo-variant-sprite symbol rect, .logo-variant-sprite symbol circle { fill: none; stroke: currentColor; stroke-width: 4; stroke-linecap: square; stroke-linejoin: miter; }
.app-shell { height: 100vh; display: grid; grid-template-rows: auto minmax(0, 1fr) auto; overflow: hidden; }
.topbar { position: relative; z-index: 30; display: grid; grid-template-columns: minmax(220px, 285px) minmax(0, 1fr); align-items: center; gap: 10px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); }
.brand { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-mark { width: 38px; height: 38px; flex: 0 0 38px; }
.brand-mark .logo-tile { fill: var(--brand); stroke: #0f2f4d; stroke-width: 2; }
.brand-mark .logo-line, .brand-mark .logo-contact { fill: none; stroke: var(--paper); stroke-width: 5; stroke-linecap: square; stroke-linejoin: miter; }
.brand-mark .logo-contact { stroke: var(--live); stroke-width: 3; }
.brand-mark .logo-dot { stroke: var(--paper); stroke-width: 2; }
.brand-mark .logo-dot.teal { fill: var(--accent); }
.brand-mark .logo-dot.amber { fill: var(--live); }
.brand-copy { min-width: 0; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: 0; }
.brand p { margin: 1px 0 0; color: var(--muted); font-size: 11px; line-height: 1.15; }
.creator-credit { font-size: 10px !important; color: var(--muted); }
.creator-credit a { color: var(--accent); text-decoration: none; }
.creator-credit a:hover { text-decoration: underline; }
.toolbar { position: relative; display: flex; flex-wrap: wrap; align-items: start; justify-content: flex-end; gap: 6px; min-width: 0; max-height: 82px; overflow: visible; }
.toolbar-group { display: flex; flex-wrap: nowrap; gap: 5px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-2); }

.tool-btn, .text-btn, .tab, .primary-btn, .mini-btn { min-height: 34px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); color: var(--ink); }
.settings-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  z-index: 40;
  display: none;
  grid-template-columns: repeat(2, minmax(145px, 1fr));
  gap: 7px;
  width: min(560px, calc(100vw - 28px));
  max-height: min(70vh, 520px);
  overflow: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.settings-menu[hidden], .topbar:not(.tools-expanded) .settings-menu { display: none !important; }
.topbar.tools-expanded .settings-menu:not([hidden]) { display: grid; }
.settings-menu .tool-btn, .settings-menu .file-action { width: 100%; justify-content: center; text-align: center; }
.settings-check {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
}
.settings-check input { width: 16px; height: 16px; accent-color: var(--brand); }
.tool-btn { padding: 6px 10px; font-size: 12px; white-space: nowrap; }
.tool-btn:hover, .text-btn:hover, .tab:hover, .mini-btn:hover { border-color: var(--brand); }
.tool-btn.run, .tool-btn[aria-pressed="true"], .primary-btn { background: var(--brand); border-color: var(--brand); color: #fff; }
.tool-btn[aria-pressed="false"] { background: var(--surface); color: var(--ink); }
.text-btn { padding: 5px 8px; color: var(--brand); font-size: 12px; }
.primary-btn { width: 100%; padding: 10px 12px; font-weight: 700; }
.mini-btn { min-height: 30px; padding: 4px 8px; font-size: 12px; }
.mini-btn.danger { color: var(--danger); }

.workspace { display: grid; grid-template-columns: 270px minmax(520px, 1fr) 360px; min-height: 0; overflow: hidden; }
.workspace.hide-left { grid-template-columns: minmax(520px, 1fr) 360px; }
.workspace.hide-left .toolbox { display: none; }
.workspace.hide-right { grid-template-columns: 270px minmax(520px, 1fr); }
.workspace.hide-right .inspector { display: none; }
.workspace.hide-left.hide-right, .workspace.circuit-only { grid-template-columns: minmax(520px, 1fr); }
.workspace.hide-left.hide-right .toolbox, .workspace.hide-left.hide-right .inspector, .workspace.circuit-only .toolbox, .workspace.circuit-only .inspector { display: none; }
.toolbox, .inspector { height: 100%; min-height: 0; overflow: auto; background: var(--surface); overscroll-behavior: contain; }
.toolbox { border-right: 1px solid var(--line); padding: 14px; }
.inspector { border-left: 1px solid var(--line); }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; color: var(--brand); font-weight: 800; }
.toolbox-search { width: 100%; min-height: 36px; margin: 0 0 12px; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: var(--surface); color: var(--ink); }
.toolbox-list { display: grid; gap: 14px; }
.tool-group h2 { margin: 0 0 8px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; }
.tool-grid { display: grid; gap: 7px; }
.symbol-tool { display: grid; grid-template-columns: 46px 1fr; align-items: center; gap: 9px; width: 100%; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); text-align: left; }
.symbol-tool:hover { border-color: var(--accent); background: #f8fbfd; }
.symbol-preview { width: 46px; height: 34px; border-radius: 6px; background: var(--surface-2); display: grid; place-items: center; color: var(--line-dark); }
.symbol-preview svg { width: 42px; height: 30px; display: block; }
.txt-preview { font-size: 11px; font-weight: 800; color: var(--brand); }
.symbol-tool strong, .symbol-tool span:last-child { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.symbol-tool strong { font-size: 13px; }
.symbol-tool span:last-child { color: var(--muted); font-size: 11px; }

.sheet-wrap { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0; overflow: hidden; }
.sheet-status { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 13px; color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); background: #fbfcfe; }
.sheet-credit { margin-left: auto; color: var(--muted); font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); font-size: 12px; font-weight: 800; }
.badge.running { color: #0f5b38; border-color: #8ccfae; background: #e7f8ee; }
.badge.stopped { color: #87530b; border-color: #edcc91; background: #fff7e6; }
.sheet-scroller {
  --grid-minor-size: 24px;
  --grid-major-size: 120px;
  min-height: 0;
  overflow: auto;
  background-color: var(--paper);
  background-image:
    linear-gradient(#d4dde7 1.2px, transparent 1.2px),
    linear-gradient(90deg, #d4dde7 1.2px, transparent 1.2px),
    linear-gradient(#e8edf2 1px, transparent 1px),
    linear-gradient(90deg, #e8edf2 1px, transparent 1px);
  background-size: var(--grid-major-size) var(--grid-major-size), var(--grid-major-size) var(--grid-major-size), var(--grid-minor-size) var(--grid-minor-size), var(--grid-minor-size) var(--grid-minor-size);
  background-position: 0 0;
  overscroll-behavior: contain;
  cursor: default;
}
.sheet-scroller.pan-mode { cursor: grab; }
.sheet-scroller.is-panning { cursor: grabbing; user-select: none; }
.sheet { width: 1500px; height: 900px; display: block; }
.paper { fill: transparent; stroke: #7c8da1; stroke-width: 2; stroke-dasharray: 8 8; }
.grid-line { fill: none; stroke: #e8edf2; stroke-width: 1; }
.grid-major { fill: none; stroke: #d4dde7; stroke-width: 1.2; }

.wire-hit { fill: none; stroke: transparent; stroke-width: 18; stroke-linecap: square; stroke-linejoin: miter; pointer-events: none; cursor: pointer; }
.wire-segment-hit { fill: none; stroke: transparent; stroke-width: 18; stroke-linecap: square; pointer-events: stroke; cursor: grab; }
.wire-segment-hit.active { stroke: rgba(124, 58, 237, 0.18); }
.wire-trace { fill: none; stroke: #7c3aed; stroke-width: 9; stroke-linecap: square; stroke-linejoin: miter; opacity: 0.28; pointer-events: none; }
.wire-selection { fill: none; stroke: rgba(11, 117, 111, 0.24); stroke-width: 13; stroke-linecap: square; stroke-linejoin: miter; pointer-events: none; }
.wire-path { fill: none; stroke: #263445; stroke-width: 3; stroke-linecap: square; stroke-linejoin: miter; pointer-events: none; }
.wire-draft { fill: none; stroke: #2563eb; stroke-width: 3; stroke-linecap: square; stroke-linejoin: miter; stroke-dasharray: 9 6; pointer-events: none; filter: drop-shadow(0 0 3px rgba(37, 99, 235, 0.32)); }
.wire-draft-point { fill: #fff; stroke: #2563eb; stroke-width: 2; pointer-events: none; }
.wire-path.marked { stroke: var(--wire-highlight); stroke-width: 5; filter: drop-shadow(0 0 3px rgba(11, 117, 111, 0.45)); }
.wire-path.selected { stroke: var(--wire-highlight, var(--accent)); stroke-width: 6; filter: drop-shadow(0 0 5px rgba(11, 117, 111, 0.58)); }
.wire-path.connected { stroke: var(--connected); stroke-width: 5; filter: drop-shadow(0 0 3px rgba(37, 99, 235, 0.45)); }
.wire-path.live.connected { stroke: var(--connected); }
.wire-handle { fill: var(--paper); stroke: var(--accent); stroke-width: 2; cursor: move; }
.wire-handle.active { fill: #d9f4ee; stroke-width: 3; }
.wire-path.live { stroke: var(--live); stroke-width: 4; filter: drop-shadow(0 0 3px rgba(233, 169, 0, 0.65)); }
.wire-number { font-size: 10px; fill: var(--brand); font-weight: 800; paint-order: stroke; stroke: var(--paper); stroke-width: 3px; }
.junction { fill: #263445; }
.junction.live { fill: var(--live); }
.junction-symbol { fill: #263445; stroke: #263445; }
.device { cursor: move; }
.device-hit { fill: transparent; pointer-events: all; cursor: pointer; }
.device .symbol-stroke { fill: none; stroke: #1f2a37; stroke-width: 2.2; stroke-linecap: square; stroke-linejoin: miter; }
.device .thin-stroke { fill: none; stroke: #1f2a37; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; }
.device .symbol-fill { fill: var(--paper); stroke: #1f2a37; stroke-width: 2; }
.device .lamp-lens { transition: fill 120ms ease, stroke 120ms ease, fill-opacity 120ms ease, filter 120ms ease; }
.device .emergency-head { stroke: #dc2626; fill: #fff5f5; }
.device .emergency-cross { stroke: #dc2626; stroke-width: 2; }
.device.selected .select-box, .annotation.selected .select-box { display: block; }
.select-box { display: none; fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; pointer-events: none; }
.device.live .symbol-stroke, .device.live .thin-stroke, .device.live .symbol-fill { stroke: var(--live); }
.device.closed .contact-state { stroke: var(--closed); }
.device.state-on .contact-state, .device.state-on .symbol-stroke, .device.state-on .thin-stroke { stroke: var(--state-on); }
.device.state-off .contact-state, .device.state-off .symbol-stroke, .device.state-off .thin-stroke { stroke: var(--state-off); }
.device.state-on .symbol-fill { fill: var(--state-on-fill); stroke: var(--state-on); }
.device.state-off .symbol-fill { fill: var(--state-off-fill); stroke: var(--state-off); }
.device.state-on .state-label { fill: var(--state-on); }
.device.state-off .state-label { fill: var(--state-off); }
.device.operated .device-hit { fill: rgba(19, 138, 67, 0.12); }
.device.operated.state-off .device-hit { fill: rgba(198, 40, 40, 0.12); }
.device.operated .symbol-stroke, .device.operated .thin-stroke, .device.operated .contact-state, .device.operated .symbol-fill { stroke-width: 3.4; filter: drop-shadow(0 0 5px rgba(19, 138, 67, 0.62)); }
.device.operated.state-off .symbol-stroke, .device.operated.state-off .thin-stroke, .device.operated.state-off .contact-state, .device.operated.state-off .symbol-fill { filter: drop-shadow(0 0 5px rgba(198, 40, 40, 0.62)); }
.device.operated .state-label { font-size: 12px; }
.device-tag { font-size: 14px; font-weight: 800; fill: var(--brand); }
.state-label { font-size: 10px; font-weight: 800; fill: var(--muted); }
.state-label.active { fill: currentColor; }
.device-desc, .terminal-label, .io-label { font-size: 11px; fill: #334155; pointer-events: none; }
.term-id { font-size: 10px; fill: var(--muted); }
.terminal-hit { fill: transparent; stroke: transparent; stroke-width: 0; cursor: crosshair; }
.terminal-node { fill: var(--paper); stroke: #1f2a37; stroke-width: 2; cursor: crosshair; pointer-events: none; }
.terminal-node.hot { stroke: var(--hot); }
.terminal-node.neutral { stroke: var(--neutral); }
.terminal-node.live { fill: #fff2ba; stroke: var(--live); }
.terminal-node.armed { stroke: var(--accent); stroke-width: 4; }
.annotation { cursor: move; }
.annotation text { font-size: 15px; fill: #1f2937; font-weight: 700; }
.annotation .note-bg { fill: rgba(255, 253, 248, 0.72); stroke: none; }
.plc-body { fill: #f8fafc; stroke: #1f2a37; stroke-width: 2; }
.plc-terminal { fill: #ffffff; stroke: #1f2a37; stroke-width: 1.3; }
.plc-terminal.live { fill: #fff2ba; stroke: var(--live); }
.plc-header { fill: #e8eef5; stroke: #1f2a37; stroke-width: 1.5; }

.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 12px; border-bottom: 1px solid var(--line); }
.tab { padding: 8px 4px; font-size: 13px; }
.tab.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tab-panel { display: none; padding: 14px; }
.tab-panel.active { display: block; }
.empty { margin: 0; color: var(--muted); font-size: 13px; }
.field { display: grid; gap: 6px; margin-bottom: 11px; color: var(--muted); font-size: 12px; font-weight: 800; }
.field input, .field select, .field textarea { width: 100%; min-height: 36px; border: 1px solid var(--line); border-radius: 7px; padding: 7px 9px; background: var(--surface); color: var(--ink); font-weight: 500; }
.field textarea { min-height: 70px; resize: vertical; }
.check-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 11px; color: var(--muted); font-size: 12px; font-weight: 800; }
.check-row input { width: 18px; height: 18px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0 14px; }
.wide-btn { width: 100%; min-height: 36px; border: 1px solid var(--brand); border-radius: 7px; background: var(--brand); color: #fff; font-weight: 700; }
.wide-btn.danger { border-color: var(--danger); background: var(--danger); }
.control-list { display: grid; gap: 7px; margin-bottom: 14px; }
.control-btn { display: grid; grid-template-columns: 68px 1fr auto; align-items: center; gap: 8px; min-height: 42px; border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; color: var(--ink); padding: 8px; text-align: left; }
.control-btn:hover { border-color: var(--brand); }
.control-btn.is-active { border-color: var(--live); background: #fff8d7; }
.control-btn strong { color: var(--brand); }
.control-btn span { color: var(--muted); font-size: 12px; }
.control-btn em { color: var(--muted); font-size: 11px; font-style: normal; }
.status-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-bottom: 13px; }
.stat, .list li, .template-card, .trace-card, .link-status { border: 1px solid var(--line); border-radius: var(--radius); background: #fbfcfe; padding: 10px; }
.trace-card strong { display: block; margin-bottom: 6px; color: var(--ink); }
.trace-steps { display: grid; gap: 4px; margin: 6px 0 10px 18px; padding: 0; }
.trace-steps li.active { color: #7c3aed; font-weight: 800; }
.stat strong { display: block; color: var(--brand); font-size: 20px; }
.stat span, .template-card p, .trace-card, .list li { color: var(--muted); font-size: 12px; }
.list { display: grid; gap: 8px; margin: 0 0 14px; padding: 0; list-style: none; }
.warning { color: var(--danger) !important; }
.ok { color: #0f6b42 !important; }
.detail-label { margin: 13px 0 7px; color: var(--brand); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.04em; }
.template-card, .template-save-card { display: grid; gap: 8px; margin-bottom: 10px; }
.template-card h3, .template-save-card h3 { margin: 0; font-size: 15px; }
.template-card p, .template-save-card p { margin: 0; }
.template-card button, .template-save-card button { min-height: 35px; border: 1px solid var(--brand); border-radius: 7px; color: #fff; background: var(--brand); }
.template-card button.secondary { color: var(--danger); border-color: #f2c4c8; background: #fff; }
.template-save-card { border: 1px solid var(--line); border-radius: var(--radius); background: #f8fbfd; padding: 10px; }
.template-save-row, .template-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.meta-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.terminal-schedule { max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 12px; }
.terminal-schedule table { width: 100%; border-collapse: collapse; font-size: 12px; }
.terminal-schedule th, .terminal-schedule td { padding: 6px 7px; border-bottom: 1px solid var(--line); text-align: left; }
.template-save-row input { min-height: 35px; min-width: 0; border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; background: #fff; }

.dialog { width: min(760px, calc(100vw - 30px)); border: 0; border-radius: 10px; padding: 0; box-shadow: var(--shadow); }
.wide-dialog { width: min(1100px, calc(100vw - 30px)); }
.dialog::backdrop { background: rgba(15, 23, 42, 0.46); }
.confirm-dialog { width: min(560px, calc(100vw - 30px)); }
.confirm-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; padding: 0 18px 18px; }
.modal { padding: 18px; }
.modal-header { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 15px; }
.modal-header h2, .modal h3 { margin: 0 0 4px; color: var(--brand); }
.modal-header p { margin: 0; color: var(--muted); font-size: 13px; }
.modal-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.ladder-head { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 16px; }
.signal-list, .rung-editor { display: grid; gap: 8px; }
.signal-pill { display: flex; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 7px; background: #fbfcfe; font-size: 12px; }
.signal-pill.on { border-color: #dfb431; background: #fff4ca; }
.ladder-contact-editor { display: grid; grid-template-columns: auto minmax(120px, 170px) 72px minmax(120px, 1fr) auto; gap: 8px; align-items: center; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: #f8fbfd; }
.ladder-contact-editor.empty { display: block; color: var(--muted); font-size: 12px; }
.ladder-contact-editor select { min-height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: #fff; }
.ladder-contact-editor span { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.ladder-rung { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: #fbfcfe; }
.ladder-rung.on { border-color: #d8aa18; background: #fffaf0; }
.ladder-add-buttons { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.ladder-rung-head { display: grid; grid-template-columns: minmax(140px, 1fr) 92px 76px 64px minmax(96px, 130px) auto; gap: 8px; margin-bottom: 8px; align-items: center; }
.ladder-rung-head input, .ladder-rung-head select { min-height: 30px; min-width: 0; border: 1px solid var(--line); border-radius: 6px; padding: 4px 6px; background: #fff; }
.ladder-muted { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; }
.ladder-diagram { position: relative; display: grid; grid-template-columns: 18px minmax(0, 1fr) 104px 18px; align-items: stretch; min-height: 96px; border: 1px solid #d7e0ea; background: #ffffff; overflow-x: auto; }
.ladder-rail { width: 3px; margin: 0 auto; background: #22a34a; }
.ladder-stages { display: flex; align-items: flex-start; gap: 0; min-width: max-content; padding: 10px 4px 8px; }
.ladder-stage { --wire-y: 24px; position: relative; display: grid; grid-template-rows: auto auto; align-items: start; gap: 4px; min-width: 118px; max-width: 138px; padding: 0 7px 4px; }
.ladder-stage-line { position: absolute; left: -7px; right: -7px; top: var(--wire-y); height: 2px; background: #1f2a37; z-index: 0; }
.ladder-parallel { position: relative; z-index: 1; display: grid; align-content: start; justify-items: center; gap: 6px; padding: 0 10px; }
.ladder-stage.is-parallel .ladder-parallel::before, .ladder-stage.is-parallel .ladder-parallel::after { content: ""; position: absolute; top: var(--wire-y); bottom: 26px; width: 2px; background: #1f2a37; }
.ladder-stage.is-parallel .ladder-parallel::before { left: 8px; }
.ladder-stage.is-parallel .ladder-parallel::after { right: 8px; }
.ladder-contact { position: relative; z-index: 1; display: grid; grid-template-rows: 12px 20px 14px; align-items: center; width: 96px; min-height: 50px; padding: 2px 4px; border: 0; border-radius: 5px; background: transparent; color: #172033; cursor: pointer; text-align: center; }
.ladder-stage.is-parallel .ladder-contact::before, .ladder-stage.is-parallel .ladder-contact::after { content: ""; position: absolute; top: 24px; width: 12px; height: 2px; background: #1f2a37; }
.ladder-stage.is-parallel .ladder-contact::before { left: -10px; }
.ladder-stage.is-parallel .ladder-contact::after { right: -10px; }
.ladder-contact:hover, .ladder-contact.selected { outline: 2px solid var(--accent); background: #eefaf7; }
.ladder-contact.on { color: #138a43; background: #eaf8ef; }
.ladder-address { color: var(--brand); font-size: 10px; font-weight: 800; line-height: 1; }
.ladder-name { max-width: 88px; overflow: hidden; color: var(--muted); font-size: 9px; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.ladder-contact-symbol { display: grid; grid-template-columns: 1fr 22px 1fr; align-items: center; color: currentColor; font-weight: 800; }
.ladder-contact-symbol i { height: 2px; background: currentColor; }
.ladder-contact-symbol b { min-width: 22px; font-size: 15px; line-height: 1; }
.ladder-stage-actions { position: relative; z-index: 1; display: flex; flex-wrap: wrap; justify-content: center; gap: 3px; }
.ladder-stage-actions .mini-btn { min-height: 22px; padding: 2px 5px; font-size: 10px; }
.ladder-coil { display: grid; grid-template-columns: 1fr; align-content: center; justify-items: center; gap: 3px; padding: 6px; border-left: 2px solid #1f2a37; background: #fbfcfe; }
.ladder-coil.on { color: #0f7a3a; background: #edfbf1; }
.timer-block { min-width: 118px; }
.timer-kind { border: 1px solid currentColor; border-radius: 4px; padding: 1px 5px; font-size: 10px; font-weight: 800; }
.coil-lead { width: 100%; height: 2px; background: currentColor; }
.coil-symbol { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 20px; line-height: 1; }
.ladder-coil strong { color: var(--brand); font-size: 11px; }
.ladder-coil small { max-width: 88px; min-height: 13px; overflow: hidden; color: var(--muted); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.ladder-actions { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 6px; }
.rung { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; background: #fbfcfe; }
.rung-top { display: grid; grid-template-columns: 1fr 130px auto; gap: 8px; margin-bottom: 8px; }
.branch { display: grid; gap: 6px; padding: 8px; border-left: 3px solid var(--accent); background: #ffffff; margin-bottom: 8px; }
.contact-edit { display: grid; grid-template-columns: 1fr 82px auto; gap: 7px; }
.contact-edit select, .rung-top input, .rung-top select { min-height: 32px; border: 1px solid var(--line); border-radius: 6px; padding: 5px 7px; }

@media (max-width: 1180px) {
  html, body { overflow: auto; }
  .app-shell { height: auto; min-height: 100vh; overflow: visible; }
  .workspace { grid-template-columns: 240px minmax(420px, 1fr); overflow: visible; }
  .inspector { grid-column: 1 / -1; height: auto; min-height: auto; border-left: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .topbar { grid-template-columns: 1fr; align-items: stretch; }
  .brand { min-width: 0; }
  .toolbar { justify-content: flex-start; max-height: 126px; overflow: visible; }
  .workspace { grid-template-columns: 1fr; }
  .toolbox { height: auto; min-height: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .tool-grid { grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
  .sheet { width: 1200px; height: 760px; }
  .modal-grid, .ladder-head, .ladder-contact-editor, .rung-top, .contact-edit, .template-save-row, .template-actions, .meta-grid { grid-template-columns: 1fr; }
}


.status-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 6px 12px; border-top: 1px solid var(--line); background: var(--surface); color: var(--muted); font-size: 12px; }
.status-bar span { padding-right: 10px; border-right: 1px solid var(--line); }
.context-menu { position: fixed; z-index: 50; display: grid; min-width: 160px; padding: 6px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); box-shadow: var(--shadow); }
.context-menu[hidden] { display: none; }
.context-menu button { min-height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--ink); text-align: left; padding: 6px 8px; }
.context-menu button:hover { background: var(--surface-2); color: var(--brand); }


/* Professional v2 panels */
.dashboard-actions, .report-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.project-list { display: grid; gap: 10px; max-height: min(62vh, 620px); overflow: auto; padding-right: 4px; }
.project-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--surface); }
.project-card.active { border-color: var(--brand); box-shadow: inset 3px 0 0 var(--brand); }
.project-card h3 { margin: 0 0 4px; color: var(--brand); font-size: 15px; }
.project-card p { margin: 0 0 5px; color: var(--text); font-size: 13px; }
.project-card small { color: var(--muted); }
.project-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.project-actions button, .report-tabs button { min-height: 30px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--text); font-weight: 700; }
.project-actions .danger { color: #b42318; border-color: #f2b8b5; }
.report-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.report-content { max-height: min(62vh, 620px); overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
.report-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.report-table th, .report-table td { padding: 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.report-table th { position: sticky; top: 0; background: var(--surface-2); color: var(--brand); z-index: 1; }
.cable-tag { fill: #6b5a00; font-weight: 700; }
.field select { width: 100%; min-height: 34px; border: 1px solid var(--line); border-radius: 7px; background: #fff; color: var(--text); }
@media (max-width: 760px) { .project-card { grid-template-columns: 1fr; } .project-actions { justify-content: flex-start; } }

/* Training and macro workflow */
.macro-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; max-height: min(62vh, 620px); overflow: auto; padding-right: 4px; }
.macro-card { border: 1px solid var(--line); border-radius: 8px; padding: 12px; background: var(--surface); display: grid; gap: 8px; align-content: start; }
.macro-card h3 { margin: 0; color: var(--brand); font-size: 15px; }
.macro-card p { margin: 0; color: var(--muted); font-size: 13px; }
.ladder-rung-head { grid-template-columns: minmax(130px, 1fr) 76px 72px 82px auto; }
.ladder-rung-head input[data-rung-preset] { min-width: 58px; }
.report-table .ok { color: #087443; font-weight: 800; }
.report-table .warning { color: #b42318; font-weight: 800; }

body.ecad-mode {
  --live: #e3342f;
  --closed: #e3342f;
  --connected: #1d4ed8;
  --paper: #fffefa;
}
body.ecad-mode .brand h1 { font-size: 17px; }
.variant-switch { margin-top: 2px !important; font-size: 10px !important; font-weight: 700; }
.variant-switch a { color: var(--brand); text-decoration: none; }
.variant-switch a:hover { text-decoration: underline; }
body.ecad-mode .sheet-status { background: #fffdfa; }
body.ecad-mode .symbol-preview { background: #fffefa; color: #111827; }
body.ecad-mode .wire-path { stroke: #202020; stroke-width: 2; }
body.ecad-mode .wire-path.live { stroke: #e3342f; stroke-width: 3; filter: none; }
body.ecad-mode .wire-path.selected { stroke: #2563eb; stroke-width: 5; filter: none; }
body.ecad-mode .wire-trace { stroke: #f59e0b; opacity: 0.34; }
body.ecad-mode .wire-number { fill: #333; stroke: var(--paper); font-size: 9px; }
body.ecad-mode .junction, body.ecad-mode .junction-symbol { fill: #111; stroke: #111; }
body.ecad-mode .device .symbol-stroke { stroke: #111827; stroke-width: 1.6; stroke-linecap: square; stroke-linejoin: miter; }
body.ecad-mode .device .thin-stroke { stroke: #111827; stroke-width: 1.1; stroke-linecap: square; stroke-linejoin: miter; }
body.ecad-mode .device .symbol-fill { fill: var(--paper); stroke: #111827; stroke-width: 1.4; }
body.ecad-mode .device.live .symbol-stroke,
body.ecad-mode .device.live .thin-stroke,
body.ecad-mode .device.live .symbol-fill,
body.ecad-mode .device.closed .contact-state { stroke: #e3342f; }
body.ecad-mode .device.state-on .contact-state,
body.ecad-mode .device.state-on .symbol-stroke,
body.ecad-mode .device.state-on .thin-stroke { stroke: #e3342f; }
body.ecad-mode .device.state-on .symbol-fill { fill: #fff5f5; stroke: #e3342f; }
body.ecad-mode .device.state-off .contact-state,
body.ecad-mode .device.state-off .symbol-stroke,
body.ecad-mode .device.state-off .thin-stroke { stroke: #111827; }
body.ecad-mode .device.operated .symbol-stroke,
body.ecad-mode .device.operated .thin-stroke,
body.ecad-mode .device.operated .contact-state,
body.ecad-mode .device.operated .symbol-fill { stroke-width: 2.6; filter: drop-shadow(0 0 4px rgba(227, 52, 47, 0.45)); }
body.ecad-mode .device-tag { fill: #4b5563; font-weight: 500; }
body.ecad-mode .ecad-tag { fill: #555; font-size: 13px; }
body.ecad-mode .ecad-desc { fill: #4b5563; font-size: 10px; }
body.ecad-mode .term-id { fill: #555; font-size: 9px; }
body.ecad-mode .terminal-label { fill: #555; font-size: 9px; }
body.ecad-mode .terminal-node { r: 4px; fill: #fffefa; stroke: #111827; stroke-width: 1.4; }
body.ecad-mode .terminal-node.live { fill: #fffefa; stroke: #e3342f; }
body.ecad-mode .terminal-hit { cursor: crosshair; }
body.ecad-mode .plc-body { fill: #fffefa; stroke: #555; stroke-width: 1.2; }
body.ecad-mode .plc-header { fill: #f8f8f6; stroke: #555; stroke-width: 1.1; }
body.ecad-mode .plc-terminal { fill: #fffefa; stroke: #555; stroke-width: 1; }
body.ecad-mode .plc-terminal.live { fill: #fff1f1; stroke: #e3342f; }
body.ecad-mode .io-label { fill: #333; font-size: 9px; }
body.ecad-mode .select-box { stroke: #2563eb; }







/* ECAD drafting refinements */
body.ecad-mode {
  --paper: #fffefa;
  --live: #e3342f;
  --closed: #e3342f;
  --connected: #0f62c2;
}
body.ecad-mode .sheet-scroller {
  background-color: #fffefa;
  background-image:
    linear-gradient(#d9dde2 1px, transparent 1px),
    linear-gradient(90deg, #d9dde2 1px, transparent 1px),
    linear-gradient(#eef0f2 1px, transparent 1px),
    linear-gradient(90deg, #eef0f2 1px, transparent 1px);
}
body.ecad-mode .sheet-status {
  background: #fffefa;
  color: #4b5563;
}
body.ecad-mode .paper {
  stroke: #6b7280;
  stroke-width: 1.2;
  stroke-dasharray: 10 6;
}
body.ecad-mode .wire-hit,
body.ecad-mode .wire-segment-hit {
  stroke-width: 14;
}
body.ecad-mode .wire-path {
  stroke: #151515;
  stroke-width: 1.65;
  filter: none;
}
body.ecad-mode .wire-path.live {
  stroke: #e3342f;
  stroke-width: 2.15;
  filter: none;
}
body.ecad-mode .wire-selection {
  stroke: rgba(15, 98, 194, 0.22);
  stroke-width: 8;
}
body.ecad-mode .wire-path.selected {
  stroke: #0f62c2;
  stroke-width: 3.2;
  filter: none;
}
body.ecad-mode .wire-path.connected {
  stroke: #0f62c2;
  stroke-width: 2.6;
  filter: none;
}
body.ecad-mode .wire-draft {
  stroke: #0f62c2;
  stroke-width: 1.8;
  stroke-dasharray: 8 5;
  filter: none;
}
body.ecad-mode .wire-number {
  fill: #111827;
  font: 500 9px Consolas, "Liberation Mono", monospace;
  stroke: #fffefa;
  stroke-width: 2px;
}
body.ecad-mode .junction,
body.ecad-mode .junction-symbol {
  fill: #111;
  stroke: #111;
}
body.ecad-mode .device .symbol-stroke {
  stroke: #111;
  stroke-width: 1.35;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
body.ecad-mode .device .thin-stroke {
  stroke: #111;
  stroke-width: 0.95;
  stroke-linecap: square;
  stroke-linejoin: miter;
}
body.ecad-mode .device .symbol-fill {
  fill: #fffefa;
  stroke: #111;
  stroke-width: 1.2;
}
body.ecad-mode .device .ecad-node,
body.ecad-mode .device .terminal-node {
  fill: #fffefa;
  stroke: #111;
}
body.ecad-mode .device.live .symbol-stroke,
body.ecad-mode .device.live .thin-stroke,
body.ecad-mode .device.live .symbol-fill,
body.ecad-mode .device.closed .contact-state,
body.ecad-mode .device.state-on .contact-state,
body.ecad-mode .device.state-on .symbol-stroke,
body.ecad-mode .device.state-on .thin-stroke {
  stroke: #e3342f;
}
body.ecad-mode .device.state-on .symbol-fill {
  fill: #fffefa;
  stroke: #e3342f;
}
body.ecad-mode .device.state-off .symbol-stroke,
body.ecad-mode .device.state-off .thin-stroke,
body.ecad-mode .device.state-off .contact-state {
  stroke: #111;
}
body.ecad-mode .device.operated .device-hit,
body.ecad-mode .device.operated.state-off .device-hit {
  fill: transparent;
}
body.ecad-mode .device.operated .symbol-stroke,
body.ecad-mode .device.operated .thin-stroke,
body.ecad-mode .device.operated .contact-state,
body.ecad-mode .device.operated .symbol-fill {
  stroke-width: 1.9;
  filter: none;
}
body.ecad-mode .device-tag,
body.ecad-mode .ecad-tag,
body.ecad-mode .term-id,
body.ecad-mode .terminal-label,
body.ecad-mode .io-label,
body.ecad-mode .device-desc,
body.ecad-mode .ecad-desc,
body.ecad-mode .annotation text {
  font-family: Consolas, "Liberation Mono", ui-monospace, monospace;
  font-weight: 500;
}
body.ecad-mode .device-tag,
body.ecad-mode .ecad-tag {
  fill: #374151;
  font-size: 12px;
}
body.ecad-mode .device-desc,
body.ecad-mode .ecad-desc {
  fill: #4b5563;
  font-size: 9px;
}
body.ecad-mode .term-id,
body.ecad-mode .terminal-label,
body.ecad-mode .io-label {
  fill: #374151;
  font-size: 8.5px;
}
body.ecad-mode .terminal-node {
  r: 4px;
  fill: #fffefa;
  stroke: #111;
  stroke-width: 1.15;
}
body.ecad-mode .terminal-node.live {
  fill: #fffefa;
  stroke: #e3342f;
  stroke-width: 1.6;
}
body.ecad-mode .terminal-node.armed {
  stroke: #0f62c2;
  stroke-width: 2.4;
}
body.ecad-mode .select-box {
  stroke: #0f62c2;
  stroke-width: 1.6;
  stroke-dasharray: 7 4;
}
body.ecad-mode .plc-body,
body.ecad-mode .plc-header,
body.ecad-mode .plc-terminal {
  fill: #fffefa;
  stroke: #4b5563;
  stroke-width: 1;
}
body.ecad-mode .plc-terminal.live {
  fill: #fffefa;
  stroke: #e3342f;
  stroke-width: 1.4;
}
body.ecad-mode .symbol-preview {
  border-radius: 0;
  background: #fffefa;
  color: #111;
}
body.ecad-mode .symbol-tool {
  border-radius: 3px;
}
body.ecad-mode .emergency-head {
  fill: #fffefa;
  stroke: #e3342f !important;
}
body.ecad-mode .emergency-cross {
  fill: none;
  stroke: #e3342f;
  stroke-width: 1.2;
}
