/* NDWS.canvas: Network Lab workspace (toolbar, SVG stage, inspector, inline editor).
   Colors and radii come from the variables of style.css (--panel, --panel-2, --line, --line-2, --accent, --accent-soft, --muted, --faint,
   --text, --ok, --bad, --warn, --mono, --sans) so both themes work. Everything is prefixed ws-. */

.ws-canvas [hidden] { display: none !important; }
.ws-canvas {
  position: relative; display: flex; flex-direction: column; width: 100%; height: 100%; min-width: 0; min-height: 240px;
  background: var(--panel-2); color: var(--text); font: 13px/1.4 var(--sans, system-ui, sans-serif); overflow: hidden; isolation: isolate;
}
.ws-canvas *, .ws-canvas *::before, .ws-canvas *::after { box-sizing: border-box; }

/* ---- toolbar */
.ws-cv-toolbar {
  flex: 0 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 2px 2px; padding: 3px 6px;
  background: var(--panel); border-bottom: 1px solid var(--line); z-index: 3;
}
.ws-cv-grp { display: inline-flex; align-items: center; gap: 1px; padding-right: 5px; margin-right: 3px; border-right: 1px solid var(--line); }
.ws-cv-grp:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.ws-cv-btn {
  flex: 0 0 auto; min-width: 32px; width: 32px; height: 32px; padding: 0; display: inline-grid; place-items: center; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted); cursor: pointer; touch-action: manipulation; font: 700 11px/1 var(--mono, monospace);
}
.ws-cv-btn.txt { width: auto; padding: 0 8px; }
.ws-cv-btn:hover:not(:disabled) { background: var(--panel-2); color: var(--text); }
.ws-cv-btn.on, .ws-cv-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.ws-cv-btn:disabled { opacity: .38; cursor: default; }
.ws-cv-btn:focus-visible, .ws-cv-tab:focus-visible, .ws-cv-swatch:focus-visible, .ws-cv-zone:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ws-canvas .ws-cv-btn svg, .ws-canvas .ws-cv-tab svg { display: block; width: 18px; height: 18px; pointer-events: none; }
.ws-cv-zoom { min-width: 44px; text-align: center; font: 600 12px/1 var(--mono, monospace); color: var(--muted); padding: 0 2px; user-select: none; }

/* ---- layout */
.ws-cv-main { position: relative; flex: 1 1 0%; min-height: 0; display: flex; flex-direction: row; }
.ws-cv-stage { position: relative; flex: 1 1 0%; min-width: 0; min-height: 0; overflow: hidden; outline: none; background: var(--panel-2); }
.ws-cv-stage:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.ws-canvas .ws-cv-svg { position: absolute; inset: 0; display: block; width: 100%; height: 100%; touch-action: none; user-select: none; -webkit-user-select: none; background: transparent; }
/* embedded workspace (class set by the canvas when opts.touchScroll is on and the Select tool is active): one finger on empty background scrolls the page;
   devices, shapes, handles and the selection overlay keep touch-action none (the touchstart handler of the canvas also blocks scrolling for them) */
.ws-canvas.ws-touch-page .ws-cv-svg { touch-action: pan-y; }
.ws-canvas.ws-touch-page .ws-node, .ws-canvas.ws-touch-page .ws-layer > *, .ws-canvas.ws-touch-page .ws-handle { touch-action: none; }

/* floating bits over the stage */
.ws-legend { position: absolute; right: 10px; bottom: 8px; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px 10px; font-size: 11px; color: var(--muted); pointer-events: none; max-width: 70%; }
.ws-legend i { display: inline-block; width: 16px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 4px; }
.ws-cv-msg { position: absolute; left: 10px; bottom: 8px; max-width: 60%; padding: 5px 10px; border-radius: 8px; background: var(--text); color: var(--panel); font-weight: 600; font-size: 12px; opacity: 0; transform: translateY(4px); transition: opacity .15s, transform .15s; pointer-events: none; }
.ws-cv-msg.on { opacity: 1; transform: none; }
.ws-cv-msg.bad { background: var(--bad); color: #fff; }
.ws-cv-tab { position: absolute; top: 6px; z-index: 4; width: 32px; height: 32px; padding: 0; display: grid; place-items: center; border: 1px solid var(--line-2); border-radius: 8px; background: var(--panel); color: var(--muted); cursor: pointer; box-shadow: var(--shadow, none); }
.ws-cv-tab:hover { color: var(--text); background: var(--panel-2); }
.ws-cv-tab-tb { left: 6px; }
.ws-cv-tab-insp { right: 6px; }

/* ---- inline text editor (HTML textarea over the shape) */
.ws-canvas textarea.ws-cv-editor {
  position: absolute; z-index: 5; margin: 0; min-height: 0; resize: none; overflow: hidden; padding: 2px 4px; line-height: 1.25;
  font-family: var(--sans, system-ui, sans-serif); border: 2px solid var(--accent); border-radius: 4px; background: var(--panel); color: var(--text);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25); outline: none; width: auto;
}
.ws-canvas textarea.ws-cv-editor:focus { border-color: var(--accent); box-shadow: 0 2px 10px rgba(0, 0, 0, .25), 0 0 0 3px var(--accent-soft); }

