/* ==========================================================================
   DeviceMap - styles
   ========================================================================== */
:root {
  --font: "Inter", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
  --radius: 8px;
  --radius-lg: 12px;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: rgba(79, 70, 229, .12);
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #d97706;
  --t: 120ms ease;
}
[data-theme="light"] {
  --bg: #f4f5f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --border: #e3e6ec;
  --border-strong: #cdd2db;
  --text: #171a21;
  --text-2: #4a5263;
  --muted: #7d8596;
  --canvas: #fbfbfd;
  --grid: #d9dde5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .16), 0 2px 6px rgba(16, 24, 40, .08);
  --device-bg: #ffffff;
  --device-border: #d5dae3;
  color-scheme: light;
}
[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1c2029;
  --surface-3: #232835;
  --border: #2a303c;
  --border-strong: #3a4252;
  --text: #e8eaf0;
  --text-2: #b4bac7;
  --muted: #828a9b;
  --canvas: #12151b;
  --grid: #262b36;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, .5);
  --device-bg: #1c2029;
  --device-border: #353c4b;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-soft: rgba(99, 102, 241, .18);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font); font-size: 13px; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased; overflow: hidden;
}
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
kbd {
  font-family: var(--mono); font-size: 10.5px; color: var(--muted); background: var(--surface-3);
  border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; line-height: 16px;
}

#app { display: grid; grid-template-rows: 52px 1fr 26px; height: 100vh; }

/* ------------------------------------------------------------------ buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius);
  cursor: pointer; white-space: nowrap; transition: background var(--t), border-color var(--t);
}
.btn:hover { background: var(--surface-3); }
.btn svg { width: 16px; height: 16px; flex: none; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.icon { width: 32px; padding: 0; justify-content: center; }
.btn.sm { height: 28px; font-size: 12px; padding: 0 9px; }
.btn.icon.sm { width: 28px; padding: 0; }
.btn.xs { height: 22px; font-size: 11.5px; padding: 0 7px; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: default; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 14.5px; padding-right: 6px; }
.brand-logo { width: 22px; height: 22px; color: var(--accent); }
.brand-logo rect { fill: var(--accent-soft); }
.menu-group { display: flex; gap: 2px; }
.caret { width: 0; height: 0; border: 4px solid transparent; border-top-color: var(--muted); margin-top: 4px; }
.file-title {
  display: flex; align-items: center; gap: 8px; color: var(--text-2); font-weight: 500;
  padding: 0 8px; border-left: 1px solid var(--border); margin-left: 4px; min-width: 0;
}
#file-name { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dirty-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); }

.seg {
  display: flex; background: var(--surface-3); border-radius: var(--radius); padding: 3px; margin-left: auto;
}
.seg button {
  display: flex; align-items: center; gap: 6px; border: 0; background: transparent; padding: 0 12px;
  height: 26px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500;
}
.seg button svg { width: 15px; height: 15px; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.top-actions { display: flex; align-items: center; gap: 4px; margin-left: auto; }
.global-search { position: relative; margin-right: 6px; }
.global-search svg { position: absolute; left: 9px; top: 8px; width: 16px; height: 16px; color: var(--muted); }
.global-search input {
  width: 290px; height: 32px; padding: 0 10px 0 32px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface-2); outline: none;
}
.global-search input:focus { border-color: var(--accent); background: var(--surface); }

/* ---------------------------------------------------------------- dropdown */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); left: 0; min-width: 240px; z-index: 50; display: none;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg); padding: 5px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-menu button, .ctx-menu button {
  display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 16px;
  border: 0; background: transparent; padding: 7px 10px; border-radius: 6px; cursor: pointer; text-align: left;
}
.dropdown-menu button:hover, .ctx-menu button:hover { background: var(--surface-3); }
.dropdown-menu .sep, .ctx-menu .sep { height: 1px; background: var(--border); margin: 4px 2px; }
.ctx-menu {
  position: fixed; z-index: 80; min-width: 200px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 5px;
}
.ctx-menu button.danger { color: var(--danger); }

