/* PLC Lab — dark industrial aesthetic (aligned with Switch CLI Lab) */
:root {
  --bg: #0b0f14;
  --bg-elev: #121820;
  --bg-panel: #0e141c;
  --border: #1e2a38;
  --border-strong: #2a3a4d;
  --text: #e6edf5;
  --text-dim: #8b9bb0;
  --text-mute: #5c6b7e;
  --accent: #3d9cf0;
  --accent-soft: rgba(61, 156, 240, 0.12);
  --ml: #f0a030;
  --clx: #3d9cf0;
  --ctl: #c45cff;
  --success: #3ecf8e;
  --warn: #e6b84d;
  --danger: #f07178;
  --term-bg: #070b10;
  --term-cyan: #79c0ff;
  --radius: 10px;
  --font: "IBM Plex Sans", system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, monospace;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.9em;
  color: var(--term-cyan);
}

a {
  color: var(--accent);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 0;
}

/* Top bar */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.65rem 1.15rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #121a24 0%, var(--bg-panel) 100%);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 1.15rem;
}

.brand h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.tagline {
  margin: 0.1rem 0 0;
  font-size: 0.75rem;
  color: var(--text-mute);
}

.network-chip {
  display: flex;
  flex-direction: column;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  min-width: 8rem;
}

.network-chip-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
}

.top-actions,
.top-right {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-left: auto;
}

.top-right {
  margin-left: 0;
}

.user-chip {
  font-size: 0.85rem;
  color: var(--success);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  background: rgba(62, 207, 142, 0.1);
  border: 1px solid rgba(62, 207, 142, 0.25);
}

.save-status {
  font-size: 0.75rem;
  color: var(--text-mute);
  min-width: 3.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-strong);
  background: var(--bg-elev);
  cursor: pointer;
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s, border-color 0.12s;
}

.btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.btn.primary {
  background: var(--accent);
  border-color: transparent;
  color: #061018;
  font-weight: 600;
}

.btn.primary:hover {
  filter: brightness(1.08);
  background: var(--accent);
}

.btn.ghost {
  background: transparent;
}

.btn.danger {
  border-color: rgba(240, 113, 120, 0.45);
  color: var(--danger);
}

.btn.danger:hover {
  background: rgba(240, 113, 120, 0.12);
}

.btn.small,
.btn-sm {
  padding: 0.28rem 0.55rem;
  font-size: 0.82rem;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Main layout */
.main {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr) 240px;
  flex: 1;
  min-height: 0;
}

.sidebar,
.rightbar {
  border-right: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.rightbar {
  border-right: none;
  border-left: 1px solid var(--border);
  padding: 1rem;
  overflow: auto;
}

.rightbar h2 {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-mute);
}

.side-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.side-tab {
  flex: 1;
  min-width: 4.2rem;
  padding: 0.55rem 0.35rem;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 0.78rem;
  border-bottom: 2px solid transparent;
}

.side-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
  background: rgba(61, 156, 240, 0.06);
}

.side-panels {
  flex: 1;
  overflow: auto;
  padding: 0.85rem;
}

.side-panel h3 {
  margin: 0.75rem 0 0.4rem;
  font-size: 0.85rem;
}

.panel-intro {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.net-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
}

.net-section-head h3 {
  margin: 0;
}

.net-list,
.link-list {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.net-item-btn {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.35rem;
}

.net-item.active .net-item-btn,
.net-item-btn:hover {
  border-color: var(--accent);
}

.muted {
  color: var(--text-mute);
  font-size: 0.8rem;
}

.muted.small,
.small {
  font-size: 0.75rem;
}

.net-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.summary-card,
.cfg-form,
.builder-block,
.inspector {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--bg-elev);
  margin-bottom: 0.75rem;
}

.summary-dl {
  margin: 0;
  display: grid;
  gap: 0.25rem;
}

.summary-dl div {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.82rem;
}

.summary-dl dt {
  color: var(--text-mute);
}

.summary-dl dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 0.78rem;
}

.cfg-form label,
.builder-block label,
.auth-form label,
.tag-form,
.rung-form label,
.inline-field {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  margin-bottom: 0.45rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.inline-field {
  flex-direction: row;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.5rem;
}

.inline-field span {
  min-width: 3rem;
}

input,
select {
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--term-bg);
}

