/* ControlByte PLC Simulator. Brand: navy 1E2761 / 003057, mint 12D1A3, coral E95D67, cream F4F0E6. */

:root {
  --bg: #0d1220;
  --panel: #121a2c;
  --panel-2: #172238;
  --line: #24304a;
  --line-2: #2f3d5c;
  --text: #dbe3f1;
  --dim: #7d8aa5;
  --navy: #1e2761;
  --mint: #12d1a3;
  --mint-soft: rgba(18, 209, 163, 0.16);
  --coral: #e95d67;
  --amber: #f5b83d;
  --cream: #f4f0e6;
  --wire: #5d6c8f;
  --power: #12d1a3;
  --text-2: #b9c4d8;
  --sym: #9fb0cf;
  --box-fill: #182641;
  --box-stroke: #3c4d72;
  --box-head: #c9d6ee;
  --comment: #8a9bbd;
  --topbar: #0a0f1b;
  --shadow: rgba(0, 0, 0, 0.45);
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  color-scheme: dark;
}

/* Light theme. The top bar stays navy in both themes, so the white logo always reads. */
:root[data-theme="light"] {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #eef1f7;
  --line: #dde3ec;
  --line-2: #c4cddb;
  --text: #1b2340;
  --text-2: #3d4766;
  --dim: #66718c;
  --mint: #0b9e7c;
  --mint-soft: rgba(11, 158, 124, 0.12);
  --wire: #8f9bb3;
  --power: #0aa37f;
  --sym: #36415f;
  --box-fill: #ffffff;
  --box-stroke: #9aa6bd;
  --box-head: #1e2761;
  --comment: #5d7096;
  --topbar: #1e2761;
  --shadow: rgba(30, 39, 97, 0.18);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 13px/1.45 var(--sans); overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.dim { color: var(--dim); }
.err { color: var(--coral); }
.ok { color: var(--mint); }

/* ---------- top bar ---------- */
.top { height: 48px; display: flex; align-items: center; gap: 14px; padding: 0 14px; background: var(--topbar); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); text-decoration: none; margin-right: 8px; }
.logo-img { height: 24px; width: auto; display: block; }
.brand-t { font-size: 13px; color: var(--dim); white-space: nowrap; padding-left: 12px; border-left: 1px solid var(--line-2); }
.brand-t b { color: var(--text); }
.tb-group { display: flex; align-items: center; gap: 6px; }
.tb-group.end { margin-left: auto; }
.scan-info { font: 11px var(--mono); color: var(--dim); margin-left: 6px; min-width: 110px; }
body.running .scan-info { color: var(--mint); }