/* --------------------------------------------------------------- workspace */
.workspace { display: grid; grid-template-columns: 250px minmax(0, 1fr) 330px; min-height: 0; }
/* fixed columns: hiding one panel never shifts the others (layout.js sets the widths) */
.workspace > .library { grid-column: 1; }
.workspace > .center { grid-column: 2; }
.workspace > .props { grid-column: 3; }
.workspace.lib-off > .library, .workspace.props-off > .props { display: none; }
.center { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.canvas-wrap { flex: 1; position: relative; min-height: 0; overflow: hidden; }
.table-wrap { display: none; min-height: 0; background: var(--surface); }
.splitter { display: none; }
.workspace[data-view="table"] .canvas-wrap { display: none; }
.workspace[data-view="table"] .table-wrap { display: flex; flex: 1; }
.workspace[data-view="split"] .canvas-wrap { flex: 0 0 var(--split, 55%); }
.workspace[data-view="split"] .table-wrap { display: flex; flex: 1; border-top: 1px solid var(--border); }
.workspace[data-view="split"] .splitter {
  display: block; height: 6px; margin: -3px 0; cursor: row-resize; z-index: 5; position: relative;
}
.workspace[data-view="split"] .splitter:hover { background: var(--accent-soft); }

/* ----------------------------------------------------------------- panels */
.library, .props {
  background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
}
.props { border-right: 0; border-left: 1px solid var(--border); overflow: hidden; }
.props-body { flex: 1; overflow-y: auto; min-height: 0; }
.props-head { border-bottom: 1px solid var(--border); padding: 10px 10px 10px 14px; }
.head-actions { display: flex; gap: 2px; align-items: center; }
.props-back { padding: 8px 10px 0; }
.dev-link { cursor: pointer; border-bottom: 1px dashed var(--border-strong); }
.dev-link:hover { color: var(--accent); border-color: var(--accent); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; padding: 12px 14px 8px;
}
.panel-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 0; font-weight: 600; }
.lib-tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; padding: 0 12px 10px; }
.tool {
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 7px 4px; font-size: 11.5px;
  border: 1px solid var(--border); background: var(--surface-2); border-radius: var(--radius); cursor: pointer; color: var(--text-2);
}
.tool:hover { border-color: var(--accent); color: var(--accent); }
.tool svg { width: 18px; height: 18px; }
.search-box { padding: 0 12px 8px; }
.search-box input, .field input, .field select, .field textarea, .input {
  width: 100%; height: 32px; padding: 0 10px; border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2); outline: none; transition: border-color var(--t);
}
.search-box input:focus, .field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  border-color: var(--accent); background: var(--surface);
}
.field textarea { height: auto; min-height: 64px; padding: 7px 10px; resize: vertical; line-height: 1.45; }
.field input[type="color"] { padding: 2px; width: 44px; cursor: pointer; }
.field input[type="checkbox"] { width: auto; height: auto; }