.builder-block select,
.builder-block .btn {
  width: 100%;
  margin-bottom: 0.35rem;
}

.family-picker {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 0.75rem;
}

.family-card {
  text-align: left;
  padding: 0.65rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  cursor: pointer;
  border-left: 3px solid var(--fam, var(--accent));
}

.family-card strong {
  display: block;
  margin-bottom: 0.2rem;
}

.family-card span {
  font-size: 0.75rem;
  color: var(--text-mute);
}

.family-card.active {
  border-color: var(--fam, var(--accent));
  background: var(--accent-soft);
}

/* Workspace */
.workspace {
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
  background: var(--bg);
}

.ws-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-panel);
}

.ws-tab {
  padding: 0.6rem 1rem;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}

.ws-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.ws-view {
  flex: 1;
  overflow: auto;
  padding: 0.85rem 1rem;
  min-height: 0;
}

.ws-view.active {
  display: block;
}

/* Chassis */
.chassis-view {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.chassis-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  overflow: hidden;
}

.chassis-card.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(61, 156, 240, 0.25);
}

.chassis-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
  cursor: pointer;
}

.pill {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.45rem;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}

.slot-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
  padding: 0.75rem;
}

.slot-cell {
  border: 1px dashed var(--border-strong);
  border-radius: 8px;
  padding: 0.45rem;
  background: var(--term-bg);
}

.slot-cell.filled {
  border-style: solid;
  border-color: rgba(62, 207, 142, 0.35);
}

.slot-label {
  font-size: 0.7rem;
  color: var(--text-mute);
  margin-bottom: 0.25rem;
}

.slot-cell select {
  width: 100%;
  font-size: 0.75rem;
}

.slot-meta {
  margin-top: 0.25rem;
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--success);
}

/* Topology */
.topo-toolbar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.topo-host {
  height: min(420px, 50vh);
  border: 1px solid var(--border);
  border-radius: 12px;
  background:
    radial-gradient(circle at 20% 20%, rgba(61, 156, 240, 0.05), transparent 40%),
    var(--term-bg);
  position: relative;
  overflow: hidden;
}

.topo-canvas {
  width: 100%;
  height: 100%;
  position: relative;
}

.topo-svg {
  width: 100%;
  height: 100%;
}

.topo-link {
  stroke: #3d9cf0;
  stroke-width: 2;
  stroke-dasharray: 4 3;
  opacity: 0.75;
}

.topo-node-body {
  fill: #151d28;
  stroke: #2a3a4d;
  stroke-width: 1.5;
}

.topo-node-body.selected {
  stroke: var(--accent);
  stroke-width: 2.5;
}

.topo-node-controller .topo-node-body {
  stroke: #c45cff;
}

.topo-node-remote .topo-node-body {
  stroke: #f0a030;
}

.topo-node-title {
  fill: var(--text);
  font-size: 11px;
  font-family: var(--font);
  font-weight: 600;
}

.topo-node-sub {
  fill: var(--text-mute);
  font-size: 9px;
  font-family: var(--mono);
}

.topo-empty {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--text-mute);
  pointer-events: none;
}

/* Tags / tables */
.view-toolbar,
.tag-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
  align-items: center;
}

.tag-form {
  flex-direction: row;
}

.tag-form input,
.tag-form select {
  flex: 1;
  min-width: 8rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th,
.data-table td {
  text-align: left;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  color: var(--text-mute);
  font-weight: 500;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Ladder */
.rung-form {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--bg-elev);
  margin-bottom: 0.85rem;
}

.instr-rows {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin: 0.5rem 0;
}

.instr-row {
  display: grid;
  grid-template-columns: 5rem 1fr 5rem auto;
  gap: 0.35rem;
  align-items: center;
}

.rung-form-actions {
  display: flex;
  gap: 0.4rem;
}

.rung-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.rung-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  margin-bottom: 0.4rem;
  background: var(--term-bg);
}

.rung-head {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
}

.rung-num {
  font-size: 0.75rem;
  color: var(--text-mute);
}

