/* Homelab Diagram editor UI.
   Spacing: 4/8 px grid. Type scale: 12 caption · 14 secondary · 16 body · 20 subhead · 32 title.
   Colour: 60 % slate background, 30 % surfaces, 10 % accent. Text contrast ≥ 4.5:1. */

@font-face { font-family: 'Fira Sans'; font-weight: 400; font-display: swap; src: url('../fonts/FiraSans-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Fira Sans'; font-weight: 500; font-display: swap; src: url('../fonts/FiraSans-Medium.woff2') format('woff2'); }
@font-face { font-family: 'Fira Sans'; font-weight: 600; font-display: swap; src: url('../fonts/FiraSans-SemiBold.woff2') format('woff2'); }
@font-face { font-family: 'Fira Sans'; font-weight: 700; font-display: swap; src: url('../fonts/FiraSans-Bold.woff2') format('woff2'); }
@font-face { font-family: 'Fira Code'; font-weight: 400; font-display: swap; src: url('../fonts/FiraCode-Regular.woff2') format('woff2'); }
@font-face { font-family: 'Fira Code'; font-weight: 500; font-display: swap; src: url('../fonts/FiraCode-Medium.woff2') format('woff2'); }

:root {
    --bg: #0f172a;            /* 60 %: app background (deep slate) */
    --surface: #1e293b;       /* 30 %: panels, cards */
    --surface-2: #273449;     /* raised: inputs, list items */
    --surface-3: #334155;     /* hover */
    --border: #334155;
    --border-subtle: #263246;
    --text: #e2e8f0;          /* 13.9:1 on --bg */
    --text-muted: #94a3b8;    /* 6.9:1 on --bg, 5.7:1 on --surface */
    --accent: #3b82f6;        /* 10 %: primary action, focus, selection */
    --accent-strong: #2563eb; /* primary button fill: white text 5.2:1 */
    --accent-text: #93c5fd;
    --danger: #f87171;
    --danger-bg: #7f1d1d40;
    --ok: #4ade80;
    --warn: #fbbf24;

    --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px; --s8: 64px;
    --r-sm: 6px; --r-md: 8px; --r-lg: 12px;
    --fs-caption: 12px; --fs-small: 14px; --fs-body: 16px; --fs-sub: 20px; --fs-title: 32px;
    --shadow: 0 8px 24px rgb(2 6 23 / 0.35), 0 2px 6px rgb(2 6 23 / 0.25);
    --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
    --font: 'Fira Sans', system-ui, sans-serif;
    --mono: 'Fira Code', ui-monospace, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
    background: var(--bg);
    color: var(--text);
    font: 400 var(--fs-small)/1.5 var(--font);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.2; font-weight: 600; }
p { margin: 0; }
.muted { color: var(--text-muted); }
.mono { font-family: var(--mono); }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- layout */
.editor {
    display: grid;
    --left-w: 232px;
    --right-w: 360px;
    grid-template-columns: var(--left-w) minmax(0, 1fr) var(--right-w);
    grid-template-rows: 56px minmax(0, 1fr) 40px;
    grid-template-areas: "tool tool tool" "left canvas right" "status status status";
    height: 100vh;
}
.toolbar {
    grid-area: tool;
    display: flex;
    align-items: center;
    gap: var(--s4);
    padding: 0 var(--s4);
    background: var(--surface);
    border-bottom: 1px solid var(--border-subtle);
}
.brand { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.brand svg { width: 24px; height: 24px; color: var(--accent-text); flex: none; }
.brand-name { font-weight: 600; font-size: var(--fs-body); white-space: nowrap; }
.file-name { color: var(--text-muted); max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-group { display: flex; align-items: center; gap: var(--s1); padding-left: var(--s4); border-left: 1px solid var(--border-subtle); }
.spacer { flex: 1; }
.zoom-label { min-width: 64px; font-variant-numeric: tabular-nums; }

.sidebar {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    min-height: 0;
}
.sidebar.left { grid-area: left; border-right: 1px solid var(--border-subtle); position: relative; }
.sidebar.right { grid-area: right; border-left: 1px solid var(--border-subtle); position: relative; }
.editor.left-collapsed { --left-w: 56px; }
.editor.right-collapsed { --right-w: 0px; }
.editor.right-collapsed .sidebar.right { display: none; }

/* panel resize handles: an 8 px grab area on the inner edge */
.resizer { position: absolute; top: 0; bottom: 0; width: 8px; z-index: 5; cursor: col-resize; touch-action: none; }
.sidebar.left .resizer { right: -4px; }
.sidebar.right .resizer { left: -4px; }
.resizer::after { content: ''; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; background: transparent; transition: background-color .12s; }
.resizer:hover::after, .resizer.dragging::after { background: var(--accent); }
.resizer:focus-visible { outline: none; }
.resizer:focus-visible::after { background: var(--accent); }
.editor.left-collapsed .sidebar.left .resizer { display: none; }
body.resizing { cursor: col-resize; user-select: none; }

/* collapsed palette: icons only */
.sidebar-head-row { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.editor.left-collapsed .sidebar-head { padding: var(--s3) var(--s2) var(--s2); justify-items: center; }
.editor.left-collapsed .sidebar-head h2, .editor.left-collapsed .sidebar-head p,
.editor.left-collapsed .palette-group h3, .editor.left-collapsed .palette-item span { display: none; }
.editor.left-collapsed .palette-group { padding: var(--s1) var(--s2); }
.editor.left-collapsed .palette-group + .palette-group { border-top: 1px solid var(--border-subtle); }
.editor.left-collapsed .palette-item { justify-content: center; padding: 0; }
.collapse-btn svg { width: 18px; height: 18px; }
.sidebar-head { padding: var(--s4) var(--s4) var(--s2); display: grid; gap: var(--s1); }
.sidebar-head h2 { font-size: var(--fs-body); }
.panel-scroll { overflow-y: auto; flex: 1; min-height: 0; padding-bottom: var(--s6); }

.canvas-wrap { grid-area: canvas; position: relative; min-width: 0; min-height: 0; }
.statusbar {
    grid-area: status;
    display: flex;
    align-items: center;
    gap: var(--s4);
    padding: 0 var(--s4);
    background: var(--surface);
    border-top: 1px solid var(--border-subtle);
    font-size: var(--fs-small);
}
.status-error { color: var(--danger); display: flex; gap: var(--s2); align-items: center; font-weight: 500; }
.status-warn { color: var(--warn); font-weight: 500; }
.status-ok { color: var(--ok); font-weight: 500; }

/* ---------------------------------------------------------------- canvas */
.canvas { width: 100%; height: 100%; display: block; outline: none; touch-action: none; cursor: default; user-select: none; }
body.kbd .canvas:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.canvas.panning, .canvas.space { cursor: grab; }
.canvas.panning { cursor: grabbing; }
.canvas.grabbing { cursor: grabbing; }
.canvas.connecting, .canvas.port-hover { cursor: crosshair; }
.canvas.row-resize { cursor: row-resize; }
.canvas [data-node] { cursor: pointer; }
.canvas .cable-hit { pointer-events: stroke; cursor: pointer; }
.canvas .cables, .canvas .cable-labels, .canvas .overlay { pointer-events: none; }
.canvas .cables .cable-hit { pointer-events: stroke; }
.canvas-empty {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    pointer-events: none;
}
.canvas-empty .empty-state { pointer-events: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow); padding: var(--s6); max-width: 440px; }

/* ---------------------------------------------------------------- buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--s2);
    height: 36px;
    padding: 0 var(--s4);
    border-radius: var(--r-md);
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text);
    font-weight: 500;
    font-size: var(--fs-small);
    cursor: pointer;
    white-space: nowrap;
    transition: background-color .12s, border-color .12s, transform .06s;
}
.btn:hover { background: var(--surface-2); border-color: var(--surface-3); }
.btn:active { transform: translateY(1px); background: var(--surface-3); }
.btn:focus-visible, .icon-btn:focus-visible, .tab:focus-visible, .palette-item:focus-visible,
.chip-toggle:focus-visible, .icon-cell:focus-visible, .segmented button:focus-visible, .link-btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; background: transparent; }
.btn.primary { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1d4ed8; border-color: #1d4ed8; }
.btn.primary:active { background: #1e40af; }
.btn.ghost { border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: transparent; }
.btn.small { height: 32px; padding: 0 var(--s3); }
.btn.icon-only { width: 36px; padding: 0; font-size: var(--fs-sub); }
.btn.icon-only svg { width: 20px; height: 20px; }
.btn.danger-ghost { border-color: transparent; color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-bg); }
.icon-btn {
    width: 32px; height: 32px; border-radius: var(--r-sm); border: none; background: transparent; color: var(--text-muted);
    font-size: var(--fs-sub); line-height: 1; cursor: pointer; display: grid; place-items: center;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:active { background: var(--border); }
.link-btn { border: none; background: none; color: var(--accent-text); cursor: pointer; padding: 0; font-weight: 500; text-decoration: underline; }
.link-btn:hover { color: #bfdbfe; }
.button-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.row { display: flex; gap: var(--s3); flex-wrap: wrap; justify-content: center; }

/* toggle switch */
.toggle { display: inline-flex; align-items: center; gap: var(--s2); cursor: pointer; color: var(--text-muted); font-weight: 500; white-space: nowrap; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { width: 36px; height: 20px; border-radius: 10px; background: var(--surface-3); position: relative; transition: background-color .15s; }
.toggle-thumb { position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: var(--text); transition: transform .15s; }
.toggle input:checked + .toggle-track { background: var(--accent-strong); }
.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(16px); }
.toggle input:focus-visible + .toggle-track { box-shadow: var(--focus); }
.toggle:hover { color: var(--text); }

/* ---------------------------------------------------------------- palette */
.palette-group { padding: var(--s2) var(--s3) var(--s3); display: grid; gap: var(--s1); }
.palette-group h3, .subhead {
    font-size: var(--fs-caption);
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    padding: var(--s2) var(--s1) var(--s1);
}
.palette-item {
    display: flex;
    align-items: center;
    gap: var(--s3);
    height: 40px;
    padding: 0 var(--s2);
    border: 1px solid transparent;
    border-radius: var(--r-md);
    background: transparent;
    cursor: grab;
    text-align: left;
    font-weight: 500;
}
.palette-item img { width: 24px; height: 24px; flex: none; }
.palette-item:hover { background: var(--surface-2); border-color: var(--border-subtle); }
.palette-item:active { cursor: grabbing; background: var(--surface-3); }

/* ---------------------------------------------------------------- property panel */
.tabs { display: flex; gap: var(--s1); padding: var(--s2) var(--s3) 0; border-bottom: 1px solid var(--border-subtle); }
.tab {
    flex: 1;
    height: 40px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    border-radius: var(--r-sm) var(--r-sm) 0 0;
}
.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); padding: var(--s4) var(--s4) 0; }
.kind-pill { font-size: var(--fs-caption); font-weight: 600; padding: 2px var(--s2); border-radius: 999px; background: #1d4ed833; color: var(--accent-text); }
.panel-section { padding: var(--s4); display: grid; gap: var(--s4); border-bottom: 1px solid var(--border-subtle); }
.panel-section:last-child { border-bottom: none; }
.panel-section h3 { font-size: var(--fs-small); font-weight: 600; display: flex; align-items: center; gap: var(--s2); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.count { font-size: var(--fs-caption); font-weight: 600; color: var(--text-muted); background: var(--surface-2); padding: 0 var(--s2); border-radius: 999px; }
.empty-inline { color: var(--text-muted); }

/* ---------------------------------------------------------------- forms */
.field { display: grid; gap: var(--s1); border: none; padding: 0; margin: 0; min-width: 0; }
.field > label, .field .label, .vlan-picker legend { font-size: var(--fs-small); font-weight: 500; color: var(--text); padding: 0; }
.field input[type=text], .field input[type=number], .field input[type=search], .field select, .field textarea {
    width: 100%;
    height: 36px;
    padding: 0 var(--s3);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--r-md);
    font-size: var(--fs-small);
    transition: border-color .12s, box-shadow .12s;
}
.field textarea { height: auto; padding: var(--s2) var(--s3); resize: vertical; line-height: 1.5; }
.field input.mono { font-family: var(--mono); font-size: var(--fs-small); }
.field input:hover, .field select:hover, .field textarea:hover { border-color: #475569; }
.field input:focus-visible, .field select:focus-visible, .field textarea:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #3b82f640; }
.field input[aria-invalid=true] { border-color: var(--danger); }
.field input::placeholder, .field textarea::placeholder { color: #8391a6; }   /* 5.6:1 on the input background */
.field-hint { font-size: var(--fs-caption); color: var(--text-muted); line-height: 1.4; }
.field-error { font-size: var(--fs-caption); color: var(--danger); font-weight: 500; }
.field-ok { font-size: var(--fs-small); color: var(--ok); font-weight: 500; }
.check { display: flex; gap: var(--s3); align-items: flex-start; cursor: pointer; }
.check input { margin: 3px 0 0; width: 16px; height: 16px; accent-color: var(--accent); flex: none; cursor: pointer; }
.check input:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.check > span { display: grid; gap: 2px; }
.check-label { font-weight: 500; }
.color-row { display: flex; align-items: center; gap: var(--s3); }
.color-row input[type=color] { width: 48px; height: 32px; padding: 0; border: 1px solid var(--border); border-radius: var(--r-sm); background: none; cursor: pointer; }
.color-row input[type=color]:focus-visible { outline: none; box-shadow: var(--focus); }
.vlan-picker { border: none; padding: 0; margin: 0; display: grid; gap: var(--s3); }
.vlan-picker legend { font-weight: 600; margin-bottom: var(--s3); }
.chips { display: flex; flex-wrap: wrap; gap: var(--s2); }
.chip-toggle {
    display: inline-flex; align-items: center; gap: var(--s2); height: 32px; padding: 0 var(--s3);
    border-radius: 999px; border: 1px solid var(--border); background: transparent; cursor: pointer; font-size: var(--fs-small); font-weight: 500;
    color: var(--text-muted);
}
.chip-toggle .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--vlan); opacity: .5; }
.chip-toggle:hover { background: var(--surface-2); color: var(--text); }
.chip-toggle.on { border-color: var(--vlan); color: var(--text); background: color-mix(in srgb, var(--vlan) 16%, transparent); }
.chip-toggle.on .dot { opacity: 1; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; width: fit-content; }
.segmented button { height: 36px; padding: 0 var(--s4); border: none; background: transparent; cursor: pointer; font-weight: 500; color: var(--text-muted); }
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button:hover { background: var(--surface-2); color: var(--text); }
.segmented button.on { background: #1d4ed833; color: var(--text); }

/* list items (ports, hardware, apps…) */
.item { background: var(--surface-2); border: 1px solid var(--border-subtle); border-radius: var(--r-md); }
.item summary {
    display: flex; align-items: center; gap: var(--s2); min-height: 40px; padding: 0 var(--s3); cursor: pointer; list-style: none;
    border-radius: var(--r-md);
}
.item summary::-webkit-details-marker { display: none; }
.item summary::before { content: '›'; color: var(--text-muted); width: 12px; transition: transform .12s; font-size: var(--fs-body); }
.item[open] summary::before { transform: rotate(90deg); }
.item summary:hover { background: var(--surface-3); }
.item summary:focus-visible { outline: none; box-shadow: var(--focus); }
.item-title { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-sub { color: var(--text-muted); font-size: var(--fs-caption); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-left: auto; }
.item-body { padding: var(--s2) var(--s3) var(--s4); display: grid; gap: var(--s4); }
.item-actions { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.item-actions .muted { font-size: var(--fs-caption); }
.swatch { width: 12px; height: 12px; border-radius: 3px; flex: none; }

/* icons */
.icon-list { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.icon-tile { display: flex; align-items: center; gap: var(--s2); height: 36px; padding: 0 var(--s1) 0 var(--s2); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg); }
.icon-tile img { width: 20px; height: 20px; }
.icon-name { font-size: var(--fs-caption); color: var(--text-muted); max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-missing { width: 20px; height: 20px; border: 1px dashed var(--text-muted); border-radius: 4px; display: grid; place-items: center; font-size: var(--fs-caption); color: var(--text-muted); }
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--s2); }
.icon-cell {
    display: grid; justify-items: center; gap: var(--s2); padding: var(--s3) var(--s2); border-radius: var(--r-md); border: 1px solid var(--border-subtle);
    background: var(--surface-2); cursor: pointer; font-size: var(--fs-caption); color: var(--text-muted); min-width: 0;
}
.icon-cell img { width: 32px; height: 32px; }
.icon-cell span:last-child { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-cell:hover { border-color: var(--accent); color: var(--text); background: var(--surface-3); }
.icon-cell:active { transform: translateY(1px); }

/* ---------------------------------------------------------------- modal */
.modal-backdrop { position: fixed; inset: 0; background: rgb(2 6 23 / .6); display: grid; place-items: center; z-index: 50; padding: var(--s5); }
.modal {
    width: min(760px, 100%); max-height: min(720px, 100%); display: flex; flex-direction: column;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow);
}
.modal.narrow { width: min(440px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s4) var(--s4) var(--s4) var(--s5); border-bottom: 1px solid var(--border-subtle); }
.modal-head h2 { font-size: var(--fs-sub); }
.modal-body { padding: var(--s5); overflow-y: auto; display: grid; gap: var(--s5); align-content: start; }
.import-notes { margin: 0; padding-left: var(--s5); display: grid; gap: var(--s2); }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s2); padding: var(--s4) var(--s5); border-top: 1px solid var(--border-subtle); }

/* ---------------------------------------------------------------- empty states, loading */
.empty-state { display: grid; justify-items: center; text-align: center; gap: var(--s3); }
.empty-state.compact { padding: var(--s6) var(--s5); }
.empty-state h2 { font-size: var(--fs-sub); }
.empty-state h4 { font-size: var(--fs-body); font-weight: 600; }
.empty-state p { color: var(--text-muted); max-width: 60ch; }
.empty-state .btn { margin-top: var(--s2); }
.empty-icon { width: 40px; height: 40px; color: var(--accent-text); }
.loading { display: flex; align-items: center; gap: var(--s2); color: var(--text-muted); }
.spinner {
    width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
    display: inline-block; animation: spin .7s linear infinite; flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }
.boot { height: 100vh; display: flex; align-items: center; justify-content: center; gap: var(--s3); color: var(--text-muted); font-size: var(--fs-body); }

#blazor-error-ui {
    display: none; position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%); z-index: 100;
    background: #450a0a; border: 1px solid var(--danger); color: var(--text); padding: var(--s3) var(--s4); border-radius: var(--r-md);
    box-shadow: var(--shadow); align-items: center; gap: var(--s4);
}
#blazor-error-ui .reload { color: #fecaca; font-weight: 600; }
#blazor-error-ui .dismiss { background: none; border: none; color: var(--text); cursor: pointer; font-size: var(--fs-sub); }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation-duration: 0s !important; } }