.lib-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.lib-cat { margin-top: 6px; }
.lib-cat > summary {
  list-style: none; cursor: pointer; padding: 6px 6px; font-size: 11.5px; font-weight: 600; color: var(--muted);
  text-transform: uppercase; letter-spacing: .05em; display: flex; justify-content: space-between; border-radius: 6px;
}
.lib-cat > summary::-webkit-details-marker { display: none; }
.lib-cat > summary:hover { background: var(--surface-3); }
.lib-cat > summary .count { font-weight: 500; }
.lib-item {
  display: flex; align-items: center; gap: 9px; padding: 5px 6px; border-radius: 7px; cursor: grab; user-select: none;
}
.lib-item:hover { background: var(--surface-3); }
.lib-item .ico { width: 28px; height: 28px; border-radius: 7px; display: grid; place-items: center; flex: none; }
.lib-item .ico svg { width: 17px; height: 17px; }
.lib-item .nm { line-height: 1.2; min-width: 0; }
.lib-item .nm small { display: block; color: var(--muted); font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lib-hint { padding: 8px 14px; font-size: 11.5px; color: var(--muted); border-top: 1px solid var(--border); }

/* --------------------------------------------------------------- properties */
.props-section { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.props-section:last-child { border-bottom: 0; }
.props-section h3 {
  margin: 0 0 10px; font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.props-title { display: flex; align-items: center; gap: 10px; padding: 14px; border-bottom: 1px solid var(--border); }
.props-title .ico { width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center; flex: none; }
.props-title .ico svg { width: 20px; height: 20px; }
.props-title .t { font-weight: 600; font-size: 14px; line-height: 1.25; min-width: 0; }
.props-title .t small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 9px; }
.field > label { font-size: 11.5px; color: var(--text-2); font-weight: 500; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.field-row.three { grid-template-columns: 1fr 1fr 1fr; }
.field-inline { display: flex; align-items: center; gap: 8px; }
.check { display: flex; align-items: center; gap: 8px; margin: 6px 0; cursor: pointer; }
.muted { color: var(--muted); }
.small { font-size: 11.5px; }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stat { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; }
.stat b { display: block; font-size: 18px; font-weight: 650; }
.stat span { font-size: 11px; color: var(--muted); }
.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: 12px; }
.legend-row svg { width: 34px; height: 10px; flex: none; }
.legend-row .n { margin-left: auto; color: var(--muted); }
.notice {
  background: var(--accent-soft); color: var(--text); border-radius: var(--radius); padding: 8px 10px; font-size: 12px; margin-bottom: 10px;
}
.notice.warn { background: rgba(217, 119, 6, .14); }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.port-list { display: flex; flex-direction: column; gap: 2px; }
.port-row {
  display: grid; grid-template-columns: 10px 1fr 84px 62px 22px; gap: 4px; align-items: center; padding: 3px 4px; border-radius: 6px;
}
.port-row:hover { background: var(--surface-2); }
.port-row .dot { width: 9px; height: 9px; border-radius: 50%; }
.port-row input, .port-row select {
  height: 26px; border: 1px solid transparent; background: transparent; border-radius: 6px; padding: 0 6px; min-width: 0; outline: none; font-size: 12px;
}
.port-row input:hover, .port-row select:hover { border-color: var(--border); }
.port-row input:focus, .port-row select:focus { border-color: var(--accent); background: var(--surface); }
.port-row .peer {
  grid-column: 2 / -1; font-size: 11.5px; color: var(--muted); padding: 0 6px 2px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.port-row .peer:hover { color: var(--accent); }
.port-row .peer.free { cursor: default; }
.port-row .peer.free:hover { color: var(--muted); }
.x-btn {
  width: 22px; height: 22px; border: 0; background: transparent; border-radius: 5px; cursor: pointer; color: var(--muted);
  display: grid; place-items: center; padding: 0;
}
.x-btn:hover { background: rgba(220, 38, 38, .12); color: var(--danger); }
.x-btn svg { width: 13px; height: 13px; }
.kv-row { display: grid; grid-template-columns: 1fr 1.4fr 22px; gap: 6px; margin-bottom: 6px; align-items: center; }
.kv-row input { height: 28px; }

/* ------------------------------------------------------------------ canvas */
#canvas {
  width: 100%; height: 100%; display: block; background-color: var(--canvas); outline: none; user-select: none;
  touch-action: none; cursor: default;
}
#canvas.show-grid {
  background-image: radial-gradient(circle, var(--grid) 1.1px, transparent 1.2px);
}
#canvas.panning { cursor: grabbing; }
#canvas.connecting { cursor: crosshair; }
.canvas-tools {
  position: absolute; right: 12px; bottom: 12px; display: flex; gap: 4px; background: var(--surface);
  border: 1px solid var(--border); padding: 4px; border-radius: 10px; box-shadow: var(--shadow);
}
.canvas-tools .btn { border-color: transparent; }
.zoom-label { min-width: 54px; justify-content: center; font-variant-numeric: tabular-nums; }
.empty-hint {
  position: absolute; inset: 0; display: grid; place-content: center; text-align: center; pointer-events: none; color: var(--muted);
}
.empty-hint h3 { color: var(--text-2); margin: 0 0 6px; font-weight: 600; }
.empty-hint p { margin: 0; line-height: 1.6; }

/* svg diagram */
.dev-body { fill: var(--device-bg); stroke: var(--device-border); stroke-width: 1; }
.device.selected .dev-body { stroke: var(--accent); stroke-width: 2; }
.device.hl .dev-body { stroke: var(--warn); stroke-width: 2.5; }
.device { cursor: move; }
.dev-name { fill: var(--text); font-size: 13px; font-weight: 600; stroke: none; }
.dev-sub { fill: var(--muted); font-size: 11px; stroke: none; }
.dev-sep { stroke: var(--border); stroke-width: 1; }
.port-label { fill: var(--text-2); font-size: 11px; stroke: none; }
.port-row-bg { fill: transparent; stroke: none; }
.port:hover .port-row-bg { fill: var(--accent-soft); }
.port-dot { stroke: var(--device-bg); stroke-width: 2; cursor: crosshair; }
.port:hover .port-dot, .port.target .port-dot { r: 7; }
.port.target .port-row-bg { fill: var(--accent-soft); }
.port.used .port-label { fill: var(--text); font-weight: 500; }
.dev-more { fill: var(--accent); font-size: 11px; stroke: none; cursor: pointer; }
.conn-path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.conn-hit { fill: none; stroke: transparent; stroke-width: 12; cursor: pointer; }
.conn.selected .conn-path { filter: drop-shadow(0 0 3px var(--accent)); }
.conn.hl .conn-path { filter: drop-shadow(0 0 4px var(--warn)); }
.conn-sel-outline { fill: none; stroke: var(--accent); stroke-opacity: .25; stroke-linecap: round; }
.conn-label-bg { fill: var(--surface); stroke: var(--border); stroke-width: 1; }
.conn-label { font-size: 10.5px; fill: var(--text-2); stroke: none; font-weight: 500; }
.conn { cursor: pointer; }
.area-rect { stroke-width: 1.5; stroke-dasharray: 6 4; }
.area.selected .area-rect { stroke-dasharray: none; stroke-width: 2; }
.area-label { font-size: 13px; font-weight: 650; stroke: none; cursor: move; }
.area-grip { fill: var(--surface); stroke: var(--accent); stroke-width: 1.5; cursor: nwse-resize; }
.area-hit { fill: transparent; stroke: transparent; stroke-width: 10; cursor: move; }
.note-text { fill: var(--text); stroke: none; cursor: move; }
.note.selected .note-box { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; fill: var(--accent-soft); }
.note-box { fill: transparent; stroke: none; }
.rubber { fill: var(--accent-soft); stroke: var(--accent); stroke-width: 1; stroke-dasharray: 4 3; }
.temp-conn { stroke: var(--accent); stroke-width: 2; stroke-dasharray: 6 4; fill: none; }

/* ------------------------------------------------------------------- table */
.tbl-panel { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.tbl-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.tbl-head .seg { margin-left: 0; }
.tbl-head .input { width: 220px; }
.tbl-head select.input { width: auto; min-width: 150px; }
.tbl-count { color: var(--muted); margin-left: auto; font-size: 12px; }
.tbl-scroll { flex: 1; overflow: auto; min-height: 0; }
table.grid { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 12.5px; }
table.grid th {
  position: sticky; top: 0; z-index: 1; background: var(--surface-2); text-align: left; font-weight: 600; color: var(--text-2);
  padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; cursor: pointer; user-select: none; font-size: 12px;
}
table.grid th:hover { color: var(--text); }
table.grid th .sort { color: var(--accent); margin-left: 4px; }
table.grid td { padding: 7px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.grid tbody tr { cursor: pointer; }
table.grid tbody tr:hover td { background: var(--surface-2); }
table.grid tbody tr.selected td { background: var(--accent-soft); }
table.grid td.dev { font-weight: 600; }
table.grid td .sub { display: block; color: var(--muted); font-weight: 400; font-size: 11px; }
table.grid td.arrow { color: var(--muted); text-align: center; width: 24px; padding: 0; }
table.grid td.act { width: 1%; white-space: nowrap; text-align: right; }
table.grid td.act .btn { visibility: hidden; }
table.grid tr:hover td.act .btn { visibility: visible; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 2px 8px 2px 6px; border-radius: 999px;
  background: var(--surface-3); font-size: 11.5px; white-space: nowrap; font-weight: 500;
}
.pill i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.pill.free { color: var(--muted); }
.sw-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 8px; vertical-align: 0; }
mark { background: rgba(250, 204, 21, .45); color: inherit; border-radius: 2px; padding: 0 1px; }
.tbl-empty { padding: 40px; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------------ status */
.statusbar {
  display: flex; align-items: center; gap: 16px; padding: 0 12px; font-size: 11.5px; color: var(--muted);
  background: var(--surface); border-top: 1px solid var(--border);
}
.statusbar .grow { flex: 1; text-align: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ------------------------------------------------------------------ modals */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 12, 18, .45); z-index: 100; display: grid; place-items: center; padding: 24px;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(520px, 100%);
  max-height: calc(100vh - 48px); display: flex; flex-direction: column; border: 1px solid var(--border);
}
.modal.wide { width: min(980px, 100%); height: min(720px, calc(100vh - 48px)); }
.modal.medium { width: min(720px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 18px 10px; }
.modal-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.modal-body { padding: 6px 18px 14px; overflow: auto; flex: 1; min-height: 0; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 18px; border-top: 1px solid var(--border); }
.modal-foot .left { margin-right: auto; display: flex; gap: 8px; }
.modal p { line-height: 1.5; margin: 0 0 10px; }

.file-list { display: flex; flex-direction: column; gap: 4px; }
.file-item {
  display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 8px 10px;
  border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
}
.file-item:hover { background: var(--surface-2); border-color: var(--border); }
.file-item.current { border-color: var(--accent); }
.file-item .fi { width: 34px; height: 34px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.file-item .fi svg { width: 18px; height: 18px; }
.file-item .meta { color: var(--muted); font-size: 11.5px; }
.file-item .acts { display: flex; gap: 2px; visibility: hidden; }
.file-item:hover .acts { visibility: visible; }

/* catalog manager */
.cat-layout { display: grid; grid-template-columns: 300px 1fr; gap: 0; height: 100%; min-height: 0; border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.cat-list { border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0; background: var(--surface-2); }
.cat-list .search-box { padding: 10px; }
.cat-items { overflow-y: auto; flex: 1; padding: 0 6px 6px; }
.cat-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 7px; cursor: pointer; }
.cat-item:hover { background: var(--surface-3); }
.cat-item.active { background: var(--accent-soft); }
.cat-item .sw { width: 12px; height: 12px; border-radius: 4px; flex: none; }
.cat-item .ico { width: 24px; height: 24px; border-radius: 6px; display: grid; place-items: center; flex: none; }
.cat-item .ico svg { width: 15px; height: 15px; }
.cat-item .nm { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cat-item .tag { font-size: 10px; color: var(--muted); border: 1px solid var(--border); border-radius: 4px; padding: 0 4px; }
.cat-group { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 10px 8px 4px; font-weight: 600; }
.cat-form { padding: 16px; overflow-y: auto; }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, 36px); gap: 4px; }
.icon-grid button {
  width: 36px; height: 36px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.icon-grid button svg { width: 18px; height: 18px; }
.icon-grid button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.group-row { display: grid; grid-template-columns: 1.3fr 1.2fr 56px 56px 70px 70px 22px; gap: 6px; margin-bottom: 6px; align-items: center; }
.group-row input, .group-row select { height: 28px; }
.group-head { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 12px; cursor: pointer; color: var(--text-2); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 500;
}
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }
.line-preview { height: 30px; width: 100%; }

/* ------------------------------------------------------------------ toast */
#toast-root { position: fixed; bottom: 40px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast {
  background: var(--text); color: var(--surface); padding: 9px 14px; border-radius: 9px; box-shadow: var(--shadow-lg); font-weight: 500; max-width: 520px;
}
.toast.error { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ------------------------------------------------------------------ print */
#print-root { display: none; }
@media print {
  @page { margin: 12mm; }
  html, body { height: auto; overflow: visible; background: #fff; }
  #app, #modal-root, #toast-root, #ctx-menu { display: none !important; }
  #print-root { display: block; color: #111; font-family: var(--font); }
  .pr-page { page-break-after: always; break-after: page; }
  .pr-page:last-child { page-break-after: auto; break-after: auto; }
  .pr-head { display: flex; justify-content: space-between; align-items: baseline; border-bottom: 2px solid #111; padding-bottom: 6px; margin-bottom: 10px; }
  .pr-head h1 { font-size: 18px; margin: 0; }
  .pr-head .meta { font-size: 10px; color: #555; }
  .pr-desc { font-size: 11px; color: #333; margin: 0 0 8px; }
  .pr-diagram svg { width: 100%; height: auto; max-height: var(--pr-max-h, 170mm); display: block; overflow: hidden; }
  .pr-page h2 { font-size: 14px; margin: 0 0 6px; }
  table.pr-table { width: 100%; border-collapse: collapse; font-size: 9.5px; }
  table.pr-table th { text-align: left; background: #eef0f4 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  table.pr-table th, table.pr-table td { border: 1px solid #ccd; padding: 3px 5px; }
  table.pr-table tr { break-inside: avoid; }
  .pr-sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .pr-diagram, .pr-diagram * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 10px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 1100px) {
  .global-search input { width: 180px; }
  .seg button { padding: 0 8px; }
}

/* library drag preview */
.lib-ghost {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none; width: 220px;
  background: var(--surface); border: 1px solid var(--accent); box-shadow: var(--shadow-lg); opacity: .92;
}

/* ------------------------------------------------------------ layout controls */
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.layout-toggle .fillbar { fill: currentColor; stroke: none; opacity: 0; }
.layout-toggle.on .fillbar { opacity: .35; }
#lock-btn.on { color: var(--warn); background: rgba(217, 119, 6, .12); }
/* float (undock) buttons are always available; "Reset layout" shows when unlocked or something floats */
.unlock-only { display: none !important; }
html.layout-unlocked .unlock-only, html.has-floating .unlock-only { display: inline-flex !important; }
html.layout-unlocked .workspace > .library, html.layout-unlocked .workspace > .props,
html.layout-unlocked .workspace .table-wrap { outline: 2px dashed rgba(217, 119, 6, .45); outline-offset: -2px; }

/* --------------------------------------------------------- undocked windows */
body.popout { display: flex; flex-direction: column; height: 100vh; }
.popout-bar {
  height: 38px; flex: none; display: flex; align-items: center; gap: 8px; padding: 0 10px 0 14px;
  background: var(--surface-2); border-bottom: 1px solid var(--border); font-weight: 600; font-size: 12px; color: var(--text-2);
}
.popout-bar .grow { flex: 1; }
#popout-root { flex: 1; min-height: 0; display: flex; }
.popout .library, .popout .props { flex: 1; width: 100%; border: 0; display: flex !important; }
.popout .table-wrap { display: flex !important; flex: 1; min-width: 0; }
.popout .dock-btn, .popout .hide-btn { display: none !important; }
.popout .props-head { display: none; }

/* ------------------------------------------------------------- master-detail */
.scope-seg button { padding: 0 10px; }
.scope-chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; padding: 3px 4px 3px 10px; border-radius: 999px;
  background: var(--accent-soft); max-width: 260px; white-space: nowrap; overflow: hidden;
}
.scope-chip b { overflow: hidden; text-overflow: ellipsis; }
.scope-chip.muted { background: var(--surface-3); padding-right: 10px; }
table.grid tbody tr.related td { background: rgba(99, 102, 241, .07); }
table.grid tbody tr.related td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
.mini-grid { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.mini-grid col.c-port { width: 64px; } .mini-grid col.c-arrow { width: 16px; } .mini-grid col.c-cable { width: 42%; }
.mini-grid td { overflow: hidden; text-overflow: ellipsis; word-break: break-word; }
.mini-grid .pill { max-width: 100%; overflow: hidden; text-overflow: ellipsis; display: inline-block; vertical-align: middle; }
.mini-grid .pill i { vertical-align: 0; margin-right: 5px; }
.mini-grid th { text-align: left; font-weight: 500; color: var(--muted); font-size: 11px; padding: 0 4px 4px; }
.mini-grid td { padding: 6px 4px; border-top: 1px solid var(--border); vertical-align: top; }
.mini-grid tbody tr { cursor: pointer; }
.mini-grid tbody tr:hover td { background: var(--surface-2); }
.mini-grid td.lp { font-weight: 600; }
.mini-grid td.arrow { color: var(--muted); width: 14px; padding-left: 0; padding-right: 0; text-align: center; }
.mini-grid .sub { display: block; color: var(--muted); font-size: 11px; }
.mini-grid .pill { font-size: 11px; padding: 1px 7px 1px 5px; }
.conn-rel-outline { fill: none; stroke-opacity: .28; stroke-linecap: round; stroke-linejoin: round; }
.device.peer .dev-body { stroke: var(--accent); stroke-dasharray: 5 3; stroke-width: 1.5; }

/* ------------------------------------------------------- multi-user: read-only */
.ro-badge {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: 11.5px; font-weight: 600; color: var(--warn);
  background: rgba(217, 119, 6, .12); border: 1px solid rgba(217, 119, 6, .35);
  border-radius: 999px; padding: 1px 3px 1px 9px;
}
.ro-badge[hidden] { display: none; }
.ro-badge .btn.xs { height: 18px; font-size: 11px; padding: 0 7px; border-radius: 999px; }
.lock-tag { color: var(--warn); font-weight: 600; }

/* ------------------------------------------- edge tabs to bring back hidden panels */
.edge-tab {
  position: absolute; top: 50%; z-index: 6; transform: translateY(-50%);
  display: none; align-items: center; justify-content: center;
  width: 20px; height: 56px; padding: 0; cursor: pointer;
  color: var(--text-2); background: var(--surface); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
}
.edge-tab svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.edge-tab:hover { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
.edge-tab.left { left: 0; border-left: 0; border-radius: 0 8px 8px 0; }
.edge-tab.right { right: 0; border-right: 0; border-radius: 8px 0 0 8px; }
.workspace.lib-hidden .edge-tab.left, .workspace.props-hidden .edge-tab.right { display: flex; }
.workspace[data-view="split"] .edge-tab { top: calc(var(--split, 55%) / 2); }

/* ports drawn as dots on the top / bottom edge */
.port-hit { fill: transparent; stroke: none; cursor: crosshair; }
.port.edge:hover .port-hit, .port.edge.target .port-hit { fill: var(--accent-soft); }
.port.edge:hover .port-dot { stroke: var(--accent); stroke-width: 2; }
.port-num { fill: var(--muted); font-size: 8.5px; stroke: none; pointer-events: none; }
.port.edge.used .port-num { fill: var(--text-2); font-weight: 600; }

/* selected connection: others fade, both ends get an info box */
.conn.dim { opacity: .18; }
.conn.dim:hover { opacity: .6; }
.end-tag-bg { fill: var(--surface); stroke-width: 1.5; filter: drop-shadow(0 2px 4px rgba(0,0,0,.18)); }
.end-tag-dev { font-size: 11.5px; font-weight: 650; fill: var(--text); }
.end-tag-port { font-size: 10.5px; fill: var(--text-2); }
.dropdown-menu .menu-label { padding: 6px 12px 2px; font-size: 10.5px; font-weight: 650; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.dropdown-menu kbd.mark { background: none; border: 0; color: var(--accent); font-size: 13px; font-weight: 700; }
.about { display: flex; gap: 16px; align-items: center; }
.about-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.kv-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kv-table td { padding: 5px 6px; border-bottom: 1px solid var(--border); }
.kv-table td:first-child { white-space: nowrap; width: 1%; }
.edge-summary { font-size: 10.5px; fill: var(--muted); stroke: none; pointer-events: none; font-weight: 500; }
.edge-summary .n { fill: var(--muted); opacity: .7; }
/* hover bubble for ports */
.port-tip {
  position: fixed; z-index: 60; pointer-events: none; max-width: 320px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: 8px; box-shadow: var(--shadow-lg); padding: 7px 10px; font-size: 12px; line-height: 1.45;
}
.port-tip b { font-size: 12.5px; }
.port-tip .sw { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 5px; vertical-align: 0; }
.port-tip .muted { color: var(--muted); }
.port-tip .to { color: var(--text-2); }
.port-stub { stroke-width: 2; stroke-linecap: round; pointer-events: none; }
.port-hole { fill: var(--device-bg); stroke: none; }
.glyph { vertical-align: -1px; flex: none; }
.glyph .port-hole { fill: var(--surface); }
.shape-legend { display: grid; grid-template-columns: 1fr 1fr; gap: 3px 10px; font-size: 12px; }
.shape-legend div { display: flex; align-items: center; gap: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.shape-pick { display: flex; flex-wrap: wrap; gap: 4px; }
.shape-pick button { width: 34px; height: 34px; border: 1px solid var(--border); background: var(--surface); border-radius: 7px; cursor: pointer; display: grid; place-items: center; padding: 0; }
.shape-pick button.active { border-color: var(--accent); background: var(--accent-soft); }
.shape-pick .port-hole { fill: var(--surface); }
.sw-glyph { width: 16px; display: inline-grid; place-items: center; }
/* print preview */
.modal.preview { width: min(1200px, 96vw); height: 92vh; display: flex; flex-direction: column; }
.modal.preview .modal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; padding-bottom: 8px; }
.pv-frame { flex: 1; width: 100%; min-height: 0; border: 1px solid var(--border); border-radius: 8px; background: #8a8f98; }
/* page breaks on the canvas */
.page-break { fill: none; stroke: #e11d48; stroke-width: 1.5; stroke-dasharray: 10 6; pointer-events: none; vector-effect: non-scaling-stroke; }
.page-break-label { fill: #e11d48; font-size: 13px; font-weight: 700; pointer-events: none; opacity: .75; }