.rung-comment {
  flex: 1;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.rung-body {
  color: var(--term-cyan);
  font-size: 0.85rem;
}

/* Training */
.train-level h3 {
  margin: 0.5rem 0 0.35rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
}

.train-modules {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}

.train-btn {
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.3rem;
}

.train-item.active .train-btn {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.train-item.done .train-btn {
  border-color: rgba(62, 207, 142, 0.4);
}

.train-title {
  font-weight: 500;
}

.train-meta {
  font-size: 0.72rem;
  color: var(--text-mute);
}

.skills-overall {
  font-family: var(--mono);
  color: var(--accent);
  margin: 0 0 0.75rem;
}

.skills-grid {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.skill-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.7rem;
  background: var(--bg-elev);
}

.skill-card.complete {
  border-color: rgba(62, 207, 142, 0.4);
}

.skill-bar {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0.4rem 0;
  overflow: hidden;
}

.skill-bar div {
  height: 100%;
  background: var(--success);
}

/* Walk strip */
.walk-active {
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  padding: 0.75rem 1rem;
  flex-shrink: 0;
  max-height: 40%;
  overflow: auto;
}

.walk-active-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.45rem;
}

.walk-badge {
  display: inline-block;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-right: 0.35rem;
}

.walk-badge.level-basic {
  color: var(--success);
  background: rgba(62, 207, 142, 0.12);
}

.walk-badge.level-intermediate {
  color: var(--warn);
  background: rgba(230, 184, 77, 0.12);
}

.walk-badge.level-advanced {
  color: var(--ctl);
  background: rgba(196, 92, 255, 0.12);
}

.walk-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 0.45rem;
}

.walk-progress-bar {
  height: 100%;
  width: 0;
  background: var(--success);
  transition: width 0.2s;
}

.walk-status {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  color: var(--text-dim);
}

.walk-status.ok {
  color: var(--success);
}

.walk-steps {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.walk-step-row {
  display: flex;
  gap: 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.85rem;
  opacity: 0.65;
}

.walk-step-row.current {
  opacity: 1;
  background: var(--accent-soft);
}

.walk-step-row.ok {
  opacity: 0.85;
  color: var(--success);
}

.walk-check {
  width: 1.4rem;
  height: 1.4rem;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  font-size: 0.75rem;
  flex-shrink: 0;
}

.walk-step-row.ok .walk-check {
  border-color: var(--success);
  color: var(--success);
}

.walk-hint-line {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--warn);
}

/* Right tips */
.tips-list {
  margin: 0 0 1.25rem;
  padding-left: 1.1rem;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.tips-list li {
  margin-bottom: 0.4rem;
}

.diff-card {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem;
  background: var(--bg-elev);
  font-size: 0.82rem;
  color: var(--text-dim);
}

.diff-card p {
  margin: 0 0 0.5rem;
}

.diff-card p:last-child {
  margin: 0;
}

/* Modal / toast */
.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.modal-card {
  position: relative;
  width: min(400px, 92vw);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 1rem 1.15rem 1.15rem;
}

.modal-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.modal-card h2 {
  margin: 0;
  font-size: 1.05rem;
}

.auth-form label {
  margin-bottom: 0.65rem;
}

.auth-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0 0 0.5rem;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 60;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
  max-width: 22rem;
}

.toast.show {
  opacity: 1;
}

.toast.ok {
  border-color: rgba(62, 207, 142, 0.45);
  color: var(--success);
}

.toast.err {
  border-color: rgba(240, 113, 120, 0.45);
  color: var(--danger);
}

.toast.warn {
  border-color: rgba(230, 184, 77, 0.45);
  color: var(--warn);
}

.toast[hidden] {
  display: block;
}

/* Responsive */
@media (max-width: 1100px) {
  .main {
    grid-template-columns: 280px minmax(0, 1fr);
  }
  .rightbar {
    display: none;
  }
}

@media (max-width: 760px) {
  .main {
    grid-template-columns: 1fr;
  }
  .sidebar {
    max-height: 40vh;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}

/* ═══════════════════════════════════════════════════════════════
   Studio 5000–style ladder editor
   ═══════════════════════════════════════════════════════════════ */

.studio-chrome {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  margin: -0.85rem -1rem;
  padding: 0;
}

.studio-runbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a2430 0%, #121a24 100%);
  flex-shrink: 0;
}