/* ---- SVG content */
.ws-grid { pointer-events: none; }
.ws-link { pointer-events: none; }
.ws-node { cursor: inherit; } /* the cursor is chosen by code (tool, hover, drag) on the svg; a fixed 'pointer' here would hide crosshair / grab / grabbing over devices */
.ws-node text { font-family: var(--sans, system-ui, sans-serif); fill: var(--text); pointer-events: none; user-select: none; }
.ws-node text.ws-hl { fill: var(--muted); }
.ws-node.ws-hov .shape { stroke-width: 3; }
.ws-node.sel .shape { stroke: var(--accent); stroke-width: 3.5; }
/* devices are keyboard buttons (tabindex 0): a visible focus ring on the hit box */
.ws-node:focus { outline: none; }
.ws-node:focus-visible .ws-hit { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: 6 4; rx: 10; }
.ws-iflbl { font-family: var(--mono, monospace); font-size: 12px; fill: var(--muted); paint-order: stroke; stroke: var(--panel-2); stroke-width: 4px; stroke-linejoin: round; pointer-events: none; user-select: none; }
.ws-lowzoom .ws-iflbl { display: none; }
.ws-label { font-family: var(--sans, system-ui, sans-serif); white-space: pre; pointer-events: all; user-select: none; }
.ws-layer-front .ws-label, .ws-layer-back .ws-label { pointer-events: all; }
.ws-lock { pointer-events: none; }
.ws-overlay, .ws-overlay * { pointer-events: none; }
.ws-sel { fill: none; stroke: var(--accent); stroke-width: 1.5; }
.ws-sel-dev { fill: var(--accent); fill-opacity: .06; }
.ws-sel-locked { stroke: var(--warn); stroke-dasharray: 5 3; }
.ws-sel-union { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; opacity: .8; }
.ws-lblbox { fill: none; stroke: var(--accent); stroke-width: 1; stroke-dasharray: 2 3; opacity: .85; }
.ws-handle { fill: var(--panel); stroke: var(--accent); stroke-width: 1.5; }
.ws-marquee { fill: var(--accent); fill-opacity: .08; stroke: var(--accent); stroke-width: 1; }
.ws-marquee.cross { stroke-dasharray: 4 3; fill-opacity: .05; }