.legend-row { display: grid; gap: var(--s2); padding-bottom: var(--s3); border-bottom: 1px solid var(--border-subtle); }
.legend-row:last-child { border-bottom: none; padding-bottom: 0; }
.icon-tile[draggable=true] { cursor: grab; }
.icon-tile.dragging { opacity: .4; }
.icon-tile.drop-before { box-shadow: -3px 0 0 var(--accent); }
.icon-btn.small { width: 24px; height: 24px; font-size: var(--fs-body); }
.icon-btn:disabled { opacity: .35; cursor: not-allowed; background: none; }
.color-group { display: grid; gap: var(--s2); }
.color-group .subhead { padding: var(--s2) 0 0; }
.color-item { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); min-height: 40px; }
.color-item label { font-weight: 500; }
.color-item .color-row .mono { font-size: var(--fs-caption); min-width: 64px; }
.inline-row { display: flex; gap: var(--s2); align-items: center; }
.inline-row input { flex: 1; }
.field .custom-input {
    width: 100%; height: 36px; padding: 0 var(--s3); background: var(--bg); border: 1px solid var(--accent);
    border-radius: var(--r-md); font-size: var(--fs-small);
}
.field .custom-input:focus-visible { outline: none; box-shadow: 0 0 0 3px #3b82f640; }
.field .custom-input::placeholder { color: #8391a6; }

/* port table */
.port-table { display: grid; gap: var(--s1); }
.port-row { display: grid; grid-template-columns: 72px minmax(0, 1fr) minmax(0, 1fr) 28px; gap: var(--s2); align-items: center; border-radius: var(--r-sm); }
.port-row.head { font-size: var(--fs-caption); font-weight: 600; color: var(--text-muted); padding-bottom: var(--s1); }
.port-row input, .port-row select {
    width: 100%; height: 32px; padding: 0 var(--s2); background: var(--bg); border: 1px solid var(--border);
    border-radius: var(--r-sm); font-size: var(--fs-small);
}
.port-row input:hover, .port-row select:hover { border-color: #475569; }
.port-row input:focus-visible, .port-row select:focus-visible { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px #3b82f640; }
.port-row .peer { font-size: var(--fs-small); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.port-row .peer.free { color: var(--text-muted); }
.port-row.open, .port-row.focused { background: var(--surface-2); box-shadow: 0 0 0 4px var(--surface-2); }
.port-row.focused { box-shadow: 0 0 0 4px var(--surface-2), inset 3px 0 0 var(--accent); }
.tag-count { margin-left: var(--s1); font-size: var(--fs-caption); font-weight: 600; color: var(--text); background: var(--surface-3); border-radius: 999px; padding: 0 6px; }
.port-detail { display: grid; gap: var(--s4); padding: var(--s3); margin: 0 0 var(--s2); background: var(--surface-2); border-radius: 0 0 var(--r-md) var(--r-md); }
.bulk-add { display: grid; gap: var(--s4); padding: var(--s4); background: var(--surface-2); border-radius: var(--r-md); }
.connection-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s1); }
.connection { display: flex; gap: var(--s2); align-items: baseline; width: 100%; text-align: left; padding: var(--s2); border: 1px solid transparent; border-radius: var(--r-sm); background: none; color: var(--text); font: inherit; font-size: var(--fs-small); cursor: pointer; }
.connection .muted { margin-left: auto; }
.connection:hover { background: var(--surface-2); }
.connection:focus-visible { outline: none; box-shadow: var(--focus); }
.connection:active { border-color: var(--accent); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* canvas editing */
.box-select { position: absolute; display: none; border: 1px solid var(--accent); background: #3b82f61f; border-radius: 2px; pointer-events: none; z-index: 4; }
.canvas .overlay .handle { pointer-events: all; }
.canvas .overlay .handle:hover rect:last-child { fill: var(--accent); }
.rename-input {
    position: absolute; z-index: 6; height: 36px; padding: 0 var(--s3); font: 600 var(--fs-body) var(--font); color: var(--text);
    background: var(--bg); border: 2px solid var(--accent); border-radius: var(--r-md); box-shadow: var(--shadow); outline: none;
}
textarea.rename-input { height: auto; padding: var(--s2) var(--s3); resize: both; line-height: 1.5; font-weight: 500; }
.menu-backdrop { position: absolute; inset: 0; z-index: 7; }
.context-menu {
    position: absolute; z-index: 8; min-width: 220px; padding: var(--s1); display: grid; gap: 2px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow); outline: none;
}
.menu-item {
    display: flex; align-items: center; justify-content: space-between; gap: var(--s4); height: 32px; padding: 0 var(--s3);
    border: none; border-radius: var(--r-sm); background: transparent; color: var(--text); font-size: var(--fs-small); font-weight: 500;
    cursor: pointer; text-align: left;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); outline: none; }
.menu-item:active { background: var(--border); }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: .45; cursor: not-allowed; background: transparent; }
.menu-item kbd { font: 500 var(--fs-caption) var(--mono); color: var(--text-muted); }
.menu-sep { height: 1px; margin: var(--s1) var(--s2); background: var(--border-subtle); }

/* toolbar dropdown */
.menu-anchor { position: relative; }
.menu-backdrop.fixed { position: fixed; z-index: 40; }
.context-menu.dropdown { top: calc(100% + 4px); left: 0; z-index: 41; min-width: 320px; }
.menu-item span { white-space: nowrap; }
.menu-head { padding: var(--s2) var(--s3) var(--s1); font-size: var(--fs-caption); font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; }
.keys dl { display: grid; grid-template-columns: 200px 1fr; gap: var(--s2) var(--s4); margin: var(--s2) 0 0; }
.keys dt { margin: 0; }
.keys dd { margin: 0; color: var(--text-muted); }
.keys kbd, .menu-item kbd { font: 500 var(--fs-caption) var(--mono); }
.keys kbd { padding: 2px var(--s2); border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--surface-2); color: var(--text); }