.studio-runbar-left,
.studio-runbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.studio-scan-meta {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-mute);
  margin-left: 0.35rem;
}

.studio-split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  flex: 1;
  min-height: 0;
}

.studio-editor-pane {
  overflow: auto;
  min-width: 0;
  border-right: 1px solid var(--border);
  background: #0a0e13;
}

.studio-watch-pane {
  overflow: auto;
  background: var(--bg-panel);
  min-height: 0;
}

.ladder-editor {
  min-height: 100%;
}

.studio-ladder {
  font-size: 12px;
}

.studio-path {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  padding: 0.4rem 0.75rem;
  background: #15202b;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-dim);
}

.studio-path-root { color: var(--text-mute); }
.studio-path-sep { color: var(--text-mute); opacity: 0.6; }
.studio-path-leaf { color: var(--accent); font-weight: 600; }

.studio-mode-pill {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 0.7rem;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
}

.studio-mode-pill.run {
  color: #061018;
  background: var(--success);
  border-color: transparent;
  font-weight: 700;
}

.studio-mode-pill.prog {
  color: var(--warn);
  background: rgba(230, 184, 77, 0.12);
  border-color: rgba(230, 184, 77, 0.35);
}

.studio-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: #101820;
}

.studio-tb-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.2rem;
}

.studio-tb-label {
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
  margin-right: 0.2rem;
}

.studio-tb-btn {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.22rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: #1a2533;
  color: var(--text);
  cursor: pointer;
}

.studio-tb-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.studio-tb-btn.active {
  background: var(--accent);
  color: #061018;
  border-color: transparent;
}

.studio-rung-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-panel);
}

.studio-hint { font-size: 0.78rem; }

.studio-sheet {
  padding: 0.5rem 0.35rem 2rem;
}

.studio-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-dim);
}

.studio-rung {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  border: 1px solid var(--border);
  border-radius: 6px;
  margin: 0 0.4rem 0.55rem;
  background: #0d1218;
  overflow: hidden;
}

.studio-rung.selected {
  border-color: rgba(61, 156, 240, 0.55);
  box-shadow: 0 0 0 1px rgba(61, 156, 240, 0.15);
}

.studio-gutter {
  background: #151c26;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.35rem 0.15rem;
  gap: 0.25rem;
  cursor: pointer;
}

.studio-rung-no {
  font-family: var(--mono);
  font-weight: 600;
  color: var(--text-dim);
  font-size: 0.85rem;
}

.studio-gutter-acts {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.btn.tiny {
  padding: 0.05rem 0.3rem;
  font-size: 0.7rem;
  min-width: 1.4rem;
}

.studio-rung-body {
  padding: 0.25rem 0.4rem 0.45rem;
  min-width: 0;
}

.studio-comment-input {
  width: 100%;
  border: none;
  background: transparent;
  color: #7eb8a0;
  font-style: italic;
  font-size: 0.78rem;
  padding: 0.15rem 0.25rem;
  margin-bottom: 0.2rem;
}

.studio-comment-input:focus {
  outline: 1px solid var(--border-strong);
  border-radius: 4px;
  background: rgba(0, 0, 0, 0.25);
}

.studio-network {
  display: flex;
  align-items: stretch;
  min-height: 72px;
  gap: 0;
}

.studio-power-rail {
  width: 5px;
  flex-shrink: 0;
  background: #3a4a5c;
  border-radius: 1px;
  align-self: stretch;
  min-height: 56px;
}

.studio-power-rail.live {
  background: #3ecf8e;
  box-shadow: 0 0 8px rgba(62, 207, 142, 0.45);
}

.studio-columns {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  flex: 1;
  gap: 0;
  min-width: 0;
  padding: 0.15rem 0;
}

.studio-col {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  position: relative;
  padding: 0 2px;
}

.studio-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 88px;
  max-width: 140px;
  padding: 0.2rem 0.35rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 4px;
  cursor: pointer;
  background: transparent;
}

.studio-cell:hover {
  background: rgba(61, 156, 240, 0.06);
}