/* ---- inspector */
.ws-cv-insp { flex: 0 0 auto; width: 272px; display: flex; flex-direction: column; min-height: 0; background: var(--panel); border-left: 1px solid var(--line); z-index: 2; }
.ws-cv-insp-h { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 4px 6px 4px 12px; border-bottom: 1px solid var(--line); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.ws-cv-insp-b { flex: 1 1 auto; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 4px 12px 14px; overscroll-behavior: contain; }
.ws-cv-hint { margin: 10px 0 6px; color: var(--muted); font-size: 12.5px; }
.ws-cv-sec { padding: 8px 0 6px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 6px; }
.ws-cv-sec:first-of-type { border-top: 0; }
.ws-cv-sec > h4, .ws-cv-sec h4 { margin: 0; font-size: 11px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.ws-cv-devname { font-weight: 700; word-break: break-all; }
.ws-cv-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ws-cv-grid4 { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ws-cv-fld { display: flex; flex-direction: column; gap: 2px; font-size: 11.5px; color: var(--muted); font-weight: 600; min-width: 0; }
.ws-cv-fld.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 8px; }
.ws-cv-fld.inline > .ws-cv-in { width: 84px; flex: 0 0 auto; }
.ws-canvas input.ws-cv-in, .ws-canvas textarea.ws-cv-in {
  width: 100%; min-width: 0; height: 32px; padding: 3px 7px; font: 13px/1.2 var(--sans, system-ui, sans-serif); color: var(--text);
  border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); outline: none;
}
.ws-canvas textarea.ws-cv-in { height: auto; min-height: 58px; resize: vertical; padding: 5px 7px; line-height: 1.3; }
.ws-canvas input.ws-cv-in:focus, .ws-canvas textarea.ws-cv-in:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ws-canvas input.ws-cv-in:disabled, .ws-canvas textarea.ws-cv-in:disabled { opacity: .5; }
.ws-cv-colorrow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ws-canvas input.ws-cv-color { width: 36px; height: 32px; padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); cursor: pointer; flex: 0 0 auto; }
.ws-canvas input.ws-cv-color:disabled { opacity: .5; cursor: default; }
.ws-canvas input.ws-cv-hex { width: 84px; flex: 0 0 auto; font-family: var(--mono, monospace); font-size: 12px; }
.ws-cv-chk { display: inline-flex; align-items: center; gap: 6px; min-height: 32px; font-size: 12.5px; color: var(--text); cursor: pointer; }
.ws-canvas .ws-cv-chk input { width: 16px; height: 16px; margin: 0; accent-color: var(--accent); }
.ws-cv-oprow { display: flex; align-items: center; gap: 8px; font-size: 11.5px; color: var(--muted); font-weight: 600; }
.ws-cv-oprow > span { flex: 0 0 auto; min-width: 58px; }
.ws-canvas input.ws-cv-range { flex: 1 1 auto; min-width: 0; width: auto; padding: 0; height: 32px; accent-color: var(--accent); }
.ws-canvas .ws-cv-oprow input.ws-cv-in { width: 56px; flex: 0 0 auto; } /* must outrank '.ws-canvas input.ws-cv-in { width: 100% }' or the slider collapses to 0 px */
.ws-cv-row2 { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.ws-cv-seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 8px; overflow: hidden; }
.ws-cv-seg .ws-cv-btn { border-radius: 0; }
.ws-cv-btn.wide { width: 100%; justify-content: center; border: 1px solid var(--line-2); font: 600 12px var(--sans, system-ui, sans-serif); }
.ws-cv-swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(32px, 1fr)); gap: 4px; } /* 9 swatches in a row were 22 px wide in the 272 px inspector: wrap so every swatch keeps the 32 px touch target */
.ws-cv-swatch { height: 32px; min-width: 0; padding: 0; border: 2px solid var(--panel); border-radius: 6px; box-shadow: 0 0 0 1px var(--line-2); cursor: pointer; }
.ws-cv-swatch:disabled { opacity: .35; cursor: default; }
.ws-cv-zones { display: flex; flex-wrap: wrap; gap: 4px; }
.ws-cv-zone { height: 32px; padding: 0 10px; border: 1px solid var(--line-2); border-left: 4px solid var(--accent); border-radius: 6px; background: var(--panel); color: var(--text); font: 600 12px var(--sans, system-ui, sans-serif); cursor: pointer; }
.ws-cv-zone:hover:not(:disabled) { background: var(--panel-2); }
.ws-cv-zone:disabled { opacity: .45; cursor: default; }
/* OSPF areas (kind choice, number field + button) */
.ws-cv-kinds { display: flex; flex-wrap: wrap; gap: 4px; }
.ws-cv-kind { display: inline-flex; align-items: center; gap: 5px; height: 32px; padding: 0 8px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--panel); color: var(--text); font: 600 12px var(--sans, system-ui, sans-serif); cursor: pointer; }
.ws-cv-kind svg { display: block; width: 16px; height: 16px; flex: none; }
.ws-cv-kind:hover:not(:disabled) { background: var(--panel-2); }
.ws-cv-kind[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.ws-cv-kind:disabled { opacity: .45; cursor: default; }
.ws-cv-kind:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ws-cv-areaadd { display: flex; align-items: center; gap: 6px; }
.ws-cv-areaadd .ws-cv-fld { flex: 1 1 auto; min-width: 0; }
.ws-cv-areanum { width: 100%; min-width: 0; }
.ws-cv-btn.ws-cv-areaplus { width: 40px; flex: none; height: 32px; font-size: 18px; line-height: 1; }

/* ---- narrow container (< 560 px): toolbar scrolls, inspector becomes a collapsible bottom strip */
.ws-canvas.ws-narrow .ws-cv-toolbar { flex-wrap: nowrap; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; }
.ws-canvas.ws-narrow .ws-cv-grp { flex: 0 0 auto; }
.ws-canvas.ws-narrow .ws-cv-main { flex-direction: column; }
.ws-canvas.ws-narrow .ws-cv-insp { width: auto; max-height: 46%; border-left: 0; border-top: 1px solid var(--line); }
.ws-canvas.ws-narrow .ws-cv-tab-insp { top: auto; bottom: 6px; right: 6px; }
.ws-canvas.ws-narrow .ws-legend { bottom: 44px; max-width: 80%; }
.ws-canvas.ws-narrow .ws-cv-msg { bottom: 44px; }
.ws-canvas.ws-narrow .ws-cv-grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.ws-canvas.ws-compact .ws-cv-toolbar { padding: 2px 4px; }

@media (prefers-reduced-motion: reduce) { .ws-cv-msg { transition: none; } }