.btn { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 6px; padding: 5px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--mint); }
.btn:disabled { opacity: 0.35; cursor: default; border-color: var(--line-2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 3px 9px; font-size: 12px; }
.btn.run { color: var(--mint); border-color: rgba(18, 209, 163, 0.45); }
.btn.stop { color: var(--coral); border-color: rgba(233, 93, 103, 0.4); }
body.running .btn.run { background: var(--mint); color: #062a22; }

/* ---------- layout ---------- */
.layout { --side-w: 440px; display: grid; grid-template-columns: 210px minmax(0, 1fr) var(--side-w); grid-template-rows: minmax(0, 1fr); height: calc(100% - 48px); }
body.embed .layout { grid-template-columns: minmax(0, 1fr) var(--side-w); }
body.embed .lib, body.embed .brand { display: none; }
.lib, .side { background: var(--panel); border-right: 1px solid var(--line); overflow: auto; }
.side { border-right: 0; border-left: 1px solid var(--line); display: flex; flex-direction: column; position: relative; overflow: visible; min-height: 0; }
.side > .pane { overflow: auto; }
/* Drag handle between the program and the simulator panel. */
.splitter { position: absolute; left: -5px; top: 0; bottom: 0; width: 10px; cursor: col-resize; z-index: 30; touch-action: none; }
.splitter::after { content: ""; position: absolute; left: 4px; top: 0; bottom: 0; width: 2px; background: transparent; transition: background 0.15s; }
.splitter:hover::after, body.resizing .splitter::after { background: var(--mint); }
.splitter-grip { position: absolute; left: 1px; top: 50%; width: 8px; height: 36px; margin-top: -18px; border-radius: 4px; background: var(--line-2); }
.splitter:hover .splitter-grip, body.resizing .splitter-grip { background: var(--mint); }
body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }

.lib-h { padding: 12px 14px 6px; font: 600 11px var(--mono); letter-spacing: 0.08em; text-transform: uppercase; color: var(--dim); }
.lib-g { padding: 10px 14px 4px; font: 11px var(--mono); color: var(--mint); text-transform: uppercase; letter-spacing: 0.06em; }
.lib-item { display: flex; gap: 6px; width: 100%; text-align: left; background: none; border: 0; padding: 6px 14px; cursor: pointer; color: var(--text); font-size: 12.5px; }
.lib-item:hover { background: var(--panel-2); }
.lib-item.on { background: var(--mint-soft); box-shadow: inset 3px 0 var(--mint); }
.lib-item .tick { width: 12px; color: var(--mint); flex: none; }

.tabs { display: flex; gap: 2px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.tabs button { background: none; border: 0; padding: 9px 14px; cursor: pointer; color: var(--dim); border-bottom: 2px solid transparent; }
.tabs button.on { color: var(--text); border-bottom-color: var(--mint); }
.pane { flex: 1; min-height: 0; }
.logic-pane { display: flex; flex-direction: column; }
.side-pane { overflow: auto; padding: 14px; }

/* ---------- palette ---------- */
.palette { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 7px 10px; border-bottom: 1px solid var(--line); background: var(--panel); flex: none; }
.pal-g { display: flex; align-items: center; gap: 3px; flex-wrap: wrap; }
.pal-t { font: 10px var(--mono); color: var(--dim); text-transform: uppercase; margin-right: 3px; }
.pal-b { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; min-width: 38px; height: 34px; padding: 0 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 5px; cursor: pointer; font: 10px var(--mono); line-height: 1.1; }
.pal-b .gl { font-size: 11px; color: var(--mint); letter-spacing: -0.5px; }
.pal-b:hover { border-color: var(--mint); }
.pal-b.danger:hover { border-color: var(--coral); color: var(--coral); }

/* ---------- ladder ---------- */
.ladder { flex: 1; overflow: auto; background: var(--bg); outline: none; padding-bottom: 20px; }
svg.rung { display: block; }
.rung-bg { fill: transparent; }
.rung-bg.sel { fill: rgba(18, 209, 163, 0.05); }
svg.rung:hover .rung-bg { fill: rgba(255, 255, 255, 0.015); }
svg.rung.drop .rung-bg { fill: rgba(18, 209, 163, 0.08); }
.num { font: 12px var(--mono); fill: var(--dim); text-anchor: middle; cursor: pointer; }
.rung-bg.sel ~ .num { fill: var(--mint); font-weight: 700; }
.com { font: 12px var(--mono); fill: var(--comment); }
.rail { stroke: var(--wire); stroke-width: 3; }
.rail.on { stroke: var(--power); }
.w { stroke: var(--wire); stroke-width: 2; }
.w.on { stroke: var(--power); stroke-width: 2.5; }
.el { cursor: pointer; }
.el .hit { fill: transparent; stroke: transparent; }
.el:hover .hit { fill: rgba(255, 255, 255, 0.03); }
.el.sel .hit { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 4 3; fill: rgba(245, 184, 61, 0.06); }
.el.drop .hit { stroke: var(--mint); stroke-dasharray: none; }
.sym line, .sym path { stroke: var(--sym); stroke-width: 2; fill: none; }
.sym.on line, .sym.on path { stroke: var(--power); }
.sym.on { filter: drop-shadow(0 0 3px rgba(18, 209, 163, 0.6)); }
.ins { font: 700 11px var(--mono); fill: var(--sym); text-anchor: middle; }
.sym.on .ins { fill: var(--power); }
.lbl { font: 12px var(--mono); fill: var(--text); text-anchor: middle; }
.lbl.missing, .arg.missing { fill: var(--coral); }
.addr { font: 10px var(--mono); fill: var(--dim); text-anchor: middle; }
.box rect { fill: var(--box-fill); stroke: var(--box-stroke); stroke-width: 1.2; }
.box.on rect { stroke: var(--power); }
.bh { font: 700 11.5px var(--mono); fill: var(--box-head); }
.box.on .bh { fill: var(--power); }
.bsep { stroke: var(--box-stroke); }
.pin { font: 10px var(--mono); fill: var(--dim); }
.arg { font: 11px var(--mono); fill: var(--text); }
.val { font: 11px var(--mono); fill: var(--amber); text-anchor: end; }
.pg { cursor: pointer; }
.pg .hit { fill: transparent; stroke: transparent; }
.pg:hover .hit { stroke: var(--line-2); stroke-dasharray: 2 4; }
.pg.sel .hit { stroke: var(--amber); stroke-width: 1.5; stroke-dasharray: 4 3; fill: rgba(245, 184, 61, 0.04); }
.pg.drop .hit { stroke: var(--mint); }
.ph { cursor: pointer; }
.ph rect { fill: transparent; stroke: var(--line-2); stroke-dasharray: 3 3; }
.ph text { font: 16px var(--mono); fill: var(--dim); text-anchor: middle; }
.ph:hover rect, .ph.sel rect { stroke: var(--amber); }
.ph.sel text { fill: var(--amber); }
.end-rung { display: flex; align-items: center; gap: 12px; padding: 8px 0 0 12px; font: 12px var(--mono); color: var(--dim); }

/* ---------- inspector ---------- */
.inspector { flex: none; border-top: 1px solid var(--line); background: var(--panel); padding: 8px 12px 10px; min-height: 62px; }
.ins-h { font-size: 12px; margin-bottom: 6px; }
.ins-h b { font-family: var(--mono); color: var(--mint); margin-right: 6px; }
.ins-fields { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.ins-f { display: flex; align-items: center; gap: 6px; }
.ins-f span { font: 11px var(--mono); color: var(--dim); }
.ins-f input { width: 150px; background: var(--bg); border: 1px solid var(--line-2); border-radius: 5px; padding: 4px 8px; font-family: var(--mono); }
.ins-f.wide input { width: 420px; max-width: 60vw; }
.ins-f input:focus { outline: none; border-color: var(--mint); }

/* ---------- tags / code ---------- */
.tags-view { padding: 12px; overflow: auto; height: 100%; }
.tags-t { border-collapse: collapse; width: 100%; font-size: 12px; }
.tags-t th { text-align: left; font: 11px var(--mono); color: var(--dim); padding: 4px 6px; border-bottom: 1px solid var(--line); }
.tags-t td { padding: 3px 4px; border-bottom: 1px solid var(--line); }
.tags-t input, .tags-t select, .tag-add input, .tag-add select { width: 100%; background: transparent; border: 1px solid transparent; border-radius: 4px; padding: 3px 6px; font-family: var(--mono); font-size: 12px; }
.tags-t input:hover:not(:disabled), .tags-t select:hover:not(:disabled), .tags-t input:focus { border-color: var(--line-2); outline: none; }
.tags-t select option { background: var(--panel); }
.tags-t :disabled { opacity: 0.75; }
.tv { font: 11px var(--mono); color: var(--amber); white-space: nowrap; }
.tag-add { display: flex; gap: 8px; margin-top: 12px; max-width: 520px; }
.tag-add input, .tag-add select { border-color: var(--line-2); background: var(--bg); }
.code-pane { display: flex; flex-direction: column; padding: 12px; gap: 8px; }
.code-help { margin: 0; color: var(--dim); font-size: 12px; }
.code-help code { color: var(--mint); font-family: var(--mono); }
#codeText { flex: 1; background: var(--bg); border: 1px solid var(--line-2); border-radius: 6px; padding: 12px; font: 13px/1.6 var(--mono); resize: none; outline: none; }
.code-bar { display: flex; gap: 12px; align-items: center; font-size: 12px; }

/* ---------- task panel ---------- */
.task-info h1 { font-size: 18px; margin: 6px 0 6px; }
.ti-top { display: flex; gap: 6px; }
.badge { font: 10px var(--mono); text-transform: uppercase; letter-spacing: 0.06em; border: 1px solid var(--line-2); border-radius: 20px; padding: 2px 8px; color: var(--dim); }
.badge.ok { color: var(--mint); border-color: var(--mint); }
.ti-desc { color: var(--text-2); }
.ti-desc p { margin: 0 0 8px; }
.ti-desc code { font-family: var(--mono); color: var(--mint); font-size: 12px; }
.ti-goals { margin: 4px 0 12px; padding-left: 18px; color: var(--text-2); }

.next-test:not(:empty) { background: var(--cream); color: #1e2761; border-radius: 6px; padding: 9px 12px; margin: 10px 0; border-left: 4px solid var(--amber); }
.nt-h { font: 700 10px var(--mono); letter-spacing: 0.1em; text-transform: uppercase; color: #6c5a2c; margin-bottom: 2px; }
.nt-h.ok { color: #0b8a6a; }
.nt-fail { color: #b8323c; margin-top: 4px; font-size: 12px; }

/* bench: the cream "hardware" look */
.bench { margin-top: 10px; background: var(--cream); color: #1e2761; border-radius: 8px; padding: 10px; display: flex; flex-direction: column; gap: 10px; }
.scene-wrap { background: #fff; border: 1px solid #d9d2c0; border-radius: 6px; }
.scene-svg { display: block; width: 100%; height: auto; }
.scene-actions { display: flex; gap: 6px; padding: 0 8px 8px; }
.scene-actions .btn { background: #fff; color: #1e2761; border-color: #c9c1ad; }
.sc-lbl { font: 10.5px var(--mono); fill: #1e2761; text-anchor: middle; }
.sc-lbl.l { text-anchor: start; }
.belt { fill: #39425e; }
.belt-dash { stroke: #8a93ad; stroke-width: 2; stroke-dasharray: 6 10; }
.roller { fill: #5b6584; stroke: #2a3150; stroke-width: 2; }
.shaft { stroke: #5b6584; stroke-width: 4; }
.motor-blk rect { fill: #d9dbe5; stroke: #1e2761; stroke-width: 1.5; }
.m-led { fill: #9aa1b8; }
.running .m-led { fill: var(--mint); }
.box-item { fill: #c99a5b; stroke: #8a6532; stroke-width: 1.2; }
.box-tape { stroke: #e8d3a6; stroke-width: 5; }
.bin { fill: none; stroke: #8b93ab; stroke-width: 2; }
.beam { stroke: #e95d67; stroke-width: 1.5; stroke-dasharray: 3 3; opacity: 0.45; }
.pe.on .beam { opacity: 0.9; stroke: var(--mint); }
.pe-head { fill: #1e2761; }
.pe-led { fill: #b6bccd; stroke: #1e2761; stroke-width: 1; }
.pe.on .pe-led, .ls.on .pe-led { fill: var(--mint); }
.barrel { fill: #e1e4ee; stroke: #1e2761; stroke-width: 1.5; }
.piston { fill: #1e2761; }
.rod { fill: #9aa3bd; }
.rod-head { fill: #1e2761; }
.tank { fill: #fff; stroke: #1e2761; stroke-width: 2; }
.water { fill: #6db6ea; }
.lvl { font: 700 14px var(--mono); fill: #1e2761; text-anchor: middle; }
.pipe { fill: none; stroke: #8b93ab; stroke-width: 5; }
.pipe.thin { stroke-width: 3; }
.valve { fill: #d9dbe5; stroke: #1e2761; }
.valve.on { fill: var(--mint); }
.consumer.on .pipe { stroke: #6db6ea; }
.mark { stroke: #1e2761; stroke-width: 1.5; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
.card { background: #fbfaf6; border: 1px solid #c8cbd8; border-radius: 4px; padding: 8px 10px 9px; position: relative; transition: box-shadow 0.2s; }
.card-h { display: flex; justify-content: space-between; align-items: center; font: 10px var(--mono); color: #5a6386; letter-spacing: 0.04em; }
.led { width: 11px; height: 11px; border-radius: 50%; border: 1px solid #5a6386; background: #d4d7e2; }
.led.on { background: var(--mint); box-shadow: 0 0 6px var(--mint); }
.card.out .led.on { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.card-t { font: 700 13px var(--mono); margin: 4px 0 8px; letter-spacing: 0.03em; }
.card.glow { box-shadow: 0 0 0 2px #f5d77a, 0 0 18px rgba(245, 184, 61, 0.75); }
.card-hint { font: 700 9.5px var(--mono); color: #946c12; letter-spacing: 0.06em; text-transform: uppercase; margin-top: 6px; }
.card-hint:empty { display: none; }
.toggle, .push { width: 100%; padding: 9px 6px; border: 2px solid #5a6386; border-radius: 4px; background: #e4e7f0; color: #1e2761; font: 700 12px var(--mono); cursor: pointer; letter-spacing: 0.05em; }
.card.in.active .toggle { background: #1e2761; color: #fff; }
.push { border-radius: 22px; background: #e4e7f0; touch-action: none; user-select: none; }
.push.down { transform: translateY(1px); background: #c9cee0; }
.push.c-green { background: #2fa36b; border-color: #1d6e47; color: #fff; }
.push.c-red { background: #d0434d; border-color: #8b2028; color: #fff; }
.push.c-green.down { background: #237d52; }
.push.c-red.down { background: #a8323b; }
.ctl-push { display: flex; flex-direction: column; gap: 4px; }
.ctl-note { font: 9.5px var(--mono); color: #7a809a; }
.ctl-range { display: flex; gap: 8px; align-items: center; }
.ctl-range input { flex: 1; accent-color: #1e2761; }
.num-out { font: 700 13px var(--mono); min-width: 32px; text-align: right; }
.vis { height: 44px; display: flex; align-items: center; justify-content: center; }
.vis.lamp { width: 40px; height: 40px; border-radius: 50%; background: #2a3150; border: 4px solid #5a6386; margin: 0 auto; transition: background 0.1s; }
.card.active .vis.lamp { background: #ffd447; box-shadow: 0 0 22px #ffd447; border-color: #c79a12; }
.card.active .vis.lamp.c-green { background: #3ddc84; box-shadow: 0 0 22px #3ddc84; border-color: #1d8a4f; }
.card.active .vis.lamp.c-red { background: #ff4f5e; box-shadow: 0 0 22px #ff4f5e; border-color: #a82431; }
.card.active .vis.lamp.c-orange { background: #ff9d2e; box-shadow: 0 0 22px #ff9d2e; border-color: #b0630b; }
.card.active .vis.lamp.horn { animation: pulse 0.4s infinite alternate; }
@keyframes pulse { to { opacity: 0.55; } }
.motor svg { width: 44px; height: 44px; }
.m-body { fill: #e4e7f0; stroke: #1e2761; stroke-width: 2; }
.fan path { fill: #5a6386; }
.m-hub { fill: #1e2761; }
.card.active .fan { animation: spin 0.6s linear infinite; }
.card.active .fan path { fill: #0b8a6a; }
@keyframes spin { to { transform: rotate(360deg); } }
.display { font: 700 22px var(--mono); }

/* checks */
.checks { margin-top: 14px; }
.ck-h { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ck-h b { margin-right: auto; }
.ck-done { background: var(--mint-soft); border: 1px solid var(--mint); color: var(--mint); border-radius: 6px; padding: 8px 10px; margin-bottom: 8px; }
.ck-list { list-style: none; margin: 0; padding: 0; counter-reset: ck; }
.ck { display: flex; gap: 8px; padding: 5px 0; border-bottom: 1px solid var(--line); color: var(--text-2); counter-increment: ck; }
.ck-i { flex: none; width: 18px; height: 18px; border-radius: 50%; border: 1px solid var(--line-2); font: 10px/16px var(--mono); text-align: center; color: var(--dim); }
.ck-i::before { content: counter(ck); }
.ck.ok .ck-i { background: var(--mint); border-color: var(--mint); color: #062a22; }
.ck.ok .ck-i::before { content: "✓"; }
.ck.fail .ck-i { background: var(--coral); border-color: var(--coral); color: #fff; }
.ck.fail .ck-i::before { content: "✗"; }
.ck.cur .ck-i { border-color: var(--amber); color: var(--amber); }
.ck.cur { color: var(--text); }
.ck.skip { opacity: 0.5; }
.ck-t em { display: block; font-style: normal; color: var(--coral); font-size: 12px; }
.sol { margin-top: 10px; }

/* I/O panel */
.io-g { font: 11px var(--mono); color: var(--dim); text-transform: uppercase; margin: 12px 0 4px; }
.io-g:first-child { margin-top: 0; }
.io-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px solid var(--line); font-family: var(--mono); font-size: 12px; }
.io-n { flex: 1; }
.io-a { color: var(--dim); font-size: 11px; }
.sw { width: 34px; height: 18px; border-radius: 10px; background: var(--line-2); border: 0; position: relative; cursor: pointer; }
.sw::after { content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--sym); transition: left 0.1s; }
.sw.on { background: var(--mint); }
.sw.on::after { left: 18px; background: #fff; }
.iv { color: var(--amber); font-size: 11px; min-width: 50px; text-align: right; }
.iv.on { color: var(--mint); }

@media (max-width: 1100px) {
  .layout { grid-template-columns: 170px minmax(0, 1fr) var(--side-w); }
}
@media (max-width: 820px) {
  body { overflow: auto; }
  .layout { display: flex; flex-direction: column; height: auto; }
  .lib { max-height: 180px; }
  .center { height: 70vh; }
  .brand-t { display: none; }
}

/* ---------- tag picker ---------- */
.argzone { cursor: text; }
.argzone .az { fill: transparent; }
.argzone:hover .az { fill: rgba(18, 209, 163, 0.12); }
.box .pin, .box .arg, .box .val { pointer-events: none; }
.picker { position: fixed; z-index: 50; width: 300px; background: var(--panel-2); border: 1px solid var(--mint); border-radius: 8px; box-shadow: 0 12px 32px var(--shadow); padding: 8px; }
.pk-h { font-size: 12px; color: var(--dim); margin-bottom: 6px; }
.pk-h b { font-family: var(--mono); color: var(--mint); margin-right: 4px; }
.pk-in { width: 100%; background: var(--bg); border: 1px solid var(--line-2); border-radius: 5px; padding: 6px 9px; font: 13px var(--mono); outline: none; }
.pk-in:focus { border-color: var(--mint); }
.pk-list { list-style: none; margin: 6px 0 0; padding: 0; max-height: 240px; overflow: auto; }
.pk-list li { display: flex; justify-content: space-between; gap: 10px; padding: 5px 8px; border-radius: 4px; cursor: pointer; }
.pk-list li:hover, .pk-list li.on { background: var(--mint-soft); }
.pk-list li.on { box-shadow: inset 2px 0 var(--mint); }
.pk-n { font: 12.5px var(--mono); white-space: nowrap; }
.pk-n b { color: var(--mint); font-weight: 700; }
.pk-m { font-size: 11px; color: var(--dim); text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-list li.create .pk-n { color: var(--amber); }
.pk-list .pk-empty { color: var(--dim); cursor: default; font-size: 12px; }
.pk-foot { margin-top: 6px; font-size: 10.5px; color: var(--dim); }

/* ---------- drag and drop ---------- */
.pal-b, svg.rung { user-select: none; -webkit-user-select: none; }
.pal-b { touch-action: none; }
body.ld-dragging, body.ld-dragging * { cursor: grabbing !important; }
.slot .slot-hit { fill: transparent; }
.slot circle { fill: var(--bg); stroke: var(--mint); stroke-width: 1.5; }
.slot path { stroke: var(--mint); stroke-width: 1.6; }
.slot.over circle { fill: var(--mint); r: 9; filter: drop-shadow(0 0 6px rgba(18, 209, 163, 0.8)); }
.slot.over path { stroke: #062a22; }
.ph.slot-ph rect { stroke: var(--mint); }
.ph.slot-ph text { fill: var(--mint); }
.ph.slot-ph.over rect { fill: var(--mint-soft); stroke-dasharray: none; }
.slot-rung { flex: 1; margin-right: 20px; border: 1.5px dashed var(--mint); border-radius: 6px; padding: 10px; color: var(--mint); text-align: center; }
.slot-rung.over { background: var(--mint-soft); border-style: solid; }
.drag-ghost { position: fixed; z-index: 60; pointer-events: none; background: var(--mint); color: #062a22; font: 700 12px var(--mono); padding: 4px 9px; border-radius: 5px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.45); }

.toast { position: absolute; left: 50%; bottom: 84px; transform: translate(-50%, 12px); max-width: 90%; background: var(--cream); color: #1e2761; border-left: 4px solid var(--coral); border-radius: 6px; padding: 9px 14px; font-size: 13px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.45); opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 40; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- PLC front panel ---------- */
.plc { display: flex; gap: 14px; align-items: center; background: #2a3147; border-radius: 6px; padding: 10px 12px; }
.plc-svg { width: 180px; flex: none; height: auto; display: block; filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.35)); }
.plc-micro850 { flex-direction: column; align-items: stretch; gap: 6px; background: #d5d9de; }
.plc-model { width: 100%; }
.plc-micro850 .run-switch { cursor: pointer; }
.plc-micro850 .plc-svg { width: 100%; height: auto; max-width: 620px; margin: 0 auto; filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.25)); }
.plc-micro850 .plc-info { flex-direction: row; align-items: baseline; gap: 12px; color: #3b4652; flex-wrap: wrap; }
.plc-micro850 .plc-state { font-size: 14px; color: #a06c00; }
.plc-micro850.run .plc-state { color: #1f8a3c; }
.plc-micro850 .plc-msg { color: #c0303a; }
.plc-info { display: flex; flex-direction: column; gap: 4px; color: #c9d1e8; font: 11px var(--mono); min-width: 0; }
.plc-state { font: 700 18px var(--mono); color: #f5c400; letter-spacing: 0.06em; }
.plc.run .plc-state { color: #39d353; }
.plc-msg { color: #ff8a8f; white-space: normal; }
.plc-msg:empty { display: none; }
.vent { fill: #6a747e; }
.pt { font: 6.2px var(--sans); fill: #e9edf1; }
.pt.sm { font-size: 5.2px; }
.pt.lg { font-size: 9px; }
.badge-t { font: 700 7.2px var(--sans); fill: #fff; letter-spacing: 0.04em; }
.nfc { fill: none; stroke: #e9edf1; stroke-width: 1; }
.pled { fill: #353c43; stroke: #23292e; stroke-width: 0.5; }
.pled.green { fill: #39d353; filter: drop-shadow(0 0 2px #39d353); }
.pled.yellow { fill: #f5c400; filter: drop-shadow(0 0 2px #f5c400); }
.pled.red { fill: #ff3b3b; filter: drop-shadow(0 0 2px #ff3b3b); }
.pled.blink { animation: pledBlink 0.5s steps(1) infinite; }
@keyframes pledBlink { 50% { fill: #353c43; filter: none; } }

/* ---------- program sheets (tabs under the diagram) ---------- */
.ladder { position: relative; }
.sheets { flex: none; display: flex; align-items: stretch; gap: 2px; padding: 0 10px; background: var(--panel); border-top: 1px solid var(--line); overflow-x: auto; }
.sheet-tab { display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 12px; border: 1px solid transparent; border-top: 0; border-radius: 0 0 6px 6px; color: var(--dim); cursor: pointer; white-space: nowrap; font-size: 12.5px; margin-top: -1px; }
.sheet-tab:hover { color: var(--text); }
.sheet-tab.on { background: var(--bg); color: var(--text); border-color: var(--line); box-shadow: inset 0 2px var(--mint); }
.sheet-tab.sol { color: var(--amber); }
.sheet-tab.sol.on { box-shadow: inset 0 2px var(--amber); }
.sheet-x { background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1; border-radius: 3px; opacity: 0; }
.sheet-tab:hover .sheet-x, .sheet-tab.on .sheet-x { opacity: 1; }
.sheet-x:hover { color: var(--coral); background: var(--panel-2); }
.sheet-add { background: none; border: 0; color: var(--dim); font-size: 16px; padding: 0 12px; cursor: pointer; }
.sheet-add:hover { color: var(--mint); }
.sheet-rename { width: 120px; margin: 3px 0; background: var(--bg); border: 1px solid var(--mint); border-radius: 4px; padding: 2px 6px; font-size: 12.5px; outline: none; }
body.readonly-sheet .palette { opacity: 0.4; pointer-events: none; }
body.readonly-sheet .ladder { box-shadow: inset 0 0 0 2px rgba(245, 184, 61, 0.35); }
.ck-done.ref { background: rgba(245, 184, 61, 0.12); border-color: var(--amber); color: var(--amber); }

/* ---------- rung comment, edited in place ---------- */
.cbtn { font: 700 11px var(--mono); fill: var(--dim); text-anchor: middle; cursor: pointer; opacity: 0; }
svg.rung:hover .cbtn, .rung-bg.sel ~ .cbtn { opacity: 1; }
.cbtn:hover { fill: var(--mint); }
.com { cursor: text; }
.com:hover { fill: var(--mint); }
.comment-edit { position: absolute; left: 50px; width: min(640px, calc(100% - 70px)); height: 22px; z-index: 20; background: var(--bg); border: 1px solid var(--mint); border-radius: 4px; padding: 2px 8px; font: 12px var(--mono); color: var(--text); outline: none; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35); }

/* ---------- theme switch ---------- */
.theme-switch { display: inline-flex; border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 6px; overflow: hidden; }
.theme-switch button { background: transparent; border: 0; color: #9aa6c4; padding: 5px 10px; cursor: pointer; font-size: 12.5px; white-space: nowrap; }
.theme-switch button + button { border-left: 1px solid rgba(255, 255, 255, 0.22); }
.theme-switch button:hover { color: #fff; }
.theme-switch button.on { background: var(--mint); color: #062a22; font-weight: 600; }
.top .btn.ghost { color: #dbe3f1; border-color: rgba(255, 255, 255, 0.22); }
.top .btn.ghost:hover { border-color: var(--mint); }
.top .btn.ghost:disabled { border-color: rgba(255, 255, 255, 0.12); }
.top .scan-info { color: #9aa6c4; }
:root[data-theme="light"] .tabs button.on { color: var(--text); }
:root[data-theme="light"] .lib-item.on { background: var(--mint-soft); }
:root[data-theme="light"] .rail { stroke: #6f7b95; }
:root[data-theme="light"] .rail.on, :root[data-theme="light"] .w.on { stroke: var(--power); }
:root[data-theme="light"] .val { fill: #b26b00; }
:root[data-theme="light"] .tv, :root[data-theme="light"] .iv { color: #b26b00; }
:root[data-theme="light"] .el.sel .hit, :root[data-theme="light"] .pg.sel .hit { stroke: #d08a00; }
:root[data-theme="light"] .brand-t { color: #aeb6d6; }
:root[data-theme="light"] .brand-t b { color: #fff; }

/* Narrow windows: keep every top-bar control visible. */
@media (max-width: 1180px) {
  .brand-t { display: none; }
  .scan-info { min-width: 0; }
  .top { gap: 10px; }
}
@media (max-width: 900px) {
  .scan-info { display: none; }
  .theme-switch button { padding: 5px 7px; }
}

/* ---------- settings menu ---------- */
.settings { position: relative; }
#btnSettings.on { border-color: var(--mint); color: #fff; }
.settings-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 70; min-width: 260px; background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-radius: 8px; box-shadow: 0 14px 34px var(--shadow); padding: 10px 12px; }
.settings-menu::before { content: ""; position: absolute; right: 22px; top: -6px; width: 10px; height: 10px; background: var(--panel); border-left: 1px solid var(--line-2); border-top: 1px solid var(--line-2); transform: rotate(45deg); }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 4px 0; }
.set-label { font-size: 12.5px; color: var(--dim); }
.settings-menu .theme-switch { border-color: var(--line-2); }
.settings-menu .theme-switch button { color: var(--dim); }
.settings-menu .theme-switch button + button { border-left-color: var(--line-2); }
.settings-menu .theme-switch button:hover { color: var(--text); }
.settings-menu .theme-switch button.on { color: #062a22; }

/* ---------- cookie consent bar ---------- */
.cookie-bar { position: fixed; left: 16px; bottom: 16px; z-index: 80; max-width: 460px; background: var(--panel); color: var(--text); border: 1px solid var(--line-2); border-left: 4px solid var(--mint); border-radius: 8px; padding: 12px 14px; box-shadow: 0 14px 34px var(--shadow); font-size: 12.5px; }
.cookie-bar p { margin: 0 0 10px; color: var(--text-2); }
.cookie-actions { display: flex; gap: 8px; }

/* ---------- account ---------- */
.account-btn.signed { border-color: rgba(18, 209, 163, 0.5); color: #fff; }