.studio-cell.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.studio-cell.energized .ld-glyph,
.ld-glyph.hot {
  color: var(--success);
  filter: drop-shadow(0 0 3px rgba(62, 207, 142, 0.5));
}

.studio-cell.branch {
  margin-top: 0.15rem;
}

.studio-branch-join {
  height: 10px;
  width: 2px;
  margin: 0 auto;
  background: #4a5d72;
}

.studio-type-lab {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--text-mute);
  letter-spacing: 0.03em;
}

.studio-tag-line {
  display: flex;
  flex-wrap: wrap;
  gap: 0.15rem;
  justify-content: center;
  width: 100%;
  margin-bottom: 0.1rem;
}

.studio-tag-input,
.studio-pre-input {
  width: 100%;
  max-width: 120px;
  font-family: var(--mono);
  font-size: 0.68rem;
  padding: 0.12rem 0.25rem;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: #0a1018;
  text-align: center;
}

.studio-pre-input {
  max-width: 56px;
}

.studio-glyph-wrap {
  display: flex;
  justify-content: center;
  width: 100%;
  min-height: 28px;
  align-items: center;
}

.ld-glyph {
  display: inline-flex;
  align-items: center;
  color: #c5d0dc;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.ld-rail {
  display: inline-block;
  width: 10px;
  height: 2px;
  background: currentColor;
  opacity: 0.7;
}

.ld-contact,
.ld-coil {
  padding: 0 0.1rem;
}

.ld-box-body {
  display: inline-block;
  border: 1.5px solid currentColor;
  border-radius: 2px;
  padding: 0.15rem 0.35rem;
  font-size: 0.68rem;
  line-height: 1.2;
  text-align: center;
  min-width: 52px;
}

.ld-box-lines {
  display: flex;
  flex-direction: column;
  font-weight: 400;
  font-size: 0.6rem;
  opacity: 0.9;
  margin-top: 0.1rem;
}

.ld-box-sm {
  border: 1px solid currentColor;
  padding: 0.1rem 0.25rem;
  font-size: 0.65rem;
  border-radius: 2px;
}

.studio-el-del {
  position: absolute;
  top: 0;
  right: 0;
  border: none;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 0 0.25rem;
  line-height: 1.2;
  opacity: 0;
}

.studio-cell:hover .studio-el-del {
  opacity: 1;
}

.studio-el-del:hover {
  color: var(--danger);
}

.studio-val-badge {
  font-family: var(--mono);
  font-size: 0.6rem;
  color: var(--term-cyan);
  margin-top: 0.1rem;
}

.studio-append-zone {
  align-self: center;
  width: 28px;
  height: 28px;
  margin: 0 0.35rem;
  border: 1px dashed var(--border-strong);
  border-radius: 6px;
  background: transparent;
  color: var(--text-mute);
  cursor: pointer;
  font-size: 1rem;
  flex-shrink: 0;
}

.studio-append-zone:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}

/* Watch panel */
.watch-panel {
  padding: 0.65rem;
}

.watch-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  margin-bottom: 0.55rem;
}

.watch-head strong {
  font-size: 0.85rem;
}

.watch-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
}

.watch-table th {
  text-align: left;
  color: var(--text-mute);
  font-weight: 500;
  font-size: 0.68rem;
  text-transform: uppercase;
  padding: 0.25rem 0.3rem;
  border-bottom: 1px solid var(--border);
}

.watch-table td {
  padding: 0.28rem 0.3rem;
  border-bottom: 1px solid rgba(30, 42, 56, 0.8);
  vertical-align: middle;
}

.watch-bool {
  font-family: var(--mono);
  font-weight: 700;
  min-width: 2rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  cursor: pointer;
  background: #1a2030;
  color: var(--text-dim);
}

.watch-bool.on {
  background: rgba(62, 207, 142, 0.2);
  border-color: var(--success);
  color: var(--success);
}

.watch-bool.off {
  background: rgba(240, 113, 120, 0.08);
  color: var(--text-mute);
}

.watch-num {
  width: 4.5rem;
  font-family: var(--mono);
  font-size: 0.75rem;
  padding: 0.15rem 0.3rem;
}

