/* ==========================================================================
   plc.css — the pop-out PLC / digital-twin takeover
   ========================================================================== */
.plc-takeover {
  position: fixed; inset: 0; z-index: 100;
  background: var(--paper); color: var(--ink);
  display: grid; grid-template-rows: auto 1fr;
  animation: plc-in .22s ease-out;
}
.plc-takeover[hidden] { display: none; }
@keyframes plc-in { from { transform: translateY(100%); } to { transform: none; } }
body.plc-open { overflow: hidden; }
@media (prefers-reduced-motion: reduce) { .plc-takeover { animation: none; } }

.plc-bar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; border-bottom: var(--line) solid var(--ink); background: var(--yellow);
}
.plc-bar .title { font-family: var(--font-display); font-size: 1.3rem; text-transform: uppercase; }
.plc-bar .spacer { flex: 1; }
.plc-bar .btn { font-size: 0.9rem; padding: 6px 12px; box-shadow: 3px 3px 0 var(--ink); }
.plc-bar .btn:hover { box-shadow: 1px 1px 0 var(--ink); }
.plc-mode { display: inline-flex; border: var(--line) solid var(--ink); overflow: hidden; font-family: var(--font-mono); font-size: 0.8rem; }
.plc-mode button { border: 0; background: var(--white); padding: 6px 12px; font: inherit; cursor: pointer; letter-spacing: 0.12em; }
.plc-mode button + button { border-left: var(--line) solid var(--ink); }
.plc-mode button[aria-pressed="true"] { background: var(--ink); color: var(--yellow); }
.plc-status { font-family: var(--font-mono); font-size: 0.75rem; letter-spacing: 0.08em; display: flex; gap: 14px; }
.plc-status .led { display: inline-block; width: 10px; height: 10px; border: 2px solid var(--ink); border-radius: 50%; background: var(--paper-2); vertical-align: -1px; margin-right: 4px; }
.plc-status .led.on { background: #38e04b; box-shadow: 0 0 6px #38e04b; }
.plc-status .led.fault { background: var(--magenta); }

.plc-split { display: grid; grid-template-columns: minmax(380px, 1fr) minmax(320px, 1fr); min-height: 0; }
.plc-pane { min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
.plc-pane + .plc-pane { border-left: var(--line) solid var(--ink); }
.pane-head { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 2px solid var(--ink); background: var(--paper-2); font-family: var(--font-caption); font-weight: 700; text-transform: uppercase; font-size: 0.85rem; }
.pane-head .spacer { flex: 1; }
.pane-head select, .pane-head button { font: inherit; font-size: 0.8rem; border: 2px solid var(--ink); background: var(--white); padding: 3px 8px; cursor: pointer; }
.pane-head button:hover { background: var(--yellow); }

/* ---- Ladder pane: text editor on top, rendered ladder below ---- */
.ladder-editor { display: grid; grid-template-rows: minmax(140px, 32%) 1fr; min-height: 0; flex: 1; }
.ladder-text {
  margin: 0; width: 100%; height: 100%; resize: none; border: 0;
  border-bottom: var(--line) solid var(--ink);
  font-family: var(--font-mono); font-size: 13px; line-height: 1.5;
  padding: 10px 14px; background: var(--ink); color: var(--paper); outline: none;
  tab-size: 4; white-space: pre; overflow: auto;
}
.ladder-text:focus { box-shadow: inset 0 0 0 3px var(--cyan); }
.ladder-errors { font-family: var(--font-mono); font-size: 0.75rem; color: var(--white); background: var(--magenta); padding: 4px 12px; display: none; }
.ladder-errors.show { display: block; }

.ladder { overflow: auto; padding: 14px 16px 30px; background:
  repeating-linear-gradient(0deg, transparent 0 23px, rgba(20,20,20,0.06) 23px 24px); }
.rung { display: flex; align-items: center; min-height: 86px; position: relative; padding-top: 18px; }
.rung-comment { position: absolute; top: 0; left: 18px; font-family: var(--font-caption); font-weight: 700; font-size: 0.72rem; text-transform: uppercase; color: var(--ink-soft); }
.rung-num { font-family: var(--font-mono); font-size: 0.7rem; width: 28px; color: var(--ink-soft); flex: none; }
.rail { width: 6px; align-self: stretch; background: var(--ink); flex: none; }
.rail.hot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.wire { flex: 1 0 18px; height: 4px; background: var(--ink); }
.wire.hot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }
.instr { flex: none; display: flex; flex-direction: column; align-items: center; gap: 2px; position: relative; }
.instr .sym { width: 60px; height: 40px; display: block; }
.instr .sym .stroke { stroke: var(--ink); stroke-width: 4; fill: none; stroke-linecap: square; }
.instr .sym .fillbox { fill: var(--white); stroke: var(--ink); stroke-width: 3; }
.instr.hot .sym .stroke { stroke: var(--yellow); filter: drop-shadow(0 0 3px var(--yellow)); }
.instr.hot .sym .fillbox { fill: var(--yellow); }
.instr .tag { font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.04em; white-space: nowrap; }
.instr .val { font-family: var(--font-mono); font-size: 10px; color: var(--ink-soft); white-space: nowrap; }
.instr.block { align-items: stretch; }
.instr.block .box { border: 3px solid var(--ink); background: var(--white); min-width: 118px; font-family: var(--font-mono); font-size: 11px; line-height: 1.35; padding: 4px 8px; }
.instr.block .box .hd { font-weight: 700; font-size: 12px; letter-spacing: 0.1em; border-bottom: 2px solid var(--ink); margin-bottom: 3px; padding-bottom: 2px; display: flex; justify-content: space-between; gap: 8px; }
.instr.block .box .row { display: flex; justify-content: space-between; gap: 10px; }
.instr.block .box .row .bit { font-weight: 700; }
.instr.block .box .row .bit.on { color: #0a7f1e; }
.instr.block.hot .box { background: var(--yellow); box-shadow: 0 0 8px var(--yellow); }
.instr.block.done .box .hd { background: var(--cyan); margin: -4px -8px 3px; padding: 2px 8px; }
.instr.err .box, .instr.err .sym .stroke { stroke: var(--magenta); border-color: var(--magenta); }
.rung.empty .wire { background: var(--ink-soft); opacity: 0.4; }

/* ---- Viewport pane ---- */
.plc-viewport { position: relative; flex: 1; min-height: 240px; background: var(--paper); }
.plc-viewport canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.plc-controls { border-top: var(--line) solid var(--ink); padding: 10px 14px; display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px 16px; background: var(--paper-2); max-height: 42%; overflow: auto; }
.joint { display: grid; grid-template-columns: 34px 1fr 52px; gap: 8px; align-items: center; font-family: var(--font-mono); font-size: 0.75rem; }
.joint input[type=range] { width: 100%; accent-color: var(--magenta); }
.joint .deg { text-align: right; }
.plc-controls .full { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- Tag monitor ---- */
.tag-monitor { font-family: var(--font-mono); font-size: 0.75rem; border-collapse: collapse; width: 100%; }
.tag-monitor th, .tag-monitor td { border-bottom: 1px solid rgba(20,20,20,0.25); padding: 3px 8px; text-align: left; }
.tag-monitor th { background: var(--paper-2); font-family: var(--font-caption); text-transform: uppercase; font-size: 0.72rem; position: sticky; top: 0; }
.tag-monitor td.v1 { color: #0a7f1e; font-weight: 700; }
.tag-monitor .btn-toggle { font: inherit; font-size: 0.7rem; border: 2px solid var(--ink); background: var(--white); padding: 0 6px; cursor: pointer; }
.tag-monitor .btn-toggle:hover { background: var(--yellow); }
.tag-wrap { overflow: auto; max-height: 220px; border-top: var(--line) solid var(--ink); }
.plc-help { padding: 10px 14px; font-size: 0.82rem; font-family: var(--font-body); border-top: 2px solid var(--ink); background: var(--white); max-height: 200px; overflow: auto; }
.plc-help code { font-family: var(--font-mono); background: var(--paper-2); padding: 0 4px; }
.plc-help[hidden] { display: none; }

@media (max-width: 860px) {
  .plc-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .plc-pane + .plc-pane { border-left: 0; border-top: var(--line) solid var(--ink); }
  .plc-viewport { min-height: 180px; }
}
.ladder-wrap { min-height: 0; display: flex; flex-direction: column; }
.ladder-wrap .ladder { flex: 1; }
