/* PLC Trainer — base styles. The tokens and component shapes in use are set by "Design system v3" at the end of this file (docs/DESIGN_SYSTEM.md). */
:root {
  --bg: #F3F0E8;
  --surface: #FBFAF6;
  --surface-2: #F0ECE2;
  --surface-3: #E8E3D7;
  --border: #E2DCCE;
  --border-strong: #CBC2AF;
  --text: #29261F;
  --muted: #7A746A;
  --accent: #D97757;
  --accent-strong: #BE5D3B;
  --accent-text: #B4532F;
  --accent-soft: #F6E4DA;
  --ok: #2F9E57;
  --warn: #C98A12;
  --danger: #CF4436;
  --lad-bg: #FFFFFF;
  --lad-wire: #4a463e;
  --lad-on: #1FA34A;
  --lad-hl: #C9F0D3;
  --lad-text: #2b2822;
  --canvas: #EDE9DF;
  --grid-dot: #CFC6B4;
  --grid-line: #E2DBCB;
  --wire-halo: rgba(40, 30, 10, .28);
  --shadow: 0 1px 2px rgba(60, 45, 20, .06), 0 4px 16px rgba(60, 45, 20, .06);
  --shadow-lg: 0 10px 40px rgba(40, 30, 10, .18);
  --sans: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --serif: 'Source Serif 4', Georgia, 'Times New Roman', serif;
  --mono: 'JetBrains Mono', ui-monospace, 'SFMono-Regular', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1E1D1A; --surface: #282723; --surface-2: #302F2A; --surface-3: #3A3832; --border: #3B3933; --border-strong: #514E46;
    --text: #EEEAE1; --muted: #A49E92; --accent-soft: #4A2E24; --lad-bg: #22211D; --lad-wire: #BDB7AA; --lad-on: #3DD16C; --lad-hl: #1E4A2C; --lad-text: #E9E4D8;
    --canvas: #23221E; --grid-dot: #3E3B34; --grid-line: #2D2B26; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
    --wire-halo: rgba(236, 230, 216, .62);
    --accent-text: #F2A385;
  }
}
:root[data-theme="dark"] {
  --bg: #1E1D1A; --surface: #282723; --surface-2: #302F2A; --surface-3: #3A3832; --border: #3B3933; --border-strong: #514E46;
  --text: #EEEAE1; --muted: #A49E92; --accent-soft: #4A2E24; --lad-bg: #22211D; --lad-wire: #BDB7AA; --lad-on: #3DD16C; --lad-hl: #1E4A2C; --lad-text: #E9E4D8;
  --canvas: #23221E; --grid-dot: #3E3B34; --grid-line: #2D2B26; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 16px rgba(0,0,0,.25); color-scheme: dark;
  --wire-halo: rgba(236, 230, 216, .62);
  --accent-text: #F2A385;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 var(--sans); display: flex; flex-direction: column; overflow: hidden; -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 7px 9px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
code, kbd, pre { font-family: var(--mono); font-size: .92em; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
kbd { border: 1px solid var(--border-strong); border-bottom-width: 2px; padding: 0 5px; border-radius: 4px; background: var(--surface); }
pre { background: var(--surface-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: 10px; overflow: auto; }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; gap: 18px; padding: 8px 16px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.logo { width: 32px; height: 32px; }
.brand-title { font-family: var(--serif); font-size: 20px; font-weight: 600; letter-spacing: -.01em; line-height: 1.1; }
.brand-sub { font-size: 12px; color: var(--muted); }
.save-st { font-size: 10.5px; padding: 0 6px; border-radius: 8px; margin-left: 4px; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.save-st.saved::before { content: '✓ '; color: var(--ok); }
.save-st.pending { color: var(--warn); }
.save-st.failed { background: var(--danger); color: #fff; }
.update-bar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: center; padding: 6px 12px; background: var(--accent-soft); border-bottom: 1px solid var(--accent); font-size: 13px; }
.update-bar .btn { padding: 4px 12px; }
.beta-tag { display: inline-block; padding: 0 6px; border-radius: 6px; background: var(--warn); color: #fff; font-size: 10px; font-weight: 700; letter-spacing: .05em; }
label.radio { display: flex; gap: 8px; align-items: baseline; margin: 6px 0; font-size: 13px; cursor: pointer; }
.rel-notes { max-height: 55vh; overflow: auto; }
.rel-notes h4 { margin: 12px 0 4px; }
.rel-notes li { margin-left: 18px; }
.rel-notes p { margin: 4px 0; }
.rel-notes .rel-note { padding: 6px 10px; border-left: 3px solid var(--warn); background: var(--surface-2); border-radius: 6px; }
.zoomv.fit { color: var(--accent-text); font-weight: 600; }
.badge { display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 2px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 10px; line-height: 16px; text-align: center; }
.badge[hidden] { display: none; }
.ev-tools { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.ev-tools .spacer { flex: 1; }
.ev-list { max-height: 55vh; overflow: auto; border: 1px solid var(--border); border-radius: 10px; }
.ev-list > .help { padding: 10px; margin: 0; }
table.ev { width: 100%; border-collapse: collapse; font-size: 12.5px; }
table.ev th { position: sticky; top: 0; background: var(--surface-2); text-align: left; font-weight: 600; padding: 6px 10px; }
table.ev td { padding: 5px 10px; border-top: 1px solid var(--border); vertical-align: top; }
table.ev td:first-child { font-family: var(--mono); white-space: nowrap; color: var(--muted); }
.evk { display: inline-block; padding: 0 7px; border-radius: 8px; background: var(--surface-3); font-size: 11px; font-weight: 600; }
tr.k-alarm .evk { background: var(--danger); color: #fff; }
tr.k-mode .evk { background: var(--ok); color: #fff; }
tr.k-force .evk { background: var(--warn); color: #fff; }
tr.k-operator .evk { background: var(--accent-soft); color: var(--accent-text); }
.tabs { display: flex; gap: 2px; background: var(--surface-2); padding: 3px; border-radius: 12px; border: 1px solid var(--border); flex-wrap: wrap; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 9px; color: var(--muted); font-weight: 500; display: flex; gap: 7px; align-items: center; }
.tabs button:hover { color: var(--text); }
.tabs button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.tabs .ti { font-size: 12px; color: var(--accent); font-family: var(--mono); }
.top-actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }

.btn { border: 1px solid var(--border-strong); background: var(--surface); padding: 7px 14px; border-radius: 9px; font-weight: 500; }
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-strong); }
.btn.danger { color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn:disabled { opacity: .45; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 8px; font-size: 18px; color: var(--muted); }
.icon-btn.lang-btn { font: 700 12px var(--mono); width: 36px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.tbtn { border: 1px solid var(--border); background: var(--surface); padding: 5px 9px; border-radius: 8px; font-size: 13px; line-height: 1.2; white-space: nowrap; }
.tbtn:hover { border-color: var(--border-strong); background: var(--surface-2); }
.tbtn.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-text); font-weight: 600; }
.tbtn.sm { padding: 3px 8px; font-size: 12px; }
.tbtn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.tbtn.warn { background: #f8e2a8; border-color: #e5c066; color: #6c4b00; }
.tbtn:disabled { opacity: .45; }
.seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: 9px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: transparent; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #fff; }
.spacer { flex: 1; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }

/* ---------- PLC status bar ---------- */
.plcbar { display: flex; align-items: center; gap: 14px; padding: 6px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); font-size: 12px; flex-wrap: wrap; }
.plcbar .mode button { padding: 4px 14px; letter-spacing: .04em; }
/* one line: the I/O lights and the message give way (clipped) before Events / View wrap to a second line */
.plcbar { flex-wrap: nowrap; }
.plcbar > * { flex-shrink: 0; }
.plcbar .io-strip { flex-shrink: 1; min-width: 0; overflow: hidden; white-space: nowrap; }
.plcbar .bar-msg { flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the connection chip gives way before the bar overflows: it keeps its start (OFFLINE / ONLINE) and the title has the rest */
.plcbar .conn-chip { flex-shrink: 2; min-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plcbar .mode button[data-mode="RUN"].on { background: var(--ok); }
.leds { display: flex; gap: 10px; }
.led { display: inline-flex; align-items: center; gap: 5px; font-weight: 600; font-size: 11px; color: var(--muted); letter-spacing: .03em; }
.led::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: #8d877b; opacity: .35; }
.led.on::before { background: #29c15a; opacity: 1; box-shadow: 0 0 6px #29c15a; }
.led.amber.on::before { background: #f2b630; box-shadow: 0 0 6px #f2b630; }
.led.red.on::before { background: #ef4b3a; box-shadow: 0 0 6px #ef4b3a; }
.io-strip { display: flex; align-items: center; gap: 3px; font-family: var(--mono); }
.io-strip .iol { color: var(--muted); margin: 0 3px 0 6px; font-size: 11px; }
.io-strip i { width: 9px; height: 13px; border-radius: 2px; background: var(--surface-3); border: 1px solid var(--border-strong); }
.io-strip i.on.in { background: #f2c230; border-color: #b78d12; }
.io-strip i.on.out { background: #ff8a3a; border-color: #c25a14; }
.io-strip i.f { outline: 2px solid #f2b630; outline-offset: 1px; }
.scan { color: var(--muted); font-family: var(--mono); }
.bar-msg { color: var(--muted); flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-msg.warn { color: var(--danger); font-weight: 600; }
.blink { animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: .25; } }

/* ---------- main / views ---------- */
#main { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr); grid-template-areas: "a"; }
/* several views at once: ladder on the left, the others stacked on the right */
#main.panes-2 { grid-template-columns: var(--c1, 50%) 6px minmax(0, 1fr); grid-template-areas: "a gv b"; }
#main.panes-3 { grid-template-columns: var(--c1, 46%) 6px minmax(0, 1fr); grid-template-rows: var(--r1, 60%) 6px minmax(0, 1fr); grid-template-areas: "a gv b" "a gv gh" "a gv c"; }
.view { display: none; min-height: 0; min-width: 0; overflow: hidden; }
.view.active { display: flex; flex-direction: column; }
#main.multi .view { position: relative; }
#main.multi .view.focus { box-shadow: inset 0 2px 0 var(--accent); }
.gutter { display: none; background: var(--border); touch-action: none; }
#main.multi .gv { display: block; grid-area: gv; cursor: col-resize; }
#main.panes-3 .gh { display: block; grid-area: gh; cursor: row-resize; }
.gutter:hover, .gutter.drag { background: var(--accent); }
.tabs button.shown:not(.on) { color: var(--text); background: color-mix(in srgb, var(--surface) 55%, transparent); }
.side-head { display: flex; align-items: center; gap: 6px; padding: 10px 12px 6px; }
.side-head h4 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); flex: 1; }
.side-head .count { background: var(--surface-3); border-radius: 10px; padding: 0 7px; font-size: 11px; }
.help { color: var(--muted); font-size: 12.5px; }
.warn-txt { color: var(--warn); }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 10px; font-size: 12.5px; }
.field > span { color: var(--muted); font-weight: 500; }
.field small { color: var(--muted); }
.form-err { color: var(--danger); font-weight: 500; min-height: 1em; }

/* ---------- ladder ---------- */
.lad-toolbar { display: flex; gap: 6px; padding: 8px 12px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; align-items: flex-end; }
.tb-group { display: flex; gap: 3px; align-items: center; padding: 2px 8px 2px 6px; border-right: 1px solid var(--border); flex-wrap: wrap; }
.tb-group:last-child { border-right: 0; }
.tb-lbl { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-right: 4px; writing-mode: horizontal-tb; }
.tb-addr { display: inline-flex; align-items: center; gap: 2px; margin-left: 4px; }
.tb-addr select { font-size: 12px; padding: 3px 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
/* status box, path and tabbed instruction palette (the layout of PLC programming software) */
.lad-status { display: grid; grid-template-columns: auto auto; grid-template-rows: auto auto; gap: 2px 8px; align-items: center; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2, var(--bg)); margin-right: 4px; }
.lad-stat-btn { grid-row: 1; grid-column: 1 / 3; display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 150px; font: 600 12.5px var(--sans, inherit); padding: 3px 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); cursor: pointer; }
.lad-stat-btn .caret { color: var(--muted); font-size: 10px; }
.lad-status.online .lad-stat-btn { border-color: #3d9a50; }
.lad-status.run .lad-stat-btn { background: color-mix(in srgb, #3ddc63 18%, var(--surface)); }
.lad-stat-lines { display: flex; flex-direction: column; font-size: 10.5px; color: var(--muted); line-height: 1.25; }
.lad-leds { display: grid; grid-template-columns: auto auto; gap: 0 8px; font: 600 9.5px var(--mono); color: var(--muted); }
.lad-leds span { display: inline-flex; align-items: center; gap: 3px; }
.lad-leds i { width: 7px; height: 7px; border-radius: 2px; background: #9a978f; display: inline-block; }
.lad-leds .on i { background: #2fbf55; box-shadow: 0 0 4px #3ddc63; }
.lad-leds .bad i { background: #e5392c; box-shadow: 0 0 4px #ff4b3a; }
.lad-leds .blink i { animation: ledBlink 1s steps(2) infinite; }
@keyframes ledBlink { 50% { opacity: .25; } }
.lad-pathbox { flex-direction: column; align-items: flex-start; gap: 1px; max-width: 260px; }
.lad-path { font-size: 11.5px; font-family: var(--mono); color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 250px; }
.lad-ins { flex-direction: column; align-items: stretch; gap: 0; padding: 0 6px; }
.ins-row { display: flex; gap: 2px; min-height: 30px; align-items: center; padding: 2px 4px; border: 1px solid var(--border); border-bottom: 0; border-radius: 5px 5px 0 0; background: var(--surface-2, var(--bg)); flex-wrap: wrap; }
.ins-btn { display: none; align-items: center; justify-content: center; height: 26px; min-width: 32px; padding: 0 5px; border-radius: 3px; border: 1px solid transparent; background: transparent; }
.ins-btn.show { display: inline-flex; }
.ins-btn:hover { border-color: var(--border); background: var(--surface); }
.ins-btn .mono { font-size: 11.5px; color: var(--lad-text); font-weight: 700; letter-spacing: -.05em; font-family: var(--mono); }
.ins-btn .boxico { font-size: 9.5px; font-weight: 700; font-family: var(--mono); border: 1.5px solid var(--lad-wire); padding: 0 3px; border-radius: 2px; line-height: 14px; }
.ins-btn small { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.ins-tabs { display: flex; gap: 0; border-top: 1px solid var(--border); flex-wrap: wrap; }
.ins-tab { font-size: 10.5px; padding: 2px 8px 3px; border: 1px solid var(--border); border-top: 0; margin-right: -1px; background: var(--surface); color: var(--muted); border-radius: 0 0 5px 5px; cursor: pointer; }
.ins-tab.on { background: var(--surface-2, var(--bg)); color: var(--text); font-weight: 600; position: relative; top: -1px; border-top: 1px solid var(--surface-2, var(--bg)); }
.lad-main { flex: 1; min-height: 0; display: flex; position: relative; }
/* Organizer docked on the left of the ladder, as in the programming software */
.lad-org { width: 250px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); overflow: auto; font-size: 12.5px; }
.lad-org[hidden] { display: none; }
.lad-org .org { font-size: 12.5px; line-height: 1.75; padding: 0 10px 0 6px; }
.lad-org .org ul { padding-left: 14px; }
.lad-org .io-cfg { margin: 0 10px; font-size: 12px; }
.lad-org h5 { margin: 10px 12px 4px; }
.org-path { margin: 0 12px 6px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 11.5px; color: var(--muted); background: var(--surface-2, var(--surface)); }
.org-path b { color: var(--text); font-weight: 600; }
.org .flt { color: var(--warn); font-size: 11.5px; }
.org-act { margin-left: 4px; opacity: .55; }
.org-act a { text-decoration: none; margin-left: 4px; font-size: 11px; }
.org li:hover > .org-act { opacity: 1; }
.org-add { font-size: 12px; color: var(--accent); }
/* online bar: LED stack, key switch, mode box with the path, forces / edits boxes */
.lad-status { display: flex !important; align-items: center; gap: 8px; }
.lad-status .lad-leds { display: flex; flex-direction: column; gap: 0; }
.lad-key { color: var(--muted); display: inline-flex; transform: rotate(-30deg); transition: transform .2s; }
.lad-key[data-pos="run"] { transform: rotate(30deg); color: var(--text); }
.lad-stat-mid { display: flex; flex-direction: column; gap: 3px; }
.lad-stat-lines { display: flex; flex-direction: column; gap: 3px; }
.st-box { border: 1px solid var(--border); background: var(--surface); padding: 1px 6px; border-radius: 3px; font-size: 10.5px; color: var(--muted); white-space: nowrap; }
/* Errors pane under the ladder */
.lad-out { border-top: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.lad-out-head { display: flex; align-items: center; gap: 4px; padding: 2px 8px; font-size: 11px; }
.lad-out .oc { font-size: 11px; padding: 1px 8px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2, var(--bg)); color: var(--text); cursor: pointer; }
.lad-out .oc.e::before { content: '⛔ '; } .lad-out .oc.w::before { content: '⚠ '; } .lad-out .oc.m::before { content: 'ℹ '; }
.lad-out .oc.off { opacity: .45; }
.lad-rungpos { margin-left: auto; color: var(--muted); font-family: var(--mono); }
.oc-tog { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; }
.lad-out-log { display: none; margin: 0; max-height: 110px; overflow: auto; padding: 4px 10px 6px; font: 11.5px/1.45 var(--mono); color: var(--text); white-space: pre-wrap; }
.lad-out.open .lad-out-log { display: block; }
.rung.empty .rung-num::before { content: '⊗ '; color: #e5392c; font-weight: 700; }
/* Who Active, Download, Select Module Type */
.who-grid { display: grid; grid-template-columns: 1fr auto; gap: 12px; }
.who-tree { border: 1px solid var(--border); border-radius: 6px; padding: 6px; min-height: 140px; max-height: 320px; overflow: auto; background: var(--surface-2, var(--bg)); }
.who-acts { display: flex; flex-direction: column; gap: 6px; min-width: 120px; }
.who-acts .btn:disabled, .who-pbtn .btn:disabled { opacity: .45; }
.who-path { margin-top: 10px; font-size: 12.5px; display: grid; gap: 4px; }
.who-pbtn { display: flex; gap: 6px; margin-top: 4px; }
.who .who-ctl.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); border-radius: 4px; }
.dl-warn { border-left: 4px solid #e0a21f; padding: 6px 10px; background: color-mix(in srgb, #e0a21f 12%, transparent); font-size: 12.5px; }
.dl-danger { border-left: 4px solid #e5392c; padding: 6px 10px; background: color-mix(in srgb, #e5392c 10%, transparent); font-size: 12.5px; }
.mod-search { width: 100%; box-sizing: border-box; padding: 6px 8px; margin-bottom: 8px; border: 1px solid var(--border); border-radius: 6px; background: var(--surface); color: var(--text); }
.mod-cat tr[data-mt] { cursor: pointer; }
.mod-cat tr.sel td { background: color-mix(in srgb, var(--accent) 18%, transparent); }
.tag-tabs { display: flex; margin: -4px 0 10px; border-bottom: 1px solid var(--border); }
.tag-tabs .ins-tab { border-radius: 5px 5px 0 0; border-top: 1px solid var(--border); border-bottom: 0; font-size: 12px; padding: 4px 12px; }
.tag-tabs .ins-tab.on { top: 1px; border-bottom: 1px solid var(--surface-2, var(--bg)); }
.tag-grid input, .tag-grid select { width: 100%; box-sizing: border-box; font: 12.5px var(--mono); padding: 3px 5px; border: 1px solid var(--border); border-radius: 3px; background: var(--surface); color: var(--text); }
.tag-grid input:disabled { background: transparent; border-color: transparent; color: var(--muted); }
.lad-rungs { flex: 1; min-width: 0; overflow: auto; background: var(--lad-bg); padding: 10px 0 60px; outline: none; position: relative; }
.lad-rungs.dragging, .lad-rungs.dragging * { cursor: grabbing !important; }
.lad-rungs .el[data-uid] { cursor: grab; }
.rung-svg .el.dragged { opacity: .35; }
.lad-drop { position: absolute; background: var(--accent); border-radius: 2px; pointer-events: none; z-index: 5; }
.lad-drop.area { background: color-mix(in srgb, var(--accent) 14%, transparent); outline: 2px dashed var(--accent); }
.lad-ghost { position: fixed; z-index: 60; pointer-events: none; background: var(--accent); color: #fff; font: 600 12px var(--mono); padding: 3px 8px; border-radius: 6px; box-shadow: var(--shadow); }
.zoomv.tbtn { min-width: 52px; text-align: center; }
.lad-side { width: 330px; flex-shrink: 0; border-left: 1px solid var(--border); background: var(--surface); overflow: auto; }
.rung { display: flex; align-items: stretch; border-left: 3px solid transparent; }
.rung.sel { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); border-left-color: var(--accent); }
.rung.has-err .rung-num { color: var(--danger); }
.rung-num { width: 56px; flex-shrink: 0; font-family: var(--mono); font-size: 12px; color: var(--muted); padding: 50px 6px 0 10px; cursor: pointer; user-select: none; }
.rung.end .rung-num { padding-top: 10px; }
.rung-body { flex: 1; min-width: 0; }
.rung-comment { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 13px; padding: 8px 6px 0; max-width: 900px; }
.rung-svg { display: block; overflow: visible; user-select: none; }
.rung-svg .rail { stroke: var(--lad-wire); stroke-width: 2.5; }
.lad-rungs.live .rung-svg .rail, .lad-rungs.live .rung.end .rail { stroke: #2fbf55; }
.rung-svg .alias { font: 10px var(--mono); fill: var(--muted); text-anchor: middle; }
.st-box.bad { color: #fff; background: #d9342b; border-color: #a52019; }
.rung-svg .w { stroke: var(--lad-wire); stroke-width: 1.6; }
.rung-svg .w.on { stroke: var(--lad-on); stroke-width: 2.6; }
.rung-svg .w.stub { stroke-width: 1.2; }
.rung-svg .sym { fill: none; stroke: var(--lad-wire); stroke-width: 2; }
.rung-svg .ins.on .sym { stroke: var(--lad-on); stroke-width: 2.6; }
.rung-svg .hlr { fill: transparent; }
.rung-svg .ins.on .hlr { fill: var(--lad-hl); }
.rung-svg .clbl { font: 700 10px var(--mono); fill: var(--lad-text); text-anchor: middle; }
.rung-svg .clbl.sm { font-size: 7.5px; }
.rung-svg .addr { font: 600 11.5px var(--mono); fill: var(--lad-text); text-anchor: middle; }
.rung-svg .addr.bad { fill: var(--danger); }
.rung-svg .desc { font: 500 10px var(--sans); fill: var(--muted); text-anchor: middle; text-transform: uppercase; letter-spacing: .02em; }
.rung-svg .fbadge { font: 700 9px var(--mono); fill: #b77800; text-anchor: middle; }
.rung-svg .hit { fill: transparent; stroke: transparent; }
.rung-svg .el:hover > .hit, .rung-svg .leg:hover > .hit, .rung-svg .br:hover > .hit { fill: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.rung-svg .el.sel > .hit, .rung-svg .leg.sel > .hit, .rung-svg .br.sel > .hit { fill: color-mix(in srgb, var(--accent-soft) 85%, transparent); stroke: var(--accent); stroke-dasharray: 4 3; }
.rung-svg .el.err > .hit { stroke: var(--danger); fill: rgba(207, 68, 54, .08); }
.rung-svg .boxr { fill: var(--lad-bg); stroke: var(--lad-wire); stroke-width: 1.6; }
.rung-svg .box.on .boxr { stroke: var(--lad-on); stroke-width: 2.4; fill: color-mix(in srgb, var(--lad-hl) 45%, var(--lad-bg)); }
.rung-svg .btitle { font: 700 12px var(--mono); fill: var(--lad-text); }
.rung-svg .bsub { font: 500 10.5px var(--sans); fill: var(--muted); }
.rung-svg .bname { font: 500 10.5px var(--sans); fill: var(--lad-text); }
.rung-svg .baddr { font: 600 10.5px var(--mono); fill: var(--lad-text); }
.rung-svg .bval { font: 600 10.5px var(--mono); fill: var(--accent-text); text-anchor: end; }
.rung-svg .bval.bad { fill: var(--danger); }
.rung-svg .bitind rect { fill: var(--lad-bg); stroke: var(--lad-wire); stroke-width: 1.4; }
.rung-svg .bitind text { font: 700 9px var(--mono); fill: var(--lad-text); text-anchor: middle; }
.rung-svg .bitind.on rect { fill: var(--lad-on); stroke: var(--lad-on); }
.rung-svg .bitind.on text { fill: #fff; }
.rung-svg .hint { font: italic 12px var(--serif); fill: var(--muted); text-anchor: middle; }
.rung-svg .endt { font: 700 12px var(--mono); fill: var(--muted); text-anchor: middle; }

/* data table */
.dt-tabs { display: flex; gap: 3px; padding: 0 12px 8px; flex-wrap: wrap; }
.dt-tabs button { border: 1px solid var(--border); background: var(--surface); padding: 3px 9px; border-radius: 7px; font: 600 12px var(--mono); }
.dt-tabs button.on { background: var(--text); color: var(--surface); border-color: var(--text); }
.dt-body { padding: 0 12px; overflow-x: auto; }
table.dt { border-collapse: collapse; font: 11px var(--mono); width: 100%; }
table.dt th { color: var(--muted); font-weight: 600; padding: 2px 2px; text-align: center; }
table.dt th.rowh { text-align: left; padding-right: 6px; white-space: nowrap; }
table.dt td { border: 1px solid var(--border); text-align: center; padding: 3px 2px; min-width: 16px; cursor: pointer; user-select: none; }
table.dt td.bit.on { background: var(--lad-hl); color: var(--lad-on); font-weight: 700; }
table.dt td.forced { outline: 2px solid #f2b630; outline-offset: -2px; }
table.dt td.dead { color: var(--border-strong); cursor: default; background: var(--surface-2); }
table.dt td.num { color: var(--accent-text); font-weight: 600; }
.io-list { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.io-row { display: grid; grid-template-columns: 14px minmax(54px, max-content) 1fr auto auto; gap: 6px; align-items: center; font-size: 12px; padding: 2px 4px; border-radius: 6px; }
.io-row:hover { background: var(--surface-2); }
.io-cfg { width: 100%; border-collapse: collapse; font-size: 13px; }
.io-cfg th, .io-cfg td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.io-cfg select { width: 100%; }
.io-st.ok { color: var(--ok); font-weight: 600; }
.io-st.bad { color: var(--danger); font-weight: 600; }
.io-row code { white-space: nowrap; }
.ctag-head { display: flex; align-items: center; gap: 8px; font-size: 12px; padding: 4px; }
.ctag-head .tbtn { margin-left: auto; }
.ctag-h { margin: 8px 4px 2px; font-size: 11px; text-transform: uppercase; color: var(--muted); }
.dt.ctag th.rowh { text-align: left; font-family: var(--mono); }
.io-slot { font-size: 11px; font-weight: 600; color: var(--muted); padding: 6px 4px 2px; }
.io-led { width: 11px; height: 11px; border-radius: 50%; background: var(--surface-3); border: 1px solid var(--border-strong); }
.io-led.on { background: #f2c230; border-color: #b78d12; box-shadow: 0 0 5px #f2c230; }
.io-row[data-io^="O"] .io-led.on { background: #ff8a3a; border-color: #c25a14; box-shadow: 0 0 5px #ff8a3a; }
.io-led.forced { outline: 2px solid #f2b630; outline-offset: 1px; }
.io-desc { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.io-force { font: 700 10px var(--mono); }
.io-force.fon, .fon { color: #1c8a43; }
.io-force.foff, .foff { color: var(--danger); }
.io-btns button { border: 1px solid var(--border); background: var(--surface); font: 600 10px var(--mono); padding: 1px 4px; border-radius: 4px; }
.io-btns button:hover { border-color: var(--accent); color: var(--accent-strong); }
.force-list { padding: 0 12px 16px; font-size: 12px; }
.force-list > div { display: flex; gap: 8px; align-items: center; padding: 2px 0; }
.force-list button { border: 0; background: transparent; color: var(--muted); }
.verify { padding-left: 18px; }
.verify li { margin-bottom: 4px; }
.verify li.e { color: var(--danger); }
.verify li.w { color: var(--warn); }
.ok-msg { color: var(--ok); font-weight: 600; }

/* ---------- wiring workspace ---------- */
.ws { flex: 1; min-height: 0; display: flex; }
.ws-palette { width: 236px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border); overflow: auto; padding: 10px; }
.ws-search { width: 100%; margin-bottom: 8px; }
.pal-tools { display: flex; gap: 6px; margin-bottom: 6px; }
.pal-tools .tbtn { flex: 1; }
.pal-cat { border-bottom: 1px solid var(--border); padding-bottom: 6px; margin-bottom: 4px; }
.pal-cat > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; margin: 8px 2px 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); user-select: none; }
.pal-cat > summary::-webkit-details-marker { display: none; }
.pal-cat > summary::before { content: '▸'; display: inline-block; transition: transform .15s; }
.pal-cat[open] > summary::before { transform: rotate(90deg); }
.pal-cat > summary small { margin-left: auto; background: var(--surface-2); border-radius: 8px; padding: 0 6px; font-weight: 500; }
.pal-cat > summary:hover { color: var(--text); }
.pal-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.pal-item { border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; padding: 6px 4px 5px; display: flex; flex-direction: column; align-items: center; gap: 3px; cursor: grab; }
.pal-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.pal-item svg { width: 100%; height: 50px; }
.pal-item span { font-size: 10.5px; text-align: center; line-height: 1.15; color: var(--text); }
.pal-item .term circle { fill: #c9c5bb; stroke: #555; stroke-width: 1; }
.pal-item .term line, .pal-item .tlbl, .pal-item .term .thit { display: none; }
.ws-center { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.ws-toolbar { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.swatches { display: flex; gap: 4px; flex-wrap: wrap; }
.sw { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--surface); box-shadow: 0 0 0 1px var(--border-strong); padding: 0; }
.sw.on { box-shadow: 0 0 0 2px var(--accent); }
.swatches.big .sw { width: 24px; height: 24px; }
.chk { display: flex; align-items: center; gap: 5px; font-size: 12.5px; color: var(--muted); }
.zoomv { font: 12px var(--mono); color: var(--muted); min-width: 40px; text-align: center; }
.ws-canvas { flex: 1; min-height: 0; position: relative; background: var(--canvas); overflow: hidden; }
.ws-svg { width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
.ws-svg.panning { cursor: grabbing; }
.ws-svg.meter-mode .term { cursor: crosshair; }
.gridDot { fill: var(--grid-dot); }
.gridLine { stroke: var(--grid-line); stroke-width: 1; }
.comp { cursor: move; }
.comp .frame { fill: transparent; stroke: transparent; }
.comp:hover .frame { stroke: var(--border-strong); stroke-dasharray: 3 3; }
.comp.sel .frame { stroke: var(--accent); stroke-width: 1.6; stroke-dasharray: none; fill: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.comp .clabel { font: 700 12px var(--mono); fill: var(--text); }
.term { cursor: crosshair; }
.term circle { fill: #d8d4ca; stroke: #45423c; stroke-width: 1.1; }
.term line { stroke: #45423c; stroke-width: 1; }
.term:hover circle:not(.thit) { fill: var(--accent); stroke: var(--accent-strong); }
.term circle.thit { fill: transparent; stroke: none; }
.tlbl { font: 700 7.5px var(--sans); fill: #1d1d1b; text-anchor: middle; paint-order: stroke; stroke: #f4f1ea; stroke-width: 2.4px; pointer-events: none; }
.part { cursor: pointer; }
.dt { font: 600 9px var(--sans); fill: #2a2824; }
.dt.light { fill: #eeeae0; }
.dt.sm { font-size: 9px; }
.dt.xs { font-size: 7.5px; font-weight: 600; }
.dt.big { font-size: 15px; font-weight: 700; }
.dt.brand { font: 700 13px var(--sans); fill: #f4efe4; }
.dt.brand.ink { fill: #1f1f1d; }
.dt.ont { fill: #e45a4a; font-weight: 700; }
.dt.warnt { fill: #f39c1e; font-weight: 800; }
.dt.burn { fill: #ff7a5c; font-size: 12px; font-weight: 800; letter-spacing: .1em; }
.dt.btn-t { font-size: 8px; font-weight: 700; }
.dt.btn-t.on { fill: #fff; }
.wire .wh { fill: none; stroke: transparent; stroke-width: 10; cursor: pointer; }
.float-win { position: fixed; z-index: 45; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); resize: both; overflow: hidden; min-width: 320px; min-height: 220px; }
.fw-head { display: flex; align-items: center; gap: 8px; padding: 4px 6px 4px 12px; cursor: move; background: var(--surface-2); border-bottom: 1px solid var(--border); user-select: none; touch-action: none; font-size: 13px; }
.fw-head .spacer { flex: 1; }
.float-win > .view { flex: 1; min-height: 0; position: relative; }
/* schematic (rails and rungs, drawn like the ladder) */
.sch-rails { display: flex; justify-content: space-between; padding: 0 16px 4px 70px; font: 600 11px var(--mono); color: var(--muted); }
.sch-svg .ssym path, .sch-svg .ssym circle, .sch-svg .ssym rect, .sch-svg .ssym ellipse { fill: none; stroke: var(--lad-wire); stroke-width: 2; }
.sch-svg .ssym .thin { stroke-width: 1.3; }
.sch-svg .ssym.on path, .sch-svg .ssym.on circle, .sch-svg .ssym.on rect, .sch-svg .ssym.on ellipse { stroke: var(--lad-on); stroke-width: 2.6; }
.sch-svg .ssym.on circle, .sch-svg .ssym.on rect { fill: var(--lad-hl); }
.sch-svg .ssym.err path, .sch-svg .ssym.err circle, .sch-svg .ssym.err rect, .sch-svg .ssym.err ellipse { stroke: var(--danger); }
.sch-svg .ssym.miss { opacity: .5; }
.sch-svg .stag { font: 600 12px var(--mono); fill: var(--lad-text); text-anchor: middle; }
.sch-svg .skind { font: 500 9.5px var(--sans); fill: var(--muted); text-anchor: middle; text-transform: uppercase; letter-spacing: .03em; }
.sch-svg .hit { fill: transparent; stroke: transparent; }
.sch-svg .sel-el:hover > .hit, .sch-svg .sleg:hover > .hit { fill: color-mix(in srgb, var(--accent-soft) 50%, transparent); }
.sch-svg .sel-el.sel > .hit, .sch-svg .sleg.sel > .hit { fill: color-mix(in srgb, var(--accent-soft) 85%, transparent); stroke: var(--accent); stroke-dasharray: 4 3; }
.sch-body.operate .sel-el { cursor: pointer; }
.sch-add { padding: 10px 70px; }
.sch-toolbar .tbtn[data-skind] { font: 600 11px var(--mono); }
.comp.jct .jdot { fill: var(--text); stroke: var(--surface); stroke-width: 1.2; }
.comp.jct .term:hover .jdot { fill: var(--accent); }
.bend { fill: var(--surface); stroke: var(--accent); stroke-width: 2; cursor: move; }
.bend:hover { fill: var(--accent); }
.guide { stroke: var(--accent); stroke-width: 1; stroke-dasharray: 5 4; pointer-events: none; }
.wire .wo { fill: none; stroke: var(--wire-halo); stroke-width: 4.8; stroke-linejoin: round; pointer-events: none; }
.wire .wb { fill: none; stroke-width: 2.8; stroke-linejoin: round; }
.wire .wl { fill: none; stroke-width: 2.2; stroke-linejoin: round; opacity: 0; pointer-events: none; }
/* live voltage: thin dots flowing along the wire (the wire keeps its own colour) */
.wire .wl.live { opacity: .9; stroke-dasharray: 2 12; stroke-linecap: round; animation: flow .7s linear infinite; stroke-width: 1.6; }
.wire .wl.short { opacity: 1; stroke: #ff2d20; stroke-width: 4; animation: blink .5s steps(2) infinite; }
.wl.p-L1 { stroke: #ff8a80; } .wl.p-L2 { stroke: #fff59d; } .wl.p-L3 { stroke: #9ec5ff; } .wl.p-N { stroke: #9e9e9e; }
.wl.p-PE { stroke: #b6f08c; } .wl.p-DCp { stroke: #ff8c7a; } .wl.p-DCm { stroke: #8fb7ff; }
@keyframes flow { to { stroke-dashoffset: -14; } }
.wire:hover .wb { stroke-width: 3; }
.wire.sel .wb { stroke-width: 3.4; filter: drop-shadow(0 0 3px var(--accent)); }
.wdot { pointer-events: none; }
.wtemp { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; pointer-events: none; }
.tsel { fill: none; stroke: var(--accent); stroke-width: 2; pointer-events: none; }
.probe circle { fill: none; stroke-width: 3; }
.probe.a circle { stroke: #e0392b; } .probe.b circle { stroke: #222; }
.probe text { font: 700 10px var(--mono); text-anchor: middle; }
.probe.a text { fill: #e0392b; } .probe.b text { fill: var(--text); }
.ws-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); background: #b3261e; color: #fff; padding: 8px 14px; border-radius: 10px; font-weight: 600; box-shadow: var(--shadow-lg); display: none; max-width: 90%; }
.ws-banner.show { display: block; }
.meter-read { position: absolute; right: 12px; top: 12px; background: #1d1c19; color: #e9e4d8; border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 4px; min-width: 210px; font-size: 12px; border: 2px solid #f2c230; }
.meter-read .mval { font: 700 26px var(--mono); color: #9cf5b5; }
.meter-read .mval:not(.live) { color: #c8c2b5; }
.meter-read small { color: #b8b2a5; }
.ws-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; padding: 6px 9px; font-size: 12px; box-shadow: var(--shadow); z-index: 3; }
.ws-hint { position: absolute; left: 12px; bottom: 10px; right: 12px; color: var(--muted); font-size: 11.5px; pointer-events: none; }
.ws-props { width: 270px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--border); overflow: auto; }
.props { padding: 0 12px 16px; }
.props h5 { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 0 6px; }
.status-box { background: var(--surface-2); border-radius: 9px; padding: 8px 10px; margin-bottom: 8px; }
.status-box small { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.status-box div { font-weight: 600; }
.legend { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; font-size: 12px; }
.legend i { display: inline-block; width: 20px; height: 4px; border-radius: 2px; margin-right: 6px; vertical-align: middle; box-shadow: 0 0 0 1px var(--wire-halo); }
.legend i.shortc { background: #ff2d20; }
.tips { padding-left: 18px; font-size: 12.5px; color: var(--muted); }
.tips li { margin-bottom: 5px; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty h3 { font-family: var(--serif); color: var(--text); }

/* ---------- HMI ---------- */
.hmi { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.hmi-toolbar { display: flex; gap: 10px; align-items: center; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.hmi-add { display: flex; gap: 4px; flex-wrap: wrap; }
.hmi-main { flex: 1; min-height: 0; display: flex; }
.hmi-stage { flex: 1; min-width: 0; overflow: auto; display: flex; justify-content: flex-start; align-items: flex-start; padding: 20px; background: var(--canvas); }
.hmi-zoom { display: flex; gap: 4px; align-items: center; }
.hmi-bezel { --k: 1; --w: 800px; --h: 480px; margin: 0 auto; width: calc((var(--w) + 60px) * var(--k)); height: calc((var(--h) + 100px) * var(--k)); background: linear-gradient(180deg, #3a3b3e, #232427); border-radius: calc(18px * var(--k)); position: relative; box-shadow: var(--shadow-lg); flex-shrink: 0; }
.hmi-brand { position: absolute; top: calc(8px * var(--k)); left: calc(30px * var(--k)); font: 600 11px var(--sans); color: #9a9ca2; transform-origin: left top; transform: scale(var(--k)); }
.hmi-screen { position: absolute; left: calc(30px * var(--k)); top: calc(30px * var(--k)); width: 800px; height: 480px; transform: scale(var(--k)); transform-origin: left top; background: linear-gradient(180deg, #1d2a38, #16202b); border: 2px solid #0b0f14; border-radius: 4px; overflow: hidden; font-family: var(--sans); color: #e8eef5; }
.hmi-keys { position: absolute; bottom: calc(18px * var(--k)); left: 50%; transform: translateX(-50%); display: flex; gap: calc(14px * var(--k)); }
.hmi-keys span { width: calc(40px * var(--k)); height: calc(16px * var(--k)); border-radius: 4px; background: #4a4c51; }
.hmi-empty { position: absolute; inset: 0; display: grid; place-items: center; color: #8fa2b5; }
.hobj { position: absolute; user-select: none; touch-action: none; }
.hmi.editing .hobj { outline: 1px dashed rgba(255, 255, 255, .25); cursor: move; }
.hmi.editing .hobj.sel { outline: 2px solid var(--accent); }
.hobj .rs { position: absolute; right: -5px; bottom: -5px; width: 12px; height: 12px; background: var(--accent); border-radius: 3px; cursor: nwse-resize; }
.hmi:not(.editing) .t-pb, .hmi:not(.editing) .t-entry { cursor: pointer; }
.h-pb { width: 100%; height: 100%; border-radius: 10px; background: linear-gradient(180deg, color-mix(in srgb, var(--c) 85%, #fff), var(--c)); border: 2px solid rgba(0, 0, 0, .35); display: grid; place-items: center; font-weight: 700; font-size: 17px; color: #fff; text-shadow: 0 1px 1px rgba(0, 0, 0, .4); box-shadow: 0 4px 0 rgba(0, 0, 0, .35); }
.t-pb.on .h-pb { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0, 0, 0, .35); filter: brightness(1.15); }
.h-ind { width: 100%; height: 100%; border-radius: 8px; background: var(--c, #5b5953); display: flex; flex-direction: column; justify-content: center; align-items: center; border: 2px solid rgba(0, 0, 0, .3); }
.h-ind.round { border-radius: 999px; }
.h-ind small, .h-num small, .h-bar small, .h-tank small, .h-lamp small, .h-motor small { font-size: 11px; letter-spacing: .06em; color: rgba(232, 238, 245, .8); font-weight: 600; }
.h-ind b { font-size: 18px; }
.h-lamp { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; }
.h-lamp i { width: 54%; aspect-ratio: 1; border-radius: 50%; border: 4px solid #8c9097; box-shadow: inset 0 -4px 8px rgba(0, 0, 0, .35); }
.t-lamp.on .h-lamp i { box-shadow: 0 0 18px currentColor, inset 0 2px 6px rgba(255, 255, 255, .5); }
.h-num { width: 100%; height: 100%; background: #0b1218; border: 2px solid #3d4a57; border-radius: 6px; display: flex; flex-direction: column; justify-content: center; padding: 0 10px; }
.h-num b { font: 700 24px var(--mono); color: #7ef0a5; text-align: right; }
.h-num.entry { border-color: #d97757; }
.h-num.entry b { color: #ffd08a; }
.h-bar { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.h-bar .trk { flex: 1; width: 60%; background: #0b1218; border: 2px solid #3d4a57; border-radius: 4px; display: flex; align-items: flex-end; overflow: hidden; }
.h-bar .trk i { width: 100%; display: block; transition: height .15s; }
.h-bar b { font: 700 13px var(--mono); }
.h-motor { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; }
.h-motor svg { flex: 1; width: 100%; min-height: 0; }
.h-motor .mb { fill: #4a5562; stroke: #97a3b0; stroke-width: 3; }
.h-motor path { fill: #b9c3cd; }
.h-motor .hub { fill: #2a3138; }
.t-motor.on .mb { fill: #2f7d45; stroke: #7ef0a5; }
.h-tank { width: 100%; height: 100%; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.h-tank .vessel { flex: 1; width: 80%; border: 3px solid #97a3b0; border-radius: 10px; position: relative; overflow: hidden; display: flex; align-items: flex-end; }
.h-tank .vessel i { width: 100%; background: linear-gradient(180deg, #6cc0f0, #2a7bbf); display: block; }
.h-tank .vessel b { position: absolute; inset: 0; display: grid; place-items: center; font: 700 16px var(--mono); }
.h-alarm { width: 100%; height: 100%; border-radius: 8px; display: flex; align-items: center; padding: 0 16px; font-weight: 700; font-size: 16px; background: #2a333d; color: #9aa5b0; border: 2px solid #3d4a57; }
.t-alarm.on .h-alarm { background: #b3261e; color: #fff; border-color: #ff7a6b; animation: blink 1s steps(2) infinite; }
.h-alarm .al-none { display: none; font-weight: 500; font-size: 14px; opacity: .8; }
.hmi:not(.editing) .t-alarm:not(.on) .al-txt { display: none; }
.hmi:not(.editing) .t-alarm:not(.on) .al-none { display: inline; }
.h-text { width: 100%; height: 100%; display: flex; align-items: center; font-weight: 700; letter-spacing: .02em; }
.h-shape { width: 100%; height: 100%; border-radius: 4px; background: #3d4a57; display: flex; align-items: center; justify-content: center; font-weight: 700; color: #fff; }
.h-shape.round { border-radius: 50%; }
.h-shape.pipe { border-radius: 999px; }
.h-trend { position: relative; width: 100%; height: 100%; background: #0f171f; border: 2px solid #3d4a57; border-radius: 6px; overflow: hidden; }
.h-trend small { position: absolute; left: 8px; top: 4px; font-weight: 700; color: #9fb0bd; }
.h-trend b { position: absolute; right: 8px; top: 2px; font: 700 16px var(--mono); }
.h-trend svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.h-img { width: 100%; height: 100%; object-fit: contain; display: block; }
.h-img.empty { display: flex; align-items: center; justify-content: center; border: 2px dashed #4a5a66; color: #9fb0bd; }
.h-pb.login { --c: #5b5953; } .t-login.on .h-pb.login { --c: #2fa84f; }
.hmi.editing .hobj.hid { opacity: .45; }
.hmi-scr { padding: 4px 6px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 12px; }
.hmi-bezel:fullscreen { --k: 1 !important; width: 100vw; height: 100vh; border-radius: 0; display: flex; align-items: center; justify-content: center; }
.hmi-bezel:fullscreen .hmi-screen { position: static; transform: none; }
.hmi-props { width: 270px; flex-shrink: 0; background: var(--surface); border-left: 1px solid var(--border); overflow: auto; }
.taglist { padding-left: 16px; font-size: 12.5px; }

/* ---------- learn ---------- */
.learn { flex: 1; min-height: 0; display: flex; }
.learn-nav { width: 290px; flex-shrink: 0; border-right: 1px solid var(--border); background: var(--surface); overflow: auto; padding: 14px 12px 30px; }
.learn-nav h3 { font-family: var(--serif); font-weight: 600; margin: 0 6px 8px; font-size: 18px; }
.learn-nav h3.mt { margin-top: 22px; }
.learn-nav h6 { margin: 12px 6px 4px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.learn-nav button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 7px 10px; border-radius: 8px; font-size: 13.5px; color: var(--text); }
.learn-nav button:hover { background: var(--surface-2); }
.learn-nav button.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
/* Learn: Course / Exercises tabs, difficulty and topic of the exercises, done marks, the hint */
.learn-tabs { display: flex; gap: 4px; padding: 4px; margin-bottom: 8px; background: var(--surface-2); border-radius: 10px; }
.learn-nav .learn-tabs button.lt { flex: 1; text-align: center; padding: 7px 6px; font-weight: 600; }
.learn-nav .learn-tabs button.lt.on { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.2); }
.learn-tabs small, .ex-diff small { color: var(--muted); font-weight: 500; }
.ex-diff { display: flex; gap: 4px; margin: 4px 0 8px; }
.learn-nav .ex-diff button { flex: 1; text-align: center; padding: 6px 4px; border: 1px solid var(--border); font-size: 12.5px; }
.learn-nav .ex-diff button.on { border-color: var(--accent); }
.ex-topic { width: 100%; margin-bottom: 6px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.learn-nav button.done { color: var(--muted); }
.learn-body details.hint { margin: 10px 0; padding: 8px 12px; border: 1px dashed var(--border); border-radius: 8px; }
.learn-body details.hint summary { cursor: pointer; font-weight: 600; }
.learn-body { flex: 1; overflow: auto; padding: 28px clamp(16px, 4vw, 56px) 60px; max-width: 980px; }
.learn-body h2 { font-family: var(--serif); font-size: 30px; font-weight: 600; margin: 4px 0 14px; letter-spacing: -.01em; }
.learn-body h3 { font-family: var(--serif); font-weight: 600; font-size: 20px; }
.learn-body h3.mt { margin-top: 34px; }
.kicker { color: var(--accent-text); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.lesson { font-size: 15px; line-height: 1.65; max-width: 720px; }
.lesson li { margin-bottom: 6px; }
table.ref { border-collapse: collapse; width: 100%; font-size: 13px; }
table.ref th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid var(--border-strong); padding: 6px 8px; }
table.ref td { border-bottom: 1px solid var(--border); padding: 6px 8px; vertical-align: top; }

/* ---------- lesson grading ---------- */
.grade { margin-top: 14px; max-width: 720px; }
.grade-ok, .grade-bad { font-weight: 600; margin: 0 0 6px; }
.grade-ok { color: var(--ok); }
.grade-bad { color: var(--danger); }
.grade-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 4px; }
.grade-list li { padding: 6px 10px; border-radius: 8px; background: var(--surface-2); }
.grade-list li.bad { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.grade-list li.ok { background: color-mix(in srgb, var(--ok, #2fa84f) 14%, var(--surface)); }
.grade-list li.next { outline: 2px solid var(--accent); outline-offset: -2px; font-weight: 600; }
.grade-list small { color: var(--muted); }

/* ---------- project list ---------- */
.proj-list { display: flex; flex-direction: column; gap: 6px; max-height: 60vh; overflow: auto; }
.proj-row { display: grid; grid-template-columns: 1fr auto auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; }
.proj-row.cur { border-color: var(--accent); background: var(--accent-soft); }
.proj-row div { min-width: 0; display: flex; flex-direction: column; }
.proj-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.proj-row small { color: var(--muted); font-size: 11.5px; }
.danger-txt { color: var(--danger) !important; font-size: 12px !important; width: auto !important; padding: 0 6px; }

/* ---------- modal / menu / toast ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgba(30, 24, 14, .35); display: grid; place-items: center; z-index: 50; padding: 16px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 16px; width: min(460px, 100%); box-shadow: var(--shadow-lg); border: 1px solid var(--border); max-height: 90vh; display: flex; flex-direction: column; }
.modal.wide { width: min(760px, 100%); }
.modal-head { display: flex; align-items: center; padding: 14px 16px 6px 20px; }
.modal-head h3 { margin: 0; flex: 1; font-family: var(--serif); font-weight: 600; font-size: 19px; }
.modal-body { padding: 8px 20px; overflow: auto; }
.modal-body textarea { width: 100%; font-family: var(--mono); font-size: 13px; }
.modal-body .help code { font-size: 11.5px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 16px; }
.ctx-menu { position: fixed; z-index: 80; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 5px; min-width: 190px; display: flex; flex-direction: column; }
.ctx-menu button { border: 0; background: transparent; text-align: left; padding: 6px 10px; border-radius: 6px; font-size: 13px; display: flex; gap: 18px; }
.ctx-menu button kbd { margin-left: auto; font-size: 11px; color: var(--muted); border: 0; background: none; padding: 0; }
@media (pointer: coarse) { .ctx-menu button kbd { display: none; } }
.ctx-menu button:hover:not(:disabled) { background: var(--accent-soft); }
.ctx-menu button:disabled { color: var(--muted); opacity: .55; cursor: default; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu hr { border: 0; border-top: 1px solid var(--border); margin: 4px 2px; }
.ctx-head { font-size: 11px; color: var(--muted); padding: 4px 10px 2px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; }
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 70; align-items: center; pointer-events: none; width: min(560px, calc(100% - 32px)); }
.toast { background: #2b2925; color: #f3efe6; padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(8px); transition: .25s; font-size: 13px; text-align: center; }
.toast.show { opacity: 1; transform: none; }
.toast.ok { background: #1f6e3b; }
.toast.warn { background: #8a5a00; }
.toast.danger { background: #a3241b; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .lad-side { width: 270px; }
  .ws-props { width: 220px; }
  .ws-palette { width: 190px; }
}
@media (max-width: 760px) {
  .lad-org { position: absolute; left: 0; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow); }
  .topbar { gap: 8px; padding: 6px max(12px, env(safe-area-inset-right, 0px)) 6px max(12px, env(safe-area-inset-left, 0px)); }
  .brand { min-width: 0; flex: 1; }
  .brand-title { font-size: 16px; white-space: nowrap; }
  .brand > div { min-width: 0; }
  .brand-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .brand .logo { width: 26px; height: 26px; flex-shrink: 0; }
  .topbar { flex-wrap: nowrap; }
  .top-actions { flex-wrap: nowrap; gap: 2px; flex-shrink: 0; }
  .top-actions .btn { padding: 6px 7px; font-size: 13px; }
  .top-actions .icon-btn { width: 30px; }
  .top-actions [data-examples] { display: none; }
  /* view tabs become a bottom navigation bar */
  .tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; border-radius: 0; border: 0; border-top: 1px solid var(--border);
    background: var(--surface); padding: 4px 4px calc(4px + env(safe-area-inset-bottom, 0px)); flex-wrap: nowrap; justify-content: space-around; gap: 0; box-shadow: 0 -4px 16px rgba(0, 0, 0, .06); }
  .tabs button { flex: 1; flex-direction: column; gap: 1px; padding: 5px 2px; font-size: 11px; min-width: 0; }
  .tabs button .ti { font-size: 15px; }
  #main { margin-bottom: calc(58px + env(safe-area-inset-bottom, 0px)); }
  #toast-root { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); }
  .plcbar { gap: 8px; padding: 5px 12px; flex-wrap: nowrap; overflow-x: auto; }
  .plcbar > * { flex-shrink: 0; }
  .io-strip, .scan, .bar-msg, [data-layout] { display: none; }
  .leds { gap: 7px; }
  .led { font-size: 10px; }
  /* toolbars: one row that scrolls sideways */
  .lad-toolbar, .ws-toolbar, .hmi-toolbar { flex-wrap: nowrap; overflow-x: auto; align-items: center; padding: 6px 10px; scrollbar-width: none; }
  .lad-toolbar::-webkit-scrollbar, .ws-toolbar::-webkit-scrollbar, .hmi-toolbar::-webkit-scrollbar { display: none; }
  .more-r { -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
  .more-l { -webkit-mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent); }
  .more-l.more-r { -webkit-mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
  .tb-group, .swatches, .hmi-add, .hmi-zoom { flex-wrap: nowrap; flex-shrink: 0; }
  .ws-toolbar > *, .hmi-toolbar > * { flex-shrink: 0; }
  .ws-hint { display: none; }
  .pal-grid { grid-template-columns: 1fr 1fr; }
  .learn { flex-direction: column; overflow: auto; }
  .learn-nav { width: 100%; max-height: none; border-right: 0; border-bottom: 1px solid var(--border); }
  .learn-body { overflow: visible; }
  .hmi-stage { padding: 10px; }
  .modal-wrap { align-items: end; padding: 0; }
  .modal { width: 100%; border-radius: 16px 16px 0 0; max-height: 85vh; padding-bottom: env(safe-area-inset-bottom, 0px); }
}
/* side panels become slide-in drawers on narrow screens */
.mobile-only { display: none; }
@media (max-width: 760px) {
  .mobile-only { display: inline-flex; align-items: center; }
  .desk-only { display: none; }
  .lad-side, .ws-props, .hmi-props, .ws-palette {
    display: block; position: fixed; top: 0; bottom: 0; z-index: 40; width: min(330px, 88vw); transition: transform .22s ease;
    box-shadow: var(--shadow-lg); padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .lad-side, .ws-props, .hmi-props { right: 0; transform: translateX(105%); border-left: 1px solid var(--border); }
  .ws-palette { left: 0; transform: translateX(-105%); border-right: 1px solid var(--border); }
  .lad-side.open, .ws-props.open, .hmi-props.open, .ws-palette.open { transform: none; }
}
/* inside a pane, side panels slide over the pane instead of taking width */
#main.multi .mobile-only, .float-win .mobile-only { display: inline-flex; align-items: center; }
#main.multi .lad-side, #main.multi .ws-props, #main.multi .hmi-props, #main.multi .ws-palette, .float-win .lad-side, .float-win .ws-props, .float-win .hmi-props, .float-win .ws-palette {
  display: block; position: absolute; top: 0; bottom: 0; z-index: 30; width: min(320px, 85%); transition: transform .22s ease; box-shadow: var(--shadow-lg); }
#main.multi .lad-side, #main.multi .ws-props, #main.multi .hmi-props, .float-win .lad-side, .float-win .ws-props, .float-win .hmi-props { right: 0; transform: translateX(105%); border-left: 1px solid var(--border); }
#main.multi .ws-palette, .float-win .ws-palette { left: 0; transform: translateX(-105%); border-right: 1px solid var(--border); }
#main.multi .lad-side.open, #main.multi .ws-props.open, #main.multi .hmi-props.open, #main.multi .ws-palette.open, .float-win .lad-side.open, .float-win .ws-props.open, .float-win .hmi-props.open, .float-win .ws-palette.open { transform: none; }
#main.multi .lad-toolbar, #main.multi .ws-toolbar, #main.multi .hmi-toolbar, .float-win .lad-toolbar, .float-win .ws-toolbar, .float-win .hmi-toolbar { flex-wrap: wrap; align-items: center; gap: 4px; padding: 5px 8px; }
#main.multi .tb-group, .float-win .tb-group { padding: 1px 5px 1px 3px; }
#main.multi .tb-lbl, #main.multi .ins-btn small, .float-win .tb-lbl, .float-win .ins-btn small { display: none; }
#main.multi .ins-btn, .float-win .ins-btn { min-width: 38px; padding: 3px 4px; }
#main.multi .lad-toolbar .tbtn, #main.multi .ws-toolbar .tbtn, .float-win .lad-toolbar .tbtn, .float-win .ws-toolbar .tbtn { padding: 4px 7px; }
#main.multi .ws-hint, .float-win .ws-hint { display: none; }
@media (prefers-reduced-motion: reduce) { .lad-side, .ws-props, .hmi-props, .ws-palette { transition: none; } }
/* touch screens: bigger targets */
@media (pointer: coarse) {
  .tbtn { min-height: 38px; padding: 6px 11px; }
  .tbtn.sm { min-height: 32px; }
  .seg button { min-height: 36px; }
  .sw { width: 24px; height: 24px; }
  .dt-tabs button { padding: 6px 12px; }
  .io-btns button { padding: 5px 8px; }
  .ctx-menu button { padding: 11px 14px; font-size: 15px; }
  .rung-svg { -webkit-touch-callout: none; }
}
.lcd { font: 700 11px var(--mono); fill: #1e2a10; pointer-events: none; }
.lcd.on { fill: #c9d86c; }
.lcd.sm { font-size: 9px; }
.wire .wpe { fill: none; stroke: #f2c230; stroke-width: 2.2; stroke-dasharray: 7 7; stroke-linejoin: round; pointer-events: none; }
.ferr { pointer-events: none; }
.ferr rect { fill: #f7f7f4; stroke: #6b6b66; stroke-width: .7; }
.ferr text { font: 700 6.5px var(--sans); fill: #1d1d1b; text-anchor: middle; }
.rails .comp .clabel, .backs .comp .clabel { opacity: .6; }
.kbd-table td { padding: 4px 10px 4px 0; font-size: 13px; } .kbd-table kbd { font: 12px var(--mono); background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; white-space: nowrap; }
/* Electrical Diagram, IEC view */
.iec-svg .colbg { fill: transparent; }
.iec-svg .srung.sel .colbg { fill: color-mix(in srgb, var(--accent-soft) 35%, transparent); }
.iec-svg .colnum { font: 600 11px var(--mono); fill: var(--muted); text-anchor: middle; }
.iec-svg .railtxt { font: 700 13px var(--mono); fill: var(--lad-text); }
.iec-svg .railsrc { font: 500 9.5px var(--mono); fill: var(--muted); }
.iec-svg .stag.iec { text-anchor: end; font-size: 11.5px; }
.iec-svg .sterm { font: 500 9px var(--mono); fill: var(--muted); }
.iec-svg .sterm.c { text-anchor: middle; }
.iec-svg .ssym .dash { stroke-dasharray: 3 2; }
.iec-svg .w.open { stroke-dasharray: 4 3; opacity: .6; }
.iec-svg .jn { fill: var(--lad-wire); }
.iec-svg .hint { font: 500 10px var(--sans); fill: var(--muted); text-anchor: middle; }
/* the diagram is drawn like the ladder (one line colour, live paths light up); wire colours belong to the Wiring */
.iec-svg .pw { stroke: var(--lad-wire); stroke-width: 1.6; }
.iec-svg .pw.on { stroke: var(--lad-on); stroke-width: 2.6; }
.iec-svg .psrc { fill: var(--lad-bg); stroke: var(--lad-wire); stroke-width: 1.6; }
.iec-svg .ssym circle.mon { fill: var(--lad-hl); stroke: var(--lad-on); }
.iec-svg .mtxt { font: 700 12px var(--sans); fill: var(--lad-text); text-anchor: middle; }
.iec-svg .mtxt.sm { font-size: 10px; }
.sch-body.operate .pel { cursor: pointer; }
.sch-svg .ssym, .sch-svg text { pointer-events: none; }
/* Electrical Diagram, free draw */
.sch-toolbar .free-group { display: none; }
.free-style .sch-toolbar .free-group { display: flex; }
.free-style .sch-toolbar .tb-group:not(.keep):not(.free-group) { display: none; }
.free-style .sch-body { padding: 0; overflow: hidden; }
.free-style .sch-add { display: none; }
.free-svg { width: 100%; height: 100%; min-height: 420px; touch-action: none; display: block; }
.gridLine { fill: none; stroke: var(--grid-line); stroke-width: 1; }
.fd-wrap { display: flex; height: 100%; min-height: 420px; }
.fd-lib { position: relative; z-index: 1; width: 212px; flex: none; display: flex; flex-direction: column; gap: 6px; padding: 8px; border-right: 1px solid var(--border); background: var(--surface); overflow: hidden; }
.fd-wrap.nolib .fd-lib { display: none; }
.fd-grp, .fd-search { width: 100%; padding: 6px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font: inherit; font-size: 13px; }
.fd-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; overflow-y: auto; padding-right: 2px; }
.fd-ico { aspect-ratio: 4 / 5; padding: 4px 4px 7px; border: 1px solid var(--border); border-bottom: 3px solid var(--g, var(--muted)); border-radius: 4px; background: var(--lad-bg); cursor: grab; }
.fd-ico:hover { border-color: var(--accent); }
.fd-ico { display: flex; flex-direction: column; align-items: stretch; gap: 2px; min-width: 0; }
.fd-ico svg { width: 100%; flex: 1; min-height: 0; pointer-events: none; }
/* the symbol's name under its icon (two lines at most; the whole name in the tooltip and on a long press) */
.fd-nm { font: 500 9.5px/1.15 var(--sans); color: var(--muted); text-align: center; display: -webkit-box; -webkit-line-clamp: 2; line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; pointer-events: none; min-height: 2.3em; }
.fd-ico .ftag, .fd-ico .sterm { display: none; }
.fd-ico.g-sources { --g: #2f9e3a; } .fd-ico.g-switches { --g: #7b3fb0; } .fd-ico.g-sensors { --g: #2f6fd6; } .fd-ico.g-auxiliaries { --g: #8a8f2a; }
.fd-ico.g-coils { --g: #d8c21f; } .fd-ico.g-loads { --g: #d9826a; } .fd-ico.g-contactors { --g: #20a8c0; } .fd-ico.g-protections { --g: #c0392b; }
.fd-ico.g-others { --g: #e39a1b; } .fd-ico.g-motors { --g: #1f8f86; }
.fd-canvas { position: relative; flex: 1; min-width: 0; overflow: hidden; }
.fd-host { position: absolute; inset: 0; overflow: hidden; }
.fd-zoom { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 2px; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 2px; box-shadow: var(--shadow); }
.free-svg .fval { font: 600 10px var(--mono); fill: var(--accent-text); pointer-events: none; }
.free-svg .fval.fcount { fill: var(--warn); }
/* a coil or lamp that gets too low a voltage */
.free-svg .ssym.lowv path, .free-svg .ssym.lowv rect, .free-svg .ssym.lowv circle { stroke: var(--warn); stroke-dasharray: 3 2; }
/* run view: current flows along a live wire, an energized coil is filled, a lit lamp glows, a contact that just switched flashes */
.free-svg .fwire .wflow { stroke: #fff; stroke-opacity: .55; stroke-width: 1.2; stroke-dasharray: 3 11; pointer-events: none; animation: fdflow .7s linear infinite; }
@keyframes fdflow { to { stroke-dashoffset: -14; } }
.free-svg .ssym.on[data-look="coil"] rect, .free-svg .ssym.on[data-look^="tcoil"] rect, .free-svg .ssym.on[data-look="icoil"] rect { fill: #ffe600; fill-opacity: 1; stroke: #e53935; }
.free-svg .ssym.on[data-look="lamp"] circle { fill: #ffd54a; stroke: #e0a800; filter: drop-shadow(0 0 6px #ffd54a); }
.free-svg .ssym.on[data-look="lamp"] path { stroke: #7a5a00; }
.free-svg .ssym.flip { animation: fdflip .4s ease-out; }
@keyframes fdflip { 0% { opacity: .35; } 100% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .free-svg .fwire .wflow, .free-svg .ssym.flip { animation: none; } }
/* conductor colours (🎨 Colours): Philippine practice as in the Wiring; N is grey so it shows on white paper */
.free-svg .fwire .w.pc-L1 { stroke: #b3261e; }
.free-svg .fwire .w.pc-L2 { stroke: #d4a20c; }
.free-svg .fwire .w.pc-L3 { stroke: #2b6fe0; }
.free-svg .fwire .w.pc-N { stroke: #8d8d86; }
.free-svg .fwire .w.pc-PE { stroke: #58a83a; }
.free-svg .fwire .w.pc-dcp { stroke: #d33a2c; }
.free-svg .fwire .w.pc-dcm { stroke: #1f4fa8; }
.free-svg .fwire .w.on[class*="pc-"] { stroke-width: 2.6; }
.free-svg .ftag.start { text-anchor: start; }
.sch-svg .ssym path.fill { fill: var(--lad-wire); }
@media (max-width: 760px) {
  .fd-lib { width: 150px; } .fd-grid { grid-template-columns: repeat(2, 1fr); }
  /* the Electrical Diagram toolbar wraps on a phone (no control cut off at the edge): icons only, the current-path
     symbols in the list instead of a button each */
  .sch-toolbar { flex-wrap: wrap; overflow: visible; gap: 4px; padding: 5px 8px; -webkit-mask-image: none; mask-image: none; }
  .sch-toolbar .tb-group { flex-wrap: wrap; flex-shrink: 1; border-right: 0; padding: 0; gap: 3px; }
  .sch-toolbar .tb-lbl, .sch-toolbar .tl, .sch-toolbar .ic, .sch-toolbar .tb-group.kinds, .sch-toolbar .pw-group { display: none; }
  /* the free drawing's short toolbar: icons only (its labels give way; without the icons the buttons were empty) */
  .free-style .sch-toolbar .free-group .ic { display: inline-block; margin-right: 0; }
  .sch-toolbar .tb-group.keep { flex-wrap: nowrap; gap: 6px; }
  .sch-toolbar .tbtn { padding: 5px 8px; min-height: 34px; }
  .sch-toolbar .seg button { padding: 5px 7px; }
  .sch-more { max-width: 100%; }
}
@media (min-width: 761px) { .sch-toolbar .mob-opt { display: none; } }
.free-svg .fitem { cursor: move; }
.free-svg .fitem .hit { fill: transparent; }
.free-svg .fitem:hover > .hit { fill: color-mix(in srgb, var(--accent-soft) 40%, transparent); }
.free-svg .fitem.sel > .hit { fill: color-mix(in srgb, var(--accent-soft) 70%, transparent); stroke: var(--accent); stroke-dasharray: 4 3; }
.free-svg .fterm { fill: var(--lad-bg); stroke: var(--lad-wire); stroke-width: 1.4; cursor: crosshair; }
.free-svg .fterm:hover, .free-svg .fterm.on { fill: var(--accent); stroke: var(--accent); }
/* like Simurelay: a connected terminal is just the end of the line (it lights up under the pointer) */
.free-svg .fterm.used:not(:hover):not(.on) { fill: transparent; stroke: transparent; }
.free-svg .sterm { font: 700 9.5px var(--sans); fill: #2bb5a6; }
.free-svg .ftag.up { text-anchor: middle; }
/* running: red where + (or a phase) reaches, blue where 0 V (or N) reaches */
.free-svg .fwire .w.on:not([class*="pc-"]) { stroke: #e53935; }
.free-svg .fwire .w.neg:not([class*="pc-"]) { stroke: #2f6fd6; stroke-width: 2.6; }
.free-svg .ssym.on path, .free-svg .ssym.on circle, .free-svg .ssym.on rect { stroke: #e53935; }
.free-svg .fwire path { fill: none; }
.free-svg .fwire .fwh { stroke: transparent; stroke-width: 10; cursor: pointer; }
.free-svg .fwire.sel .w { stroke: var(--accent); stroke-width: 2.6; }
.free-svg .ftag { font: 600 11.5px var(--mono); fill: var(--lad-text); text-anchor: end; pointer-events: none; }
.free-svg .ftag.faddr { font-weight: 400; font-size: 10px; }
.free-svg .ftag.fcmt { font: italic 400 10px var(--sans); fill: var(--muted); }
/* tag colour (drawing settings) */
.free-svg.tagc-red .ftag:not(.fcmt) { fill: #c62828; }
.free-svg.tagc-blue .ftag:not(.fcmt) { fill: #1f5fbf; }
.free-svg.tagc-green .ftag:not(.fcmt) { fill: #2e7d32; }
.free-svg.tagc-orange .ftag:not(.fcmt) { fill: #d9730d; }
.free-svg.tagc-purple .ftag:not(.fcmt) { fill: #7b3fb5; }
.fd-props .chk { display: flex; align-items: center; gap: 6px; font-size: 12px; margin: 4px 0; }
.free-svg .ssym rect.fill { fill: var(--lad-wire); }
/* free draw is the Electrical Diagram: no view switch, no Edit / Operate (Play operates the drawing) */
.free-only .sch-toolbar .tb-group.keep { display: none !important; }
/* the short drawing toolbar: these tools are in the ⋯ menu */
.sch-toolbar .tbtn.in-more { display: none; }
.free-svg .fguide { stroke: var(--accent); stroke-width: .8; stroke-dasharray: 4 4; opacity: .8; pointer-events: none; }
.free-svg .wtemp { fill: none; stroke: var(--accent); stroke-width: 2; stroke-dasharray: 5 4; pointer-events: none; }
.free-svg .fbox { fill: color-mix(in srgb, var(--accent-soft) 45%, transparent); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; pointer-events: none; }
.sch-body.operate .free-svg .fitem { cursor: pointer; }
.free-svg .fbend { fill: var(--surface); stroke: var(--accent); stroke-width: 2; cursor: move; }
.free-svg .ssym .jdot { fill: var(--lad-wire); stroke: none; }
.free-svg .fjdot { fill: var(--lad-wire); pointer-events: none; }
.free-svg .fjdot.on { fill: #e53935; }
.free-svg .ssym.on .jdot { fill: #e53935; }
.free-svg .ftext { font: 600 13px var(--sans); fill: var(--lad-text); pointer-events: none; }
.org, .org ul { list-style: none; margin: 0; padding-left: 18px; }
.org { padding-left: 0; font-size: 13px; line-height: 1.9; }
.org small { color: var(--muted); }
.tag-tbl td, .tag-tbl th { white-space: nowrap; }
.conn-chip { font: 700 11px var(--mono); padding: 3px 8px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); }
.conn-chip.on { background: var(--ok); color: #fff; border-color: transparent; }
.conn-chip.edit { background: var(--warn); color: #fff; border-color: transparent; }
.conn-chip.off { background: var(--surface-2); }
.lad-banner { display: flex; gap: 8px; align-items: center; padding: 6px 14px; background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }
.lad-comm select { font-size: 12px; padding: 3px 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }
.lad-comm-real { display: inline-flex; gap: 2px; }
.lad-comm-real[hidden] { display: none; }
.net-remote { border: 1px solid var(--border); border-radius: 8px; padding: 8px; margin: 6px 0; }
.net-words { display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 4px; margin-top: 6px; }
.net-words label { display: flex; flex-direction: column; font-size: 11px; }
.net-words input { width: 100%; min-width: 0; padding: 2px 4px; font: 12px var(--mono); border: 1px solid var(--border); border-radius: 4px; background: var(--surface); color: var(--text); }
@media (max-width: 760px) { .net-words { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.lad-banner[hidden] { display: none; }
/* ---------- free draw: Simurelay's look (light and dark follow the app theme; colours can be changed in ⋯ → Settings) ---------- */
:root { --fd-bg: #F0F0F0; --fd-grid: #E2E2E2; --fd-grid2: #C8C8C8; --fd-sym: #0A0A0A; --fd-sel: #2979FF; --fd-align: rgba(170, 170, 170, .24); --fd-tag: #008000; --fd-cmt: #008000; --fd-term: #008000;
  --fd-L1: #A35740; --fd-L2: #455A64; --fd-L3: #18FFFF; --fd-N: #2962FF; --fd-PE: #FDD835; --fd-P: #FF0000; --fd-M: #2962FF; --fd-coil: #FFE600; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fd-bg: #141414; --fd-grid: #1E1E21; --fd-grid2: #28282D; --fd-sym: #B4B4B4; --fd-align: rgba(100, 100, 100, .24); --fd-tag: #1DE9B6; --fd-cmt: #FFFF8D; --fd-term: #1DE9B6; } }
:root[data-theme="dark"] { --fd-bg: #141414; --fd-grid: #1E1E21; --fd-grid2: #28282D; --fd-sym: #B4B4B4; --fd-align: rgba(100, 100, 100, .24); --fd-tag: #1DE9B6; --fd-cmt: #FFFF8D; --fd-term: #1DE9B6; }
.fd-canvas { background: var(--fd-bg); }
.free-svg { --lad-wire: var(--fd-sym); --lad-text: var(--fd-sym); --lad-bg: var(--fd-bg); --grid-dot: var(--fd-grid2); --grid-line: var(--fd-grid2); }
.free-svg .gridLine { stroke: var(--fd-grid2); }
.free-svg .gridDot { fill: var(--fd-grid); }
.free-svg .ftag, .free-svg .ftag.faddr { font: 700 12.5px var(--sans); fill: var(--fd-tag); }
.free-svg .ftag.fcmt { font: 400 11px var(--sans); fill: var(--fd-cmt); }
.free-svg .sterm { font: 700 11px var(--sans); fill: var(--fd-term); }
.free-svg .mtxt { fill: var(--fd-sym); }
/* terminals: small grey squares; under the pointer and when picked, blue; a wired terminal is just the end of its line */
.free-svg .fterm { fill: #9E9E9E; stroke: none; cursor: crosshair; }
.free-svg .fterm:hover, .free-svg .fterm.on { fill: var(--fd-sel); stroke: var(--fd-sel); stroke-width: 4; }
.free-svg .fterm.used:not(:hover):not(.on) { fill: transparent; stroke: transparent; }
.free-svg .fitem:hover > .hit { fill: transparent; }
.free-svg .fitem.sel > .hit { fill: transparent; stroke: var(--fd-sel); stroke-width: 3; stroke-dasharray: none; }
.free-svg .fitem.sel .ssym path, .free-svg .fitem.sel .ssym circle, .free-svg .fitem.sel .ssym rect, .free-svg .fitem.sel .ssym ellipse { stroke: var(--fd-sel); }
.free-svg .fitem.sel .ftag, .free-svg .fitem.sel .sterm { fill: var(--fd-sel); }
.free-svg .fwire .w { stroke: var(--fd-sym); }
.free-svg .fwire.sel .w { stroke: var(--fd-sel); stroke-width: 3; }
.free-svg .fseg { fill: none; stroke: #FF9800; stroke-width: 2; pointer-events: none; }
/* the short drawing toolbar: these tools are in the ⋯ menu */
.sch-toolbar .tbtn.in-more { display: none; }
.free-svg .fguide { stroke: var(--fd-align); stroke-width: 4; stroke-dasharray: none; opacity: 1; pointer-events: none; }
.free-svg .fguide.hit { stroke: var(--fd-sel); stroke-width: 1.5; opacity: .7; }
.free-svg .wtemp { stroke: var(--fd-sel); }
.free-svg .fjdot { fill: var(--fd-sym); }
/* editing: one line colour; running: each conductor in its colour (as Simurelay), the energized coil yellow */
.free-svg:not(.run) .fwire .w.on, .free-svg:not(.run) .fwire .w.neg { stroke: var(--fd-sym); stroke-width: 2; }
.free-svg:not(.run) .fwire .wflow { display: none; }
.free-svg:not(.run) .fjdot.on { fill: var(--fd-sym); }
.free-svg:not(.run) .ssym.on path, .free-svg:not(.run) .ssym.on circle, .free-svg:not(.run) .ssym.on rect { stroke: var(--fd-sym); }
.free-svg:not(.run) .ssym.on[data-look] rect, .free-svg:not(.run) .ssym.on[data-look="lamp"] circle { fill: none; filter: none; }
.free-svg.run .fwire .w[class*=" p-"] { stroke-width: 2.6; } .free-svg.run .fwire .w.p-P, .free-svg.run .fwire .w.p-M { stroke-width: 2; }
.free-svg.run .fwire .w.p-L1 { stroke: var(--fd-L1); } .free-svg.run .fjdot.p-L1 { fill: var(--fd-L1); }
.free-svg.run .fwire .w.p-L2 { stroke: var(--fd-L2); } .free-svg.run .fjdot.p-L2 { fill: var(--fd-L2); }
.free-svg.run .fwire .w.p-L3 { stroke: var(--fd-L3); } .free-svg.run .fjdot.p-L3 { fill: var(--fd-L3); }
.free-svg.run .fwire .w.p-N { stroke: var(--fd-N); } .free-svg.run .fjdot.p-N { fill: var(--fd-N); }
.free-svg.run .fwire .w.p-PE { stroke: var(--fd-PE); } .free-svg.run .fjdot.p-PE { fill: var(--fd-PE); }
.free-svg.run .fwire .w.p-P { stroke: var(--fd-P); } .free-svg.run .fjdot.p-P { fill: var(--fd-P); }
.free-svg.run .fwire .w.p-M { stroke: var(--fd-M); } .free-svg.run .fjdot.p-M { fill: var(--fd-M); }
.free-svg .fwire path.w { fill: none; }
.free-svg .ssym[data-look="pot"] circle, .free-svg .ssym.on[data-look="pot"] circle { fill: var(--fd-bg); stroke: var(--fd-sym); }
.free-svg.run .ssym.on path, .free-svg.run .ssym.on circle, .free-svg.run .ssym.on rect { stroke: var(--fd-sym); }
.free-svg.run .ssym.on[data-look="coil"] rect, .free-svg.run .ssym.on[data-look^="tcoil"] rect, .free-svg.run .ssym.on[data-look="icoil"] rect { fill: var(--fd-coil); stroke: var(--fd-sym); }
/* Play: only the drawing, a Stop button at the top left and a green line along the top (as Simurelay) */
.fd-stop { display: none; position: absolute; left: 8px; top: 8px; z-index: 2; gap: 2px; padding: 3px; border-radius: 6px; background: var(--surface); border: 1px solid var(--border); }
.fd-stop button { width: 30px; height: 26px; border: 0; border-radius: 4px; background: transparent; cursor: pointer; color: #E53935; font-size: 15px; }
.fd-stop button:hover { background: var(--surface-2); }
#view-schematic.fd-playing .fd-stop { display: flex; }
#view-schematic.fd-playing .fd-canvas { box-shadow: inset 0 2px 0 #1FA34A; }
#view-schematic.fd-playing .sch-toolbar, #view-schematic.fd-playing .fd-lib, #view-schematic.fd-playing .sch-side, #view-schematic.fd-fullsym .sch-side { display: none; }
.free-svg .fwire .wflow { display: none; }
/* the property bar (Simurelay's VALUES bar): in place of the toolbar and the library while it is open */
.fd-pbar { position: absolute; left: 0; right: 0; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 6px 10px; background: var(--surface); border-bottom: 1px solid var(--border); font-size: 13px; }
.fd-pbar[hidden] { display: none; }
.fd-pbar .fpb-name { font-weight: 600; white-space: nowrap; }
.fd-pbar .fpb-in { width: 200px; padding: 4px 8px; font-size: 13px; }
.fd-pbar input[data-pbterm] { width: 80px; }
.fd-pbar .fpb-tabs { display: inline-flex; gap: 2px; }
.fd-pbar .fpb-tabs button, .fd-pbar .fpb-step { min-width: 38px; height: 32px; padding: 0 8px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-2); color: var(--text); font: 600 10.5px var(--sans); cursor: pointer; display: inline-flex; flex-direction: column; align-items: center; justify-content: center; }
.fd-pbar .fpb-tabs button b { font-size: 12px; line-height: 1; }
.fd-pbar .fpb-tabs button.on { background: #1FA34A; border-color: #1FA34A; color: #fff; }
.fd-pbar .fpb-step { font-size: 14px; }
.fd-pbar .fpb-val { min-width: 54px; text-align: center; font: 700 14px var(--sans); color: #E53935; }
#view-schematic { position: relative; }
#view-schematic.fd-barred .sch-toolbar, #view-schematic.fd-barred .fd-lib { visibility: hidden; }
#view-schematic > .fd-pbar { min-height: 52px; }
#view-schematic:not(.free-style) > .fd-pbar { display: none; }
.fd-wrap.nozoom .fd-zoom { display: none; }
.fds h4 { margin: 10px 0 6px; } .fds-row { display: flex; align-items: center; gap: 10px; margin: 6px 0; } .fds-row input[type="color"] { width: 34px; height: 26px; padding: 0; border: 0; background: none; }
.fd-pbar .fpb-dev { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); } .fd-pbar .fpb-dev input, .fd-pbar .fpb-dev select { width: auto; max-width: 140px; padding: 3px 6px; font-size: 12px; }
.free-svg .gridLine.minor { stroke: var(--fd-grid); stroke-width: .5; }
.free-svg .gridLine { stroke-width: 1; }
@media (min-width: 761px) { #view-schematic.free-style .sch-side { display: none; } }

/* =====================================================================================================
   Design system v3 — "Engineering Neutral"
   Neutral greys for surfaces, colour only for state and action (control-room practice): blue for
   interaction and selection, green = RUN / energized, amber = forced / warning, red = fault / alarm.
   One sans family for the interface, mono for addresses and values. Device drawings keep their own colours.
   ===================================================================================================== */
:root {
  --bg: #E9EDF1;
  --surface: #FFFFFF;
  --surface-2: #F3F5F8;
  --surface-3: #E3E8EE;
  --border: #D5DCE3;
  --border-strong: #B4BEC9;
  --text: #17202B;
  --muted: #5A6675;
  --accent: #1F64B8;
  --accent-strong: #174E91;
  --accent-text: #1A57A3;
  --accent-soft: #DCE8F7;
  --brand: #D97757;
  --ok: #1E8E46;
  --warn: #B87800;
  --danger: #C8362B;
  --lad-bg: #FFFFFF;
  --lad-wire: #3A4350;
  --lad-on: #1B9E48;
  --lad-hl: #CDEFD8;
  --lad-text: #1E2630;
  --canvas: #E6EAEF;
  --grid-dot: #C3CBD5;
  --grid-line: #DCE2E9;
  --wire-halo: rgba(20, 30, 45, .26);
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --shadow-lg: 0 12px 36px rgba(16, 24, 40, .20);
  --serif: var(--sans);
  --r-sm: 4px;
  --r: 6px;
  --r-lg: 8px;
  --ctl-h: 30px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0F1419; --surface: #171D24; --surface-2: #1D242C; --surface-3: #262E38; --border: #2A333E; --border-strong: #404B58;
    --text: #E4E9EF; --muted: #93A0AE; --accent: #4C8DFF; --accent-strong: #3874E0; --accent-text: #8DB6FF; --accent-soft: #1A2E4D;
    --ok: #2FB866; --warn: #E0A12A; --danger: #F0594C;
    --lad-bg: #12171D; --lad-wire: #AEB8C4; --lad-on: #3DDC75; --lad-hl: #173A26; --lad-text: #E2E8EE;
    --canvas: #12171D; --grid-dot: #2B343F; --grid-line: #1C232B; --wire-halo: rgba(228, 233, 239, .55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 8px rgba(0, 0, 0, .25);
  }
}
:root[data-theme="dark"] {
  --bg: #0F1419; --surface: #171D24; --surface-2: #1D242C; --surface-3: #262E38; --border: #2A333E; --border-strong: #404B58;
  --text: #E4E9EF; --muted: #93A0AE; --accent: #4C8DFF; --accent-strong: #3874E0; --accent-text: #8DB6FF; --accent-soft: #1A2E4D;
  --ok: #2FB866; --warn: #E0A12A; --danger: #F0594C;
  --lad-bg: #12171D; --lad-wire: #AEB8C4; --lad-on: #3DDC75; --lad-hl: #173A26; --lad-text: #E2E8EE;
  --canvas: #12171D; --grid-dot: #2B343F; --grid-line: #1C232B; --wire-halo: rgba(228, 233, 239, .55);
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 2px 8px rgba(0, 0, 0, .25);
}
body { font-size: 13.5px; }
input, select, textarea { border-radius: var(--r); }
code { border-radius: var(--r-sm); }

/* top bar: one row; the brand mark keeps the product colour */
.topbar { padding: 6px 14px; gap: 14px; }
.logo g, .logo [fill="#D97757"] { fill: var(--brand); }
.brand-title { font-size: 17px; font-weight: 700; letter-spacing: -.015em; }
.brand-sub { font-size: 11.5px; }
.save-st { border-radius: var(--r-sm); }

/* buttons: one shape, one height scale */
.btn { border-radius: var(--r); padding: 6px 13px; min-height: var(--ctl-h); }
.btn.primary { font-weight: 600; }
.icon-btn { border-radius: var(--r); }
.tbtn { border-radius: var(--r); padding: 4px 9px; min-height: 28px; border-color: var(--border); }
.tbtn.sm { min-height: 24px; }
.tbtn.on { font-weight: 600; }
.tbtn.warn { background: color-mix(in srgb, var(--warn) 18%, var(--surface)); border-color: color-mix(in srgb, var(--warn) 55%, var(--surface)); color: var(--text); }
.seg { border-radius: var(--r); }
.seg button { padding: 4px 13px; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* view tabs on a computer: a flat switcher, the active view underlined */
@media (min-width: 761px) {
  .tabs { background: transparent; border: 0; padding: 0; gap: 2px; border-radius: 0; align-self: stretch; }
  .tabs button { border-radius: var(--r) var(--r) 0 0; padding: 8px 14px; position: relative; font-weight: 600; }
  .tabs button:hover { background: var(--surface-2); }
  .tabs button.on { background: transparent; box-shadow: none; color: var(--accent-text); }
  .tabs button.on::after { content: ''; position: absolute; left: 10px; right: 10px; bottom: -7px; height: 3px; border-radius: 3px 3px 0 0; background: var(--accent); }
  .tabs button.shown:not(.on) { background: var(--surface-2); }
  .tabs .ti { color: inherit; opacity: .75; }
}
/* tablet: the top bar stays on one row */
@media (min-width: 761px) and (max-width: 1100px) {
  .topbar { flex-wrap: nowrap; gap: 8px; }
  .brand { min-width: 0; }
  .brand-sub { display: none; }
  .tabs button { padding: 8px 9px; }
  .tabs .ti { display: none; }
  .top-actions { gap: 0; flex-shrink: 0; }
  .top-actions .btn { padding: 6px 8px; }
}

/* PLC status bar: PROG is the selected mode in the interaction colour, RUN in green */
.plcbar { padding: 5px 14px; gap: 12px; }
.plcbar .mode button { padding: 3px 13px; }
.led { font-size: 10.5px; }
.led::before { background: #7D8794; }

/* ladder toolbar: tighter groups, no wrap into tall stacks on a computer */
.lad-toolbar { padding: 6px 10px; gap: 4px; align-items: center; }
.tb-group { padding: 1px 6px 1px 4px; gap: 3px; }
.tb-lbl { font-size: 9.5px; font-weight: 600; margin-right: 2px; }
.lad-status, .lad-stat-btn { border-radius: var(--r-sm); }
.ins-btn { border-radius: var(--r-sm); }
.rung-comment { font-style: normal; font-size: 12.5px; font-weight: 500; }
.rung-svg .hint { font-style: normal; }

/* panels, palette, dialogs */
.pal-item { border-radius: var(--r); }
.modal { border-radius: var(--r-lg); }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-wrap { background: rgba(10, 16, 24, .45); }
.learn-body h2 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.learn-body h3 { font-size: 18px; font-weight: 700; }
.learn-nav h3 { font-weight: 700; }

/* tablet and small laptop: every tool stays in sight (a beginner must find + Rung without scrolling), in as few rows
   as fit: groups don't break inside, group names give way to the separators */
@media (min-width: 761px) and (max-width: 1280px) {
  #main:not(.multi) .lad-toolbar { flex-wrap: wrap; row-gap: 4px; }
  #main:not(.multi) .lad-toolbar .tb-group { flex-wrap: nowrap; }
  #main:not(.multi) .lad-toolbar .tb-lbl { display: none; }
  /* the instruction palette takes the rest of its row; only its buttons and tabs scroll, like a ribbon */
  #main:not(.multi) .lad-toolbar .lad-ins { flex: 1 1 320px; min-width: 0; }
  #main:not(.multi) .lad-ins .ins-row, #main:not(.multi) .lad-ins .ins-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  #main:not(.multi) .lad-ins .ins-row > *, #main:not(.multi) .lad-ins .ins-tabs > * { flex-shrink: 0; }
  #main:not(.multi) .lad-toolbar .tb-addr select { max-width: 132px; }
  #main:not(.multi) .lad-toolbar .zoomv { min-width: 0; padding: 4px 6px; }
}
/* up to 1024 px the bar above is the controller (PROG / RUN and its lights) and the ladder's status box steps back */
@media (min-width: 761px) and (max-width: 1024px) {
  #main:not(.multi) .lad-toolbar .lad-status { display: none; }
  body[data-solo="ladder"] .plcbar .leds { display: flex; }
}

/* the visually hidden instruction names stay inside their button: without a positioned parent they escaped the
   scrolling toolbar and widened the page (sideways panning on phones) */
.ins-btn { position: relative; }

/* one set of controller lights: on the Ladder alone its status box (RUN / OK / BAT / I/O, forces, path) is the
   controller, so the bar's POWER / RUN / FORCE / FAULT lights step back; every other view and side-by-side layout keeps them */
body[data-solo="ladder"] .plcbar .leds { display: none; }
/* the I/O strip is shown whole or not at all: below 1100 px it would be cut to a few cells (the Data panel has the I/O) */
@media (max-width: 1100px) { .plcbar .io-strip { display: none; } }

/* Organizer: a project tree like engineering tools have — no bullets or underlined links, indent guides, row hover */
.lad-org .org, .lad-org .org ul { list-style: none; margin: 0; }
.lad-org .org { padding: 0 8px 8px 8px; line-height: 1.65; }
.lad-org .org ul { padding-left: 12px; margin-left: 7px; border-left: 1px solid var(--border); }
.lad-org .org li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lad-org .org a { color: var(--text); text-decoration: none; padding: 1px 5px; border-radius: var(--r-sm); }
.lad-org .org a:hover { background: var(--accent-soft); color: var(--accent-text); }
.lad-org .org a[aria-current] { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.lad-org .org small { color: var(--muted); }
.lad-org .org .org-add, .lad-org .org-add { color: var(--accent-text); }
.lad-org .side-head, .lad-org h5 { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; color: var(--muted); }

/* HMI Studio: objects in labelled groups (Controls, Indicators, Equipment, Drawing) instead of one run of 17 buttons */
.hmi-add { display: flex; flex-wrap: wrap; gap: 4px 0; align-items: center; }
.hmi-addg { display: inline-flex; align-items: center; gap: 3px; padding: 0 8px; border-left: 1px solid var(--border); }
.hmi-addg:first-child { border-left: 0; padding-left: 0; }
.hmi-addg .tbtn { padding: 3px 8px; font-size: 12.5px; }
@media (max-width: 760px) { .hmi-add, .hmi-addg { flex-wrap: nowrap; flex-shrink: 0; } }

/* lists in the side panels (HMI screens, tag lists): rows, not bullets with underlined links */
.hmi-props .taglist { list-style: none; padding: 0; margin: 4px 0 8px; }
.hmi-props .taglist li { padding: 2px 4px; border-radius: var(--r-sm); }
.hmi-props .taglist a { color: var(--text); text-decoration: none; font-weight: 500; }
.hmi-props .taglist a:hover { color: var(--accent-text); }

/* Errors pane: a line about a rung is a link to it */
.lad-out-log .ol-go { cursor: pointer; border-radius: var(--r-sm); }
.lad-out-log .ol-go:hover, .lad-out-log .ol-go:focus-visible { background: var(--accent-soft); text-decoration: underline; }
.lad-out-log .ol-go.e { color: var(--danger); }
.lad-out-log .ol-go.w { color: var(--warn); }

/* destructive primary action */
.btn.primary.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.primary.danger:hover { filter: brightness(.92); }

/* a long project name is cut with … instead of widening the top bar (the full name is in File → Open project) */
.brand > div { min-width: 0; }
.brand-sub { white-space: nowrap; }
.brand-sub [data-pname] { display: inline-block; max-width: 260px; overflow: hidden; text-overflow: ellipsis; vertical-align: bottom; }

/* Find an instruction, at the end of the palette tabs */
.ins-find { margin-left: auto; width: 96px; height: 20px; padding: 1px 6px; font-size: 11px; border-radius: var(--r-sm); align-self: center; }
.ins-find:focus { width: 150px; }

/* icon set (UI.icon / UI.iconize): one stroke weight and size everywhere; an icon before a label keeps a small gap */
.ic { width: 16px; height: 16px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: -3px; }
.ic { margin-right: 5px; }
.ic.solo { margin-right: 0; }
.icon-btn .ic { width: 18px; height: 18px; vertical-align: middle; }
.btn .ic { width: 15px; height: 15px; }

/* instruction palette: a glyph button names its mnemonic under the glyph (XIC, OTE…), so a beginner can read the palette;
   box instructions already show their mnemonic. Side-by-side layouts keep the compact one-line buttons */
#main:not(.multi) .ins-btn.show:has(.mono) { flex-direction: column; height: 34px; min-width: 40px; gap: 1px; }
#main:not(.multi) .ins-btn .mono + small { position: static; width: auto; height: auto; overflow: visible; clip: auto; font: 600 8.5px var(--sans); color: var(--muted); letter-spacing: .03em; line-height: 1; }
#main:not(.multi) .ins-btn.show { border-color: var(--border); background: var(--surface); }
#main:not(.multi) .ins-btn.show:hover { border-color: var(--accent); background: var(--accent-soft); }

/* Properties of the selected instruction (top of the Ladder side panel) */
.lad-props { border-bottom: 1px solid var(--border); }
.lad-props .lp-body { padding: 0 12px 12px; display: flex; flex-direction: column; gap: 8px; }
.lad-props .lp-title { font-size: 14px; } .lad-props .lp-title b { font-family: var(--mono); }
.lad-props .lp-sub { font-size: 12px; color: var(--muted); margin-top: -4px; }
.lp-ops { width: 100%; border-collapse: collapse; font-size: 12px; }
.lp-ops th { text-align: left; font-weight: 500; color: var(--muted); padding: 3px 6px 3px 0; white-space: nowrap; }
.lp-ops td { padding: 3px 4px; border-top: 1px solid var(--border); } .lp-ops tr:first-child td { border-top: 0; }
.lp-ops .lp-live { color: var(--ok); font-weight: 600; font-size: 11.5px; padding-top: 0; }
.lp-ops .lp-liverow td { border-top: 0; }
.lp-note { font-size: 12px; padding: 6px 8px; border-radius: var(--r); background: var(--surface-2); }
.lp-uses { display: flex; flex-direction: column; gap: 3px; font-size: 12px; } .lp-uses > span { color: var(--muted); font-weight: 600; }
.lp-uses small { color: var(--muted); }
.lp-go { text-align: left; border: 0; background: transparent; color: var(--accent-text); font: 500 12px var(--mono); padding: 2px 4px; border-radius: var(--r-sm); }
.lp-go:hover { background: var(--accent-soft); }

/* the ladder toolbar groups are told apart by their separators: the group names only show on very wide screens */
@media (max-width: 1700px) { #main:not(.multi) .lad-toolbar .tb-lbl { display: none; } }

/* parts library header: on a narrow panel the two buttons keep only their icons (the name is in the tooltip) instead of being cut */
@media (max-width: 1100px) { .pal-tools .tbtn { font-size: 0; padding: 4px; } .pal-tools .tbtn .ic { margin-right: 0; } .ws-search { font-size: 12.5px; } }

/* the update notice floats in the bottom-right corner: it arrives a few seconds after start and used to push the whole
   layout down under the user's pointer (a click meant for one thing hit another) */
.update-bar { position: fixed; right: 16px; bottom: 44px; z-index: 60; max-width: min(460px, calc(100% - 32px)); justify-content: flex-start; padding: 10px 12px; border: 1px solid var(--accent); border-radius: var(--r-lg); box-shadow: var(--shadow-lg); background: var(--surface); }
@media (max-width: 760px) { .update-bar { left: 12px; right: 12px; bottom: calc(70px + env(safe-area-inset-bottom, 0px)); max-width: none; } }

/* view tabs: drawn icons (the same size on every platform, unlike text glyphs); the project name gives way to the save state */
.tabs .ti { display: inline-flex; line-height: 0; }
.tabs .ti svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 760px) { .tabs .ti svg { width: 20px; height: 20px; } }
.brand-sub { display: flex; align-items: center; min-width: 0; }
.brand-sub [data-pname] { min-width: 0; flex: 0 1 auto; }
.brand-sub .save-st { flex: none; }
@media (min-width: 761px) and (max-width: 1100px) { .brand-sub, .tabs .ti { display: none; } }
/* Wiring: the zoom buttons and Fit stay together (Fit used to wrap to a row of its own) */
.ws-zoom { display: inline-flex; align-items: center; gap: 6px; flex: none; }
@media (min-width: 761px) and (max-width: 1280px) { .ws-toolbar .tb-lbl { display: none; } .ws-toolbar { gap: 6px; } }
/* Data Files: an ON bit is green (energized), so it is not mistaken for a forced one (amber) */
.io-led.on, .io-row[data-io^="O"] .io-led.on, .io-strip i.on.in, .io-strip i.on.out { background: var(--ok); border-color: var(--ok); box-shadow: 0 0 5px color-mix(in srgb, var(--ok) 60%, transparent); }
/* up to 1024 px (repeated here: the rules above lost to later ones) the bar above is the controller and the ladder status box steps back, so the instruction palette gets the room */
@media (min-width: 761px) and (max-width: 1024px) {
  #main:not(.multi) .lad-toolbar .lad-status { display: none !important; }
  body[data-solo="ladder"] .plcbar .leds { display: flex; }
}
/* Data Files beside the ladder: all 16 bits fit the panel (bit 0, the one used most, was scrolled out of sight) */
.lad-dt table.dt.bits { table-layout: fixed; font-size: 10px; }
.lad-dt table.dt.bits td, .lad-dt table.dt.bits th { min-width: 0; padding-left: 0; padding-right: 0; }
.lad-dt table.dt.bits th.rowh { width: 32px; padding-right: 4px; }
.lad-dt table.dt.bits th:not(.rowh) { font-size: 8px; letter-spacing: -.4px; }
/* the task of the open exercise, above the work */
.task-strip { display: flex; align-items: center; gap: 10px; padding: 5px 12px; background: color-mix(in srgb, var(--accent) 9%, var(--surface)); border-bottom: 1px solid var(--border); font-size: 12.5px; min-width: 0; }
.task-strip[hidden] { display: none; }
.task-strip .ts-kind { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--accent-text); flex: none; }
.task-strip .ts-title { flex: none; white-space: nowrap; }
.task-strip .ts-task { flex: 1 1 auto; min-width: 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.task-strip button { flex: none; }
@media (max-width: 760px) { .task-strip .ts-task, .task-strip .ts-kind { display: none; } .task-strip .ts-title { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; } }
/* Electrical Diagram: the empty-drawing hint wraps inside the view */
.fd-empty { position: absolute; left: 16px; right: 16px; top: 14px; display: flex; flex-direction: column; gap: 2px; color: var(--muted); font-size: 12.5px; pointer-events: none; }
.fd-empty b { color: var(--text); font-weight: 600; }
/* the Errors pane head stays one tidy row (on a phone the chips wrapped and Rung n of m was cut) */
.lad-out .oc, .lad-rungpos { white-space: nowrap; }
.lad-out-head { min-width: 0; }
@media (max-width: 760px) { .lad-out .oc { padding: 1px 6px; min-height: 28px; } .lad-out-head { gap: 3px; padding: 2px 6px; } }
/* the Ladder beside other views (Workbench): a compact toolbar. The bar above is the controller (its lights show when
   the Ladder is not alone), the instruction palette is one scrolling row with its tabs, and the groups wrap as a whole */
#main.multi .lad-toolbar { flex-wrap: wrap; row-gap: 4px; column-gap: 6px; }
#main.multi .lad-toolbar .tb-group { flex-wrap: wrap; border-right: 0; padding-right: 0; row-gap: 4px; }
#main.multi .lad-toolbar .tb-lbl, #main.multi .lad-toolbar .lad-status { display: none !important; }
#main.multi .lad-toolbar .lad-ins { flex: 1 1 100%; min-width: 0; }
#main.multi .lad-ins .ins-row, #main.multi .lad-ins .ins-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
#main.multi .lad-ins .ins-row > *, #main.multi .lad-ins .ins-tabs > * { flex-shrink: 0; }
/* the groups after the instruction palette: no box of their own on a computer or tablet */
.lad-more { display: contents; }
/* phone: the instruction palette is a row of its own, and every other tool is one scrolling row under it with + Rung
   first (one long row hid + Rung far to the right). The bar above is the controller. */
@media (max-width: 760px) {
  .lad-toolbar { flex-wrap: wrap; overflow-x: visible; row-gap: 4px; }
  .lad-toolbar .lad-status { display: none !important; }
  .lad-toolbar .lad-ins { flex: 1 1 100%; min-width: 0; }
  .lad-ins .ins-row, .lad-ins .ins-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .lad-ins .ins-row > *, .lad-ins .ins-tabs > * { flex-shrink: 0; }
  .lad-more { display: flex; flex: 1 1 100%; min-width: 0; gap: 6px; overflow-x: auto; scrollbar-width: none; }
  .lad-more > .tb-group { flex: none; flex-wrap: nowrap; }
  .lad-more > .tb-group:has([data-act="rung"]) { order: -1; }
}
/* UI/UX standards pass (ui-ux-design-master audit, 2026-10-23) */
/* a dialog never grows wider than the screen: a long option (a select) used to push it past a phone (OK and × cut off) */
.modal { max-width: calc(100vw - 32px); min-width: 0; }
.modal-body select, .modal-body input, .modal-body textarea { max-width: 100%; min-width: 0; }
@media (max-width: 760px) { .modal-wrap { grid-template-columns: minmax(0, 1fr); } .modal { max-width: 100vw; } }
/* the PLC bar scrolls inside itself when it is too long (long Tagalog words): the page no longer grows sideways */
.plcbar { min-width: 0; max-width: 100%; overflow-x: auto; scrollbar-width: none; }
.plcbar::-webkit-scrollbar { display: none; }
/* fills that carry white text reach 4.5:1 (WCAG 1.4.3) in both themes: green RUN 2.6:1 and dark-theme blue 3.2:1 were too light */
:root { --fill-accent: var(--accent); --fill-ok: #1E7F3F; --fill-danger: #C0392B; --on-warn: #1A1300; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --fill-accent: #2F6AD6; } }
:root[data-theme="dark"] { --fill-accent: #2F6AD6; }
.btn.primary { background: var(--fill-accent); border-color: var(--fill-accent); }
.tbtn.on, .seg button.on, .lad-ghost { background: var(--fill-accent); border-color: var(--fill-accent); }
.plcbar .mode button[data-mode="RUN"].on, .conn-chip.on, tr.k-mode .evk { background: var(--fill-ok); color: #fff; }
tr.k-alarm .evk { background: var(--fill-danger); }
tr.k-force .evk { color: var(--on-warn); }
.btn.primary.danger { background: var(--fill-danger); border-color: var(--fill-danger); }
/* an ON bit's 1 in the data tables: dark green text on the pale green cell (2.8:1 → 5.4:1 in light; dark keeps its bright green) */
:root { --lad-on-text: #116B30; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --lad-on-text: var(--lad-on); } }
:root[data-theme="dark"] { --lad-on-text: var(--lad-on); }
table.dt td.bit.on { color: var(--lad-on-text); }
/* no interface text under 11 px (it was down to 8 px). Drawings (ladder rungs, diagram, terminal screens) follow their zoom instead */
.save-st, .beta-tag, .badge, .tb-lbl, .lad-stat-btn .caret, .lad-stat-lines, .st-box, .ins-tab, .io-force, .io-btns button, .pal-item span,
.learn-nav h6, .led, .fd-nm, .task-strip .ts-kind, .ins-btn .boxico { font-size: 11px; }
.lad-leds { font-size: 11px; }
#main:not(.multi) .ins-btn .mono + small { font-size: 11px; }
.lad-dt table.dt.bits { font-size: 11px; }
.lad-dt table.dt.bits th:not(.rowh) { font-size: 11px; letter-spacing: -.6px; }
/* every control is at least 24 × 24 px (WCAG 2.5.8): F1 / F0 / × in the Data Files were 18 px, the Wiring colour swatches 18 px */
.io-btns button { min-width: 24px; min-height: 24px; }
.ins-tab, .lad-stat-btn, .ins-find, .lad-out .oc { min-height: 24px; }
.oc-tog { min-width: 24px; min-height: 24px; }
.ws-toolbar .sw { width: 24px; height: 24px; }
/* the instruction palette stays inside its own box at every width: its button row and its tabs scroll like a ribbon
   (with longer Tagalog words it ran under the program file list at 1280 px) */
.lad-toolbar .lad-ins { min-width: 0; max-width: 100%; }
.lad-ins .ins-row, .lad-ins .ins-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
.lad-ins .ins-row > *, .lad-ins .ins-tabs > * { flex-shrink: 0; }
@media (min-width: 1281px) { #main:not(.multi) .lad-toolbar .lad-ins { flex: 0 1 600px; } }
/* the top bar keeps one row on a tablet: the name and the view tabs do not wrap */
.brand-title, .tabs button { white-space: nowrap; }
@media (min-width: 761px) and (max-width: 1100px) { .tabs { flex-wrap: nowrap; min-width: 0; } .brand { min-width: 0; } .tabs button { padding: 7px 8px; } }
/* the 16-bit grid of a data file shows bit 0 first (as the reference software, bit 0 on the right): it scrolls from the right */
.lad-dt table.dt.bits { display: block; max-width: 100%; overflow-x: auto; scrollbar-width: thin; }
.lad-dt table.dt.bits th:not(.rowh) { letter-spacing: 0; }
.lad-dt table.dt.bits td, .lad-dt table.dt.bits th { min-width: 15px; padding-left: 1px; padding-right: 1px; }
.lad-ins > .ins-row, .lad-ins > .ins-tabs { align-self: stretch; min-width: 0; max-width: 100%; }
.ins-btn small { font-size: 11px; }
/* amber text (saving, warnings) reaches 4.5:1 on light surfaces; the dark theme keeps its bright amber */
:root { --warn-text: #8A5A00; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --warn-text: var(--warn); } }
:root[data-theme="dark"] { --warn-text: var(--warn); }
.save-st.pending, .warn-txt, .org .flt, .verify li.w, .lad-out-log .ol-go.w { color: var(--warn-text); }
/* small print in the interface is at least 11 px too (the operator-panel drawings keep their own scale) */
small:not(.hmi small):not(svg small) { font-size: max(11px, .85em); }