.studio-ladder.online .studio-cell.power-in {
  /* subtle power rail into cell */
}

@media (max-width: 960px) {
  .studio-split {
    grid-template-columns: 1fr;
  }
  .studio-watch-pane {
    border-top: 1px solid var(--border);
    max-height: 220px;
  }
  .studio-editor-pane {
    border-right: none;
  }
}

/* ═══════════════════════════════════════════════════════════════
   Examples — process demos + HMI
   ═══════════════════════════════════════════════════════════════ */

.examples-list { margin-top: 0.25rem; }

.ex-cat {
  margin: 0.75rem 0 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
}

.ex-list {
  list-style: none;
  margin: 0 0 0.5rem;
  padding: 0;
}

.ex-item-btn {
  width: 100%;
  display: flex;
  gap: 0.5rem;
  text-align: left;
  padding: 0.55rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elev);
  cursor: pointer;
  margin-bottom: 0.3rem;
  color: inherit;
}

.ex-item-btn > span:last-child {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

.ex-item-btn strong {
  font-size: 0.85rem;
}

.ex-item.active .ex-item-btn,
.ex-item-btn:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.ex-ico {
  font-size: 1.1rem;
  line-height: 1.2;
  flex-shrink: 0;
}

.ex-chrome {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  margin: -0.85rem -1rem;
}

.ex-runbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.5rem 0.85rem;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #1a2430 0%, #121a24 100%);
  flex-shrink: 0;
}

.ex-runbar-left,
.ex-runbar-right {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.ex-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(240px, 0.85fr);
  flex: 1;
  min-height: 0;
}

.ex-process-col {
  overflow: auto;
  border-right: 1px solid var(--border);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  background: #0a0e13;
}

.ex-explain-col {
  overflow: auto;
  padding: 0.85rem 1rem;
  background: var(--bg-panel);
}

.ex-process-card,
.ex-logic-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg-elev);
  overflow: hidden;
}

.ex-visual {
  min-height: 180px;
  padding: 1rem;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(61, 156, 240, 0.08), transparent 55%),
    #0b1018;
}

.ex-empty {
  color: var(--text-dim);
  text-align: center;
  max-width: 28rem;
  line-height: 1.5;
}

.ex-gauges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
}

.ex-gauge-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--term-bg);
  font-size: 0.78rem;
}

.ex-gauge-chip.wide {
  flex: 1 1 140px;
  flex-direction: column;
  align-items: stretch;
  gap: 0.25rem;
}

.ex-gauge-chip strong.on { color: var(--success); }
.ex-gauge-chip strong.off { color: var(--text-mute); }

.ex-mini-bar {
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.ex-mini-bar div {
  height: 100%;
  background: var(--accent);
  transition: width 0.08s linear;
}

.ex-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  align-items: center;
}

.ex-ctrl-btn {
  min-width: 5.5rem;
  padding: 0.55rem 0.9rem;
  border-radius: 8px;
  border: 2px solid var(--border-strong);
  background: #1a2430;
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  touch-action: none;
}

.ex-ctrl-btn.pressed,
.ex-ctrl-btn.active {
  filter: brightness(1.15);
  box-shadow: 0 0 0 2px rgba(61, 156, 240, 0.25);
}

.ex-ctrl-btn.style-start {
  border-color: rgba(62, 207, 142, 0.55);
  color: var(--success);
  background: rgba(62, 207, 142, 0.1);
}

.ex-ctrl-btn.style-stop {
  border-color: rgba(240, 113, 120, 0.55);
  color: var(--danger);
  background: rgba(240, 113, 120, 0.1);
}

.ex-ctrl-btn.style-estop {
  border-color: #f07178;
  background: #f07178;
  color: #1a0505;
  min-width: 6.5rem;
  font-size: 0.95rem;
}

.ex-ctrl-btn.style-estop.active {
  animation: ex-pulse 0.8s ease infinite;
}

.ex-ctrl-btn.style-reset {
  border-color: rgba(61, 156, 240, 0.5);
  color: var(--accent);
}

@keyframes ex-pulse {
  50% { filter: brightness(1.25); }
}

.ex-setpoint {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  flex: 1 1 200px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.ex-setpoint input[type="range"] {
  flex: 1;
  min-width: 80px;
}

.ex-logic-head {
  display: flex;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  background: var(--bg-panel);
}

.ex-ladder {
  max-height: 320px;
  overflow: auto;
}

.ex-ladder .studio-path {
  font-size: 0.72rem;
}

.ex-explain h3 {
  margin: 0 0 0.35rem;
  font-size: 1.1rem;
}

.ex-explain h4 {
  margin: 1rem 0 0.35rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-mute);
}

.ex-summary {
  color: var(--text-dim);
  margin: 0 0 0.5rem;
}

.ex-explain ul,
.ex-explain ol {
  margin: 0;
  padding-left: 1.15rem;
  color: var(--text-dim);
  font-size: 0.88rem;
}

.ex-explain li {
  margin-bottom: 0.35rem;
}

.ex-tag-docs code {
  color: var(--term-cyan);
}

/* Process visuals */
.ex-motor {
  text-align: center;
}

.ex-motor-body {
  width: 110px;
  height: 110px;
  margin: 0 auto 0.5rem;
  border-radius: 50%;
  border: 4px solid #2a3a4d;
  background: #151d28;
  display: grid;
  place-items: center;
  position: relative;
}

.ex-motor.running .ex-motor-body {
  border-color: var(--success);
  box-shadow: 0 0 20px rgba(62, 207, 142, 0.35);
}

.ex-motor.estopped .ex-motor-body {
  border-color: var(--danger);
  box-shadow: 0 0 20px rgba(240, 113, 120, 0.4);
}

.ex-motor-shaft {
  width: 70%;
  height: 70%;
  border-radius: 50%;
  background:
    conic-gradient(from 0deg, #3d9cf0, #1a3048, #3d9cf0, #1a3048, #3d9cf0);
  border: 2px solid #4a6a88;
}

.ex-motor.running .ex-motor-shaft {
  animation: ex-spin linear infinite;
}

@keyframes ex-spin {
  to { transform: rotate(360deg); }
}

.ex-motor-label {
  font-weight: 700;
  font-family: var(--mono);
  letter-spacing: 0.04em;
}

.ex-perm {
  margin-top: 0.35rem;
  font-size: 0.8rem;
  font-family: var(--mono);
}

.ex-perm.ok { color: var(--success); }
.ex-perm.bad { color: var(--danger); }

.ex-timer-lamp { text-align: center; width: min(280px, 100%); }

.ex-lamp {
  width: 72px;
  height: 72px;
  margin: 0 auto 0.75rem;
  border-radius: 50%;
  background: #2a2030;
  border: 3px solid #4a3a50;
  transition: background 0.15s, box-shadow 0.15s;
}

.ex-lamp.on {
  background: #3ecf8e;
  border-color: #7ee7b0;
  box-shadow: 0 0 28px rgba(62, 207, 142, 0.65);
}

.ex-timer-bar {
  height: 10px;
  background: var(--border);
  border-radius: 5px;
  overflow: hidden;
  margin-bottom: 0.4rem;
}

.ex-timer-bar div {
  height: 100%;
  background: var(--warn);
  transition: width 0.05s linear;
}

.ex-tank { text-align: center; }

.ex-tank-shell {
  position: relative;
  width: 140px;
  height: 180px;
  margin: 0 auto 0.5rem;
  border: 3px solid #4a5d72;
  border-radius: 8px 8px 14px 14px;
  background: #0d1520;
  overflow: hidden;
}

.ex-tank-liquid {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #5eb0f8, #2a6fad);
  transition: height 0.08s linear;
  opacity: 0.85;
}

.ex-tank-sp {
  position: absolute;
  left: 0;
  right: 0;
  height: 0;
  border-top: 2px dashed rgba(230, 184, 77, 0.85);
  z-index: 2;
}

.ex-mixer {
  position: absolute;
  left: 50%;
  top: 45%;
  width: 48px;
  height: 48px;
  margin: 0;
  background:
    linear-gradient(90deg, transparent 44%, #c5d0dc 44%, #c5d0dc 56%, transparent 56%),
    linear-gradient(0deg, transparent 44%, #c5d0dc 44%, #c5d0dc 56%, transparent 56%);
  border-radius: 50%;
  z-index: 3;
  opacity: 0.85;
}

.ex-mixer.spin {
  /* angle set inline; add continuous spin via animation when running */
  animation: none;
}

.ex-valves {
  display: flex;
  justify-content: center;
  gap: 1rem;
  margin-bottom: 0.4rem;
}

.ex-valve {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  color: var(--text-mute);
}

.ex-valve.open {
  color: #061018;
  background: var(--accent);
  border-color: transparent;
}

.ex-phase-row {
  display: flex;
  justify-content: center;
  gap: 0.35rem;
  margin-bottom: 0.35rem;
}

.ex-phase {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  color: var(--text-mute);
}

.ex-phase.on {
  background: rgba(62, 207, 142, 0.15);
  border-color: var(--success);
  color: var(--success);
}

.ex-temp {
  display: flex;
  align-items: center;
  gap: 1.25rem;
}

.ex-thermo {
  position: relative;
  width: 28px;
  height: 160px;
  border: 2px solid #8a9bb0;
  border-radius: 14px;
  background: #1a2030;
  overflow: hidden;
}

.ex-thermo-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(180deg, #f07178, #c0392b);
  transition: height 0.1s linear;
}

.ex-thermo-sp {
  position: absolute;
  left: -4px;
  right: -4px;
  height: 0;
  border-top: 2px solid var(--warn);
  z-index: 2;
}

.ex-temp-big {
  font-size: 1.6rem;
  font-weight: 700;
  font-family: var(--mono);
}

.ex-heater {
  margin-top: 0.5rem;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--text-mute);
  display: inline-block;
}

.ex-heater.on {
  background: rgba(240, 113, 120, 0.2);
  border-color: var(--danger);
  color: var(--danger);
}

.ex-pressure { text-align: center; }

.ex-gauge-dial {
  position: relative;
  width: 130px;
  height: 130px;
  margin: 0 auto 0.5rem;
  border-radius: 50%;
  border: 3px solid #4a5d72;
  background:
    conic-gradient(from 210deg, #3ecf8e 0 40%, #e6b84d 40% 70%, #f07178 70% 100%);
  opacity: 0.9;
}

.ex-gauge-dial::after {
  content: "";
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  background: #0d1520;
}

.ex-gauge-needle {
  position: absolute;
  left: 50%;
  bottom: 50%;
  width: 3px;
  height: 48px;
  margin-left: -1.5px;
  background: #e6edf5;
  transform-origin: bottom center;
  z-index: 2;
  border-radius: 2px;
  transition: transform 0.08s linear;
}

.ex-gauge-center {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 12px;
  height: 12px;
  margin: -6px 0 0 -6px;
  border-radius: 50%;
  background: #e6edf5;
  z-index: 3;
}

.ex-gauge-val {
  font-size: 1.15rem;
  font-weight: 700;
}

.ex-pump {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 700;
  border: 1px solid var(--border);
  color: var(--text-mute);
}

.ex-pump.on {
  background: rgba(62, 207, 142, 0.15);
  border-color: var(--success);
  color: var(--success);
}

.ex-alarm-flash {
  margin-top: 0.5rem;
  color: var(--danger);
  font-weight: 800;
  letter-spacing: 0.04em;
  animation: ex-pulse 0.6s ease infinite;
}

.ex-cylinder { width: min(320px, 100%); text-align: center; }

.ex-cyl-bore {
  height: 48px;
  border: 3px solid #4a5d72;
  border-radius: 8px;
  background: #0d1520;
  position: relative;
  overflow: hidden;
  margin-bottom: 0.45rem;
}

.ex-cyl-rod {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: linear-gradient(90deg, #3d5a80, #79c0ff);
  transition: width 0.08s linear;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.ex-cyl-piston {
  width: 10px;
  height: 100%;
  background: #e6edf5;
}

.ex-cyl-limits {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-mute);
}

.ex-cyl-limits .lit {
  color: var(--success);
}

@media (max-width: 960px) {
  .ex-layout {
    grid-template-columns: 1fr;
  }
  .ex-process-col {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .ex-ladder {
    max-height: 240px;
  }
}
