/* PidGen web UI - plain CSS, no framework */
:root {
    --bg: #f6f7f9;
    --panel: #ffffff;
    --line: #e3e6ea;
    --line-strong: #cfd4da;
    --text: #1f2937;
    --muted: #6b7280;
    --accent: #2563eb;
    --accent-weak: #e8efff;
    --danger: #b91c1c;
    --warn: #b45309;
    --ok: #15803d;
    --radius: 6px;
    font-size: 14px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; background: #f1f3f5; padding: 1px 4px; border-radius: 3px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 16px 0 8px; }
h3 { font-size: 14px; margin: 14px 0 6px; display: flex; align-items: center; gap: 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--warn); }

/* layout */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 24px; height: 46px; padding: 0 16px; background: #111827; color: #e5e7eb; flex: 0 0 auto; }
.topbar .brand { display: flex; align-items: center; gap: 8px; color: #fff; font-weight: 600; font-size: 16px; }
.topbar .brand:hover { text-decoration: none; }
.topbar nav { display: flex; gap: 4px; }
.topbar nav a { color: #cbd5e1; padding: 6px 10px; border-radius: var(--radius); }
.topbar nav a.active, .topbar nav a:hover { background: #1f2937; color: #fff; text-decoration: none; }
.topbar-right { margin-left: auto; font-size: 12px; color: #9ca3af; }
.content { flex: 1 1 auto; min-height: 0; overflow: auto; }

.page { max-width: 1200px; margin: 0 auto; padding: 20px 24px 40px; }
.page.wide { max-width: none; }
.page.narrow { max-width: 820px; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
.page-head .actions { margin: 0; }
.empty { padding: 40px; text-align: center; color: var(--muted); background: var(--panel); border: 1px dashed var(--line-strong); border-radius: var(--radius); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.form-card h2 { margin-top: 0; }

/* buttons & inputs */
.btn { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border: 1px solid var(--line-strong); background: #fff;
    color: var(--text); border-radius: var(--radius); cursor: pointer; font: inherit; white-space: nowrap; }
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.danger { color: var(--danger); border-color: #f1c4c4; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: #eef0f3; }
.btn.small { height: 24px; padding: 0 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
button.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font: inherit; }
input, select, textarea { font: inherit; color: var(--text); border: 1px solid var(--line-strong); border-radius: 4px; padding: 5px 7px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-weak); border-color: var(--accent); }
input[type=checkbox] { width: auto; }
label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #374151; margin-bottom: 8px; }
label.check { flex-direction: row; align-items: center; gap: 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 4px 16px; }
textarea.code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; line-height: 1.4; white-space: pre; tab-size: 2; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sep { width: 1px; height: 22px; background: var(--line-strong); margin: 0 4px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; flex: 0 0 auto; }
.tag-pill { margin-left: auto; font-size: 10px; padding: 1px 6px; border-radius: 9px; background: #f3f4f6; color: var(--muted); }
.tag-pill.company { background: #fef3c7; color: #92400e; }
kbd { border: 1px solid var(--line-strong); border-bottom-width: 2px; border-radius: 3px; padding: 0 4px; font-size: 12px; background: #fff; }

/* tables */
table.grid { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); }
table.grid th, table.grid td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid th { background: #f9fafb; font-weight: 600; font-size: 12px; color: #374151; position: sticky; top: 0; z-index: 1; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.grid.compact th, table.grid.compact td { padding: 3px 6px; font-size: 12px; }
table.grid tr.selected td { background: var(--accent-weak); }
table.grid tr.modified td:first-child { box-shadow: inset 3px 0 0 #f59e0b; }
table.grid tr.muted-row td { color: var(--muted); }
table.grid tfoot tr.totals td { font-weight: 600; border-top: 2px solid var(--line); background: #f9fafb; position: sticky; bottom: 0; }
.row-actions { white-space: nowrap; text-align: right; }
input.cell { border-color: transparent; background: transparent; padding: 2px 4px; min-width: 90px; }
input.cell:hover { border-color: var(--line-strong); background: #fff; }
input.cell.wide { min-width: 200px; }

.messages { margin: 8px 0; padding-left: 18px; font-size: 12px; }
.messages li { margin: 2px 0; }
.messages li.warning { color: var(--warn); }
.messages li.error { color: var(--danger); font-weight: 600; }
.messages li.info { color: var(--muted); }
ul.plain { list-style: none; padding: 0; margin: 4px 0; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 0; }
.steps li { margin-bottom: 10px; }

/* tabs */
.tabs { display: flex; gap: 2px; align-items: center; border-bottom: 1px solid var(--line); margin-bottom: 8px; flex-wrap: wrap; }
.tabs .tab { border: none; background: none; padding: 7px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font: inherit; }
.tabs .tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
.tabs .tab:hover { color: var(--text); text-decoration: none; }
.tabs .tab.drop-target { color: var(--text); background: color-mix(in srgb, var(--accent) 18%, transparent); border-bottom-color: var(--accent); }
.tabs.big .tab { font-size: 14px; }
.tabs .grow { flex: 1; }
.tabs .check { margin: 0 8px; }

/* editor */
.editor, .pidview { display: flex; flex-direction: column; height: 100%; }
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 7px 12px; background: var(--panel);
    border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.toolbar-title { font-size: 14px; }
.toolbar-title .crumb { color: var(--muted); }
.toolbar-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.dirty { color: #f59e0b; margin-left: 6px; }
.editor-body { flex: 1; display: grid; grid-template-columns: 220px 1fr 310px; min-height: 0; }
.palette, .props { background: var(--panel); overflow: auto; padding: 10px; }
.palette { border-right: 1px solid var(--line); }
.props { border-left: 1px solid var(--line); }
.palette .search { margin-bottom: 8px; }
.palette-group { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 4px; }
.palette-item { display: flex; align-items: center; padding: 5px 6px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 4px;
    cursor: grab; background: #fff; user-select: none; }
.palette-item:hover { border-color: var(--accent); }
.palette-item .palette-name { flex: 1; }
.palette-item .add { border: none; background: none; color: var(--accent); cursor: pointer; font-size: 16px; line-height: 1; }
.canvas { position: relative; min-width: 0; min-height: 0; background: #fbfbfd; }
.canvas .diagram-canvas { width: 100%; height: 100%; }
.props h3 { margin-top: 0; }
.section-title { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 14px 0 6px; border-top: 1px solid var(--line); padding-top: 10px; }
.param { margin-bottom: 6px; }
.statusbar { display: flex; justify-content: space-between; padding: 4px 12px; font-size: 12px; background: var(--panel); border-top: 1px solid var(--line); }
.check-panel { position: relative; background: #fffbeb; border-bottom: 1px solid #fde68a; padding: 6px 30px 6px 14px; max-height: 160px; overflow: auto; }
.check-panel .close { position: absolute; right: 8px; top: 4px; border: none; background: none; font-size: 18px; cursor: pointer; }
.check-panel .ok { color: var(--ok); }

/* block scheme nodes */
.unit-node { position: relative; background: #fff; border: 1.5px solid #64748b; border-radius: 6px; box-shadow: 0 1px 2px rgba(0,0,0,.08);
    display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 8px 10px 6px; }
.unit-node.selected { box-shadow: 0 0 0 3px rgba(37, 99, 235, .35); }
.unit-node.grouped { outline: 3px solid color-mix(in srgb, var(--group) 45%, transparent); outline-offset: 3px;
    background: color-mix(in srgb, var(--group) 7%, #fff); }
.unit-node-group { position: absolute; left: 6px; top: -11px; max-width: 70%; padding: 0 6px; border-radius: 8px; color: #fff;
    font-size: 10px; line-height: 16px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unit-node-count { position: absolute; right: 6px; top: 8px; font-size: 11px; font-weight: 700; color: #334155;
    background: #e2e8f0; border-radius: 8px; padding: 0 6px; line-height: 16px; }
.group-chip { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 8px; color: #fff; font-size: 10px; line-height: 15px; }
.group-input { display: flex; align-items: center; gap: 6px; }
.group-input input { flex: 1; }
.group-list li { margin: 3px 0; }
/* v0.23: "Show air supply" off - faded air supply, bubble arrow under the basins it feeds */
.unit-node.faded { opacity: .5; }
.unit-node-air { position: absolute; left: 22%; top: 100%; margin-top: 1px; display: flex; align-items: flex-start; gap: 5px;
    pointer-events: none; color: #0284c7; font-size: 11px; white-space: nowrap; transform: translateX(-5px); }
.unit-node-air .air-col { display: flex; flex-direction: column; align-items: center; width: 10px; }
.unit-node-air .air-arrow { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent;
    border-bottom: 10px solid #0284c7; }
.unit-node-air .air-bubble { width: 5px; height: 5px; border: 1.2px solid #0284c7; border-radius: 50%; margin-top: 2px; box-sizing: border-box; }
.unit-node-air .air-text { padding-top: 10px; line-height: 12px; }
/* v0.24: block scheme line editing */
.seg-handle { fill: #fff; stroke: #2563eb; stroke-width: 1.5px; cursor: move; }
.seg-handle:hover { fill: #2563eb; }
.diagram-link-vertex { display: none; }
.toolbar label.switch { display: inline-flex; flex-direction: row; align-items: center; gap: 4px; font-size: 13px; margin: 0 4px; white-space: nowrap; }
.unit-node-band { position: absolute; left: 0; right: 0; top: 0; height: 5px; border-radius: 4px 4px 0 0; }
.unit-node-name { font-weight: 600; font-size: 13px; line-height: 1.2; max-width: 100%; overflow-wrap: anywhere; }
.unit-node-type { font-size: 11px; line-height: 1.2; color: var(--muted); margin-top: 2px; }
.unit-node-summary { font-size: 10px; color: #475569; margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
/* v0.38: margin -7.5 px = half the port (6) + the block's 1.5 px border - absolute positions count from inside the
   border, the port offsets from its outer edge (as in the DWG / PDF), so the port centre sits exactly on its line. */
.diagram-port.unit-port { position: absolute; width: 12px; height: 12px; margin: -7.5px; border-radius: 50%; border: 2px solid #334155; background: #fff; cursor: crosshair; z-index: 2; }
.diagram-port.unit-port.out { background: #334155; }
.diagram-port.unit-port.optional { border-style: dashed; }
.diagram-port.unit-port:hover { transform: scale(1.3); border-color: var(--accent); }
.diagram-port.unit-port.has-links { border-color: var(--accent); }
.diagram-port.unit-port.out.has-links { background: var(--accent); }
.unit-port-tip { display: none; position: absolute; left: 14px; top: -6px; background: #111827; color: #fff; font-size: 10px; padding: 2px 5px; border-radius: 3px; white-space: nowrap; pointer-events: none; }
.diagram-port.unit-port:hover .unit-port-tip { display: block; }
.diagram-link .diagram-link-label, .default-link-label { font-size: 11px; }

/* P&ID view */
.msgbar { padding: 5px 14px; font-size: 12px; border-bottom: 1px solid var(--line); background: #f0fdf4; }
.msgbar.warning { background: #fffbeb; }
.msgbar.error { background: #fef2f2; }
.msgbar .messages { max-height: 160px; overflow: auto; }
/* v0.40: sheet | lists | properties - the properties column is always there (unless hidden), so selecting does not resize the sheet. */
.pid-body { flex: 1; display: grid; grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr) 320px; min-height: 0; }
.pid-body.lists-hidden { grid-template-columns: minmax(0, 1fr) 320px; }
.pid-body.props-hidden { grid-template-columns: minmax(0, 3fr) minmax(360px, 2fr); }
.pid-body.lists-hidden.props-hidden { grid-template-columns: minmax(0, 1fr); }
.tabs .lists-toggle, .tabs .props-toggle { margin-left: 6px; }
.sheet-pane, .list-pane { display: flex; flex-direction: column; min-height: 0; padding: 8px 12px; }
.list-pane { border-left: 1px solid var(--line); background: var(--panel); }
.sheet-view { flex: 1; overflow: auto; background: #e5e7eb; border: 1px solid var(--line); border-radius: 4px; }
.sheet-zoom { margin: 0 auto; }
.sheet-view.panning { cursor: grabbing; }
.sheet-view.blueprint { background: #0f2f57; }
.view-options { display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; margin: 0 0 8px; }
.view-options label { display: inline-flex; align-items: center; gap: 4px; margin: 0; }
.view-options select { padding: 2px 4px; font-size: 12px; width: auto; }
.sheet-zoom svg { width: 100%; height: auto; display: block; background: #fff; }
.sheet-view .pid-item { cursor: pointer; }
/* Highlight colours: red / orange on white paper, yellow on the blueprint. Texts only change colour (a stroke makes
   them look bold and hard to read). */
.sheet-view { --hl: #dc2626; --hl-unit: #ea580c; --hl-line: #2563eb; --hl-area: 234, 88, 12; }
.sheet-view.blueprint { --hl: #ffd400; --hl-unit: #ffd400; --hl-line: #ffd400; --hl-area: 255, 212, 0; }
.sheet-view .pid-item:hover :not(text):not(.pid-label) { stroke: var(--accent); }
.sheet-view.blueprint .pid-item:hover :not(text):not(.pid-label) { stroke: #ffe766; }
.sheet-view .pid-item.selected :not(text):not(.pid-label) { stroke: var(--hl) !important; fill-opacity: 1; }
.sheet-view .pid-item.selected text { fill: var(--hl); stroke: none !important; }
/* Editing in the sheet: only symbols and the invisible click targets react to the mouse. */
.sheet-zoom svg > :not(.pid-item):not(.pid-overlay):not(.pe-layer):not(.pid-mark) { pointer-events: none; }
.sheet-zoom svg .pid-item { pointer-events: bounding-box; cursor: move; }
.sheet-zoom svg .pid-item[data-key=""], .sheet-zoom svg .pid-item[data-key="frame"] { pointer-events: none; }
.sheet-zoom svg .pid-item.selected-unit :not(text):not(.pid-label) { stroke: var(--hl-unit) !important; }
.sheet-zoom svg .pid-item.selected-unit text { fill: var(--hl-unit); stroke: none !important; }
/* Texts that move on their own: tag + DN / data lines of a symbol, flow arrow + line number. */
.sheet-zoom svg .pid-label { pointer-events: bounding-box; cursor: grab; }
.sheet-zoom svg .pid-label:hover text { fill: var(--accent); }
.sheet-zoom svg .pid-mark { pointer-events: bounding-box; cursor: grab; }
.sheet-zoom svg .pid-mark:hover :is(text, polygon) { fill: var(--accent); }
.sheet-zoom svg .pid-mark.selected :is(text, polygon) { fill: var(--hl); }
.sheet-zoom svg .dragging { cursor: grabbing; opacity: .75; }
.pid-overlay .pa-title.dragging { fill: rgba(var(--hl-area), .25); stroke: rgba(var(--hl-area), .8); stroke-width: .3; }
.pid-overlay .pl-hit { fill: none; stroke: transparent; stroke-width: 2.6; pointer-events: stroke; cursor: pointer; }
.pid-overlay .pl-hit:hover { stroke: rgba(37, 99, 235, .25); }
.pid-overlay .pl-hit.run { stroke: rgba(37, 99, 235, .3); }
.blueprint .pid-overlay .pl-hit:hover { stroke: rgba(255, 212, 0, .3); }
.blueprint .pid-overlay .pl-hit.run { stroke: rgba(255, 212, 0, .4); }
.pid-overlay .pa-frame { fill: none; stroke: transparent; stroke-width: 2.6; pointer-events: stroke; cursor: move; }
.pid-overlay .pa-title { fill: transparent; pointer-events: fill; cursor: move; }
.pid-overlay .pa:hover .pa-frame, .pid-overlay .pa:hover .pa-title { stroke: rgba(var(--hl-area), .35); }
.pid-overlay .pa.sel .pa-frame { stroke: rgba(var(--hl-area), .6); }
.pid-overlay .pa.sel .pa-title { fill: rgba(var(--hl-area), .12); }
.pe-layer .pl-sel { fill: none; stroke: var(--hl-line); stroke-width: 1; stroke-opacity: .75; pointer-events: stroke; cursor: copy; }
.pe-layer .pe-handle { pointer-events: all; }
.pe-layer .pe-handle.s { fill: var(--hl-line); stroke: #fff; stroke-width: .3; }
.pe-layer .pe-handle.s.h { cursor: ns-resize; }
.pe-layer .pe-handle.s.v { cursor: ew-resize; }
.pe-layer .pe-handle.v { fill: #fff; stroke: var(--hl-line); stroke-width: .5; cursor: pointer; }
.pe-layer .pe-seg { stroke: #f97316; stroke-width: 1.6; stroke-opacity: .8; pointer-events: none; }
.pe-layer .pe-seg.no { stroke: #dc2626; stroke-width: 2.2; }
.pe-layer .pe-handle.s.active { fill: #f97316; }
.pe-layer .pe-handle.e { fill: #fff; stroke: #f97316; stroke-width: .5; }
.pe-layer .pe-handle.e.manual { fill: #f97316; stroke: #fff; }
.pe-layer .pe-handle.e.ey { cursor: ns-resize; }
.pe-layer .pe-handle.e.ex { cursor: ew-resize; }
.blueprint .pe-layer .pe-handle.s { stroke: #0f2f57; }
.blueprint .pe-layer .pe-handle.v { fill: #0f2f57; }
.box-sel { fill: rgba(37, 99, 235, .08); stroke: #2563eb; stroke-width: .4; stroke-dasharray: 1.5 1; pointer-events: none; }
.blueprint .box-sel { fill: rgba(255, 212, 0, .1); stroke: #ffd400; }
.selection-bar { display: flex; align-items: center; gap: 10px; padding: 0 10px; margin-bottom: 6px; background: #eff6ff;
    border: 1px solid #bfdbfe; border-radius: 4px; font-size: 13px; height: 34px; overflow: hidden; white-space: nowrap; }
.selection-bar.empty { background: transparent; border-color: transparent; color: var(--muted); }
.selection-bar > span { overflow: hidden; text-overflow: ellipsis; }
.selection-bar .grow { flex: 1; }
.selection-bar .sel-title { flex: none; }
.selection-bar .btn { flex: none; }
.selection-bar .help { flex: none; display: inline-flex; width: 18px; height: 18px; border-radius: 50%; align-items: center; justify-content: center;
    background: #dbeafe; color: #1d4ed8; font-size: 11px; font-weight: 700; cursor: help; }
.list-tools { display: flex; gap: 6px; align-items: center; margin-bottom: 6px; }
.list-tools .search { margin-left: auto; max-width: 180px; height: 24px; }
.column-chooser { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 8px; border: 1px solid var(--line); border-radius: 4px; margin-bottom: 6px; background: #fafafa; }
.column-chooser label { margin: 0; }
.table-wrap { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 4px; }
.table-wrap table.grid { border: none; }
.hidden-items { font-size: 12px; margin-top: 6px; }

/* library */
.split { display: grid; grid-template-columns: 260px 1fr; gap: 16px; }
.list-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; height: fit-content; }
.list-item { display: flex; align-items: center; width: 100%; text-align: left; border: none; background: none; padding: 6px 8px; border-radius: 4px; cursor: pointer; font: inherit; }
.list-item:hover { background: #f3f4f6; }
.list-item.active { background: var(--accent-weak); font-weight: 600; }
.detail-col { min-width: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.preview-box { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; }
.preview-box svg { width: 100%; height: auto; max-height: 560px; }
.symbol-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.symbol-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; text-align: center; }
.symbol-svg { height: 90px; display: flex; align-items: center; justify-content: center; }
.symbol-svg svg { max-width: 100%; max-height: 90px; width: 100%; height: 90px; }
.symbol-id { font-family: Consolas, monospace; font-size: 11px; margin-top: 4px; }
.frame-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 16px; }
.frame-card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; }
.frame-card h3 { margin-top: 0; }
.frame-svg svg { width: 100%; height: auto; border: 1px solid var(--line); }

#blazor-error-ui { background: #fef3c7; bottom: 0; box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2); display: none; left: 0; padding: 0.6rem 1.25rem 0.7rem 1.25rem; position: fixed; width: 100%; z-index: 1000; }
#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

/* Port layout of a unit in the block scheme editor */
.port-table { width: 100%; border-collapse: collapse; margin: 4px 0; }
.port-table td { padding: 2px 3px; vertical-align: middle; }
.port-table td:first-child { white-space: nowrap; max-width: 110px; overflow: hidden; text-overflow: ellipsis; }
.port-table select { padding: 1px 2px; font-size: 12px; width: auto; }
.port-table input[type=range] { width: 80px; }
.port-table tr.moved td:first-child { color: var(--accent); font-weight: 600; }
.row-buttons { display: flex; gap: 6px; margin: 4px 0 12px; flex-wrap: wrap; }
.sensor-list { list-style: none; margin: 4px 0 6px; padding: 0; }
.sensor-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; border-bottom: 1px solid var(--line); }
.sensor-list .sensor-fn { display: inline-block; min-width: 38px; font-weight: 600; text-align: center; border: 1px solid var(--line); border-radius: 9px; padding: 0 4px; }
.sensor-list .sensor-name { flex: 1; }
.sensor-list .btn { padding: 0 6px; }
.sensor-pick { width: 100%; margin: 4px 0; font-size: 12px; }

/* Library: rule & symbol set bar */
.set-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; padding: 10px 16px; }
.set-bar > label { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.set-bar > label select { min-width: 220px; }
.set-bar .actions { margin-top: 0; margin-left: auto; }
.inline-form { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.inline-form input { min-width: 220px; }
.save-target { padding: 8px 10px; border: 1px dashed var(--line); border-radius: var(--radius); }

/* Shared server: user name, edit locks */
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 13px; border: 1px solid rgba(255,255,255,.25); background: rgba(255,255,255,.08); color: inherit; font: inherit; font-size: 12px; cursor: pointer; }
.user-chip:hover { background: rgba(255,255,255,.18); }
.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding-top: 12vh; z-index: 1000; }
.modal { width: min(460px, calc(100vw - 32px)); box-shadow: 0 12px 40px rgba(0,0,0,.25); }
.modal h2 { margin-top: 0; }
.name-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.lock-banner { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 8px 14px; background: #fef3c7; color: #78350f; border-bottom: 1px solid #fcd34d; font-size: 13px; }
.lock-banner.lost { background: #fee2e2; color: #7f1d1d; border-color: #fca5a5; }
.lock-banner .btn { height: 24px; }
.edit-pill { display: inline-block; margin-left: 6px; padding: 1px 7px; border-radius: 9px; font-size: 11px; background: #fef3c7; color: #92400e; }
fieldset.ro { border: 0; padding: 0; margin: 0; min-width: 0; }
.import-summary { display: grid; gap: 6px; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: #fafafa; }
.import-summary .choice { display: grid; gap: 2px; margin-top: 4px; }
.import-summary .choice label.check { display: flex; flex-direction: row; align-items: center; justify-content: flex-start; gap: 6px; font-weight: normal; }
.import-summary .choice input[type=radio] { width: auto; height: auto; margin: 0; flex: none; }

/* Calculated values of the selected unit (block scheme editor) */
.calc-box { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; margin: 6px 0 4px; background: #f9fafb; line-height: 1.5; }
.calc-box .muted { display: inline-block; min-width: 70px; }

/* v0.22: calculated values (flow, DN, channel size) in light grey, typed ones in the normal colour */
input::placeholder { color: #9aa1ab; opacity: 1; }
select.auto-value { color: #8a919c; }
select.auto-value option { color: var(--text, #111827); }

/* v0.25: junction where a line joins / leaves the main line of a shared port */
.scheme-junction { transform: translate(-50%, -50%); width: 9px; height: 9px; border-radius: 50%; border: 1.5px solid #1f2937; background: #fff; box-sizing: border-box; pointer-events: none; }

/* v0.26: influent / effluent drawn as a data table */
.unit-node.table-mode { background: transparent; border-color: transparent !important; box-shadow: none; }
.unit-node.table-mode > :not(.unit-node-table):not(.diagram-port) { display: none; }
.unit-node-table { position: absolute; margin: -1.5px 0 0 -1.5px; overflow: visible; font-family: Arial, Helvetica, sans-serif; fill: #1f2937; }
.unit-node.table-mode.selected .unit-node-table rect { stroke: var(--accent); stroke-width: 1.5; }
.flow-link-label { white-space: nowrap; font-size: 10px; color: #475569; background: rgba(255,255,255,.85); padding: 0 3px; border-radius: 3px; pointer-events: none; }
.flow-link-label.h { transform: translate(-50%, 0); }
.flow-link-label.v { transform: translate(0, -50%); }
/* v0.38: the flow written with the medium - just below its box (right of it on a vertical run), never on it. */
.medium-link-label { position: relative; }
.flow-link-label.attached { position: absolute; font-weight: 400; line-height: normal; text-align: left; }
.flow-link-label.attached.h { top: 100%; left: 50%; margin-top: 2px; }
.flow-link-label.attached.v { left: 100%; top: 50%; margin-left: 4px; }
/* v0.39: fading arrow + TRANSPORT under containers / at an open transport outlet (coordinates from the block's outer
   corner, hence the border's 1.5 px). */
.unit-node-transport { position: absolute; left: 0; top: 0; margin: -1.5px 0 0 -1.5px; overflow: visible; pointer-events: none;
    font-family: Arial, Helvetica, sans-serif; fill: #1f2937; z-index: 0; }
.diagram-link .movable { pointer-events: auto; cursor: grab; }
.data-table-edit { width: 100%; border-collapse: collapse; margin: 4px 0; }
.data-table-edit th { text-align: left; font-weight: 500; color: #64748b; padding: 1px 2px; }
.data-table-edit td { padding: 1px 2px; }
.data-table-edit input { width: 100%; box-sizing: border-box; padding: 2px 4px; font-size: 12px; }
.data-table-edit td:nth-child(1) { width: 46%; } .data-table-edit td:nth-child(2) { width: 22%; } .data-table-edit td:nth-child(3) { width: 26%; }

/* v0.27: resize handle (bottom right) */
.unit-node-resize { position: absolute; right: -1px; bottom: -1px; width: 10px; height: 10px; cursor: nwse-resize; z-index: 3; opacity: 0;
    background: linear-gradient(135deg, transparent 50%, #64748b 50%); border-radius: 0 0 5px 0; }
.unit-node:hover .unit-node-resize, .unit-node.selected .unit-node-resize { opacity: .8; }

/* ---------- home screen (v0.29, wwwroot/home.js) ---------- */
.pg-home { position: fixed; inset: 0; z-index: 0; overflow: hidden; color: #fff; }
.pg-home .home-bg, .pg-home .home-deco, .pg-home .home-fx { position: fixed; inset: 0; width: 100%; height: 100%; }
.pg-home .home-fx { pointer-events: none; }
.pg-home .home-scene { position: fixed; left: 0; right: 0; top: 46px; bottom: 0; width: 100%; height: calc(100% - 46px); }
body.home-mode .topbar { position: relative; z-index: 10; background: rgba(0, 12, 30, .35); border-bottom: 1px solid rgba(255,255,255,.12); backdrop-filter: blur(6px); }
body.home-mode .topbar nav a.active, body.home-mode .topbar nav a:hover { background: rgba(255,255,255,.12); }
body.home-mode .topbar-right { color: rgba(255,255,255,.8); }
.pg-home .node { cursor: pointer; }
.pg-home .node .lift { transition: transform .25s ease, filter .25s ease; transform-box: fill-box; transform-origin: center; }
.pg-home .node:hover .lift { transform: translateY(-4px) scale(1.025); }
.pg-home .node:hover .poly-fill { filter: brightness(1.25); }
.pg-home .fade { transition: opacity .55s ease; }
.pg-home .hidden { opacity: 0 !important; pointer-events: none; }
.pg-home .dim { opacity: .12 !important; pointer-events: none; }
.pg-home .sub-in { animation: pgSubIn .45s ease both; }
@keyframes pgSubIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.pg-home .bob { animation: pgBob 6s ease-in-out infinite; }
@keyframes pgBob { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
.pg-home .spin { animation: pgSpin 14s linear infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pgSpin { to { transform: rotate(360deg); } }
.pg-home .flow { animation: pgFlow 1.6s linear infinite; }
@keyframes pgFlow { to { stroke-dashoffset: -28; } }
.pg-home .label { font-variant-caps: small-caps; letter-spacing: .04em; fill: #fff; pointer-events: none; }
.pg-home .home-switcher { position: fixed; left: 50%; bottom: 18px; transform: translateX(-50%); z-index: 20; display: flex; gap: 4px; padding: 5px;
    border-radius: 999px; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.25); backdrop-filter: blur(6px); }
.pg-home .home-switcher button { font: 600 13px "Segoe UI", system-ui, sans-serif; color: #dfe9f5; background: transparent; border: 0;
    padding: 7px 14px; border-radius: 999px; cursor: pointer; }
.pg-home .home-switcher button.on { background: #fff; color: #0b2a4a; }
.pg-home .home-switcher span { font-size: 12px; color: #9fb4cc; align-self: center; padding: 0 8px 0 10px; }
.pg-home .home-back { position: fixed; left: 18px; top: 62px; z-index: 12; font: 600 13px "Segoe UI", system-ui, sans-serif; color: #fff; cursor: pointer;
    background: rgba(255,255,255,.12); border: 1px solid rgba(255,255,255,.3); padding: 6px 14px; border-radius: 999px;
    font-variant-caps: small-caps; letter-spacing: .05em; transition: opacity .3s; }

/* ---------- home screen v0.30: open New Project blocks (home.js places Home.razor's data-slot HTML) ---------- */
.pg-home-slots, .pg-home .home-tips { position: fixed; left: 0; right: 0; top: 46px; bottom: 0; pointer-events: none; overflow: hidden;
    --hp-acc: #b6ff6a; --hp-ink: #04222b; --hp-box: rgba(2, 34, 42, .88); --hp-line: rgba(160, 255, 240, .55); --hp-field: rgba(0, 18, 24, .6); }
.pg-home-slots[data-theme="A"], .pg-home .home-tips[data-theme="A"] {
    --hp-acc: #8fd0ff; --hp-ink: #062040; --hp-box: rgba(6, 28, 56, .9); --hp-line: rgba(255, 255, 255, .55); --hp-field: rgba(4, 20, 44, .65); }
.pg-home-slots[data-theme="C"], .pg-home .home-tips[data-theme="C"] {
    --hp-acc: #111827; --hp-ink: #ffffff; --hp-box: rgba(255, 255, 255, .97); --hp-line: #cfd4da; --hp-field: #ffffff; }
.pg-home-slots { z-index: 1; color: #fff; font-family: "Segoe UI", system-ui, sans-serif; }
.pg-home .home-tips { z-index: 2; }
.pg-home-slots [data-slot] { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-sizing: border-box; pointer-events: auto;
    visibility: hidden; transition: opacity .35s ease; }
.pg-home-slots [data-slot].hp-placed { visibility: visible; }
.pg-home-slots [data-slot].hp-off { opacity: 0; pointer-events: none; }
/* file box: slides out from under the hub (home.js draws a copy of the hub above it) */
.home-front { position: fixed; left: 0; right: 0; top: 46px; bottom: 0; width: 100%; height: calc(100% - 46px); z-index: 2; pointer-events: none; }
.home-front .spin { animation: pgSpin 14s linear infinite; transform-box: fill-box; transform-origin: center; }
.hp-drop { display: flex; align-items: center; gap: 7px; padding: 0 8px 0 26px; border: 1.2px dashed var(--hp-line); border-radius: 0 7px 7px 0;
    background: var(--hp-box); font-size: 9.5px; box-shadow: 0 4px 14px rgba(0, 0, 0, .35); transition: box-shadow .2s, border-color .2s; }
.hp-drop.hp-placed:not(.hp-off) { animation: hpSlide .55s cubic-bezier(.2, .8, .2, 1) .35s both; }
@keyframes hpSlide { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.hp-drop.hp-dragging { border-style: solid; border-color: var(--hp-acc); box-shadow: 0 0 0 1.5px var(--hp-acc), 0 0 16px var(--hp-acc); }
.hp-pick { flex: none; display: inline-block; margin: 0; cursor: pointer; padding: 4px 8px; border-radius: 4px; background: var(--hp-acc); color: var(--hp-ink); font-weight: 700;
    font-size: 9px; letter-spacing: .02em; white-space: nowrap; }
.hp-pick:hover { filter: brightness(1.12); }
.hp-pick input[type=file] { display: none; }
.hp-line { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: .85; font-style: italic; }
.hp-line.hp-file { font-style: normal; font-weight: 600; opacity: 1; }
.hp-line.hp-error { font-style: normal; color: #ffb4a8; opacity: 1; }
/* question / messages block */
.hp-ask { display: flex; flex-direction: column; gap: 5px; padding: 2px 4px; font-size: 11px; line-height: 1.35; overflow: auto; }
.hp-ask .hp-q { font-weight: 700; font-size: 12.5px; }
.hp-ask .hp-btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: auto; padding-bottom: 2px; }
.hp-msgs { margin: 0; padding-left: 14px; font-size: 10.5px; opacity: .92; }
.hp-btn { font: 600 10.5px "Segoe UI", system-ui, sans-serif; color: #fff; background: rgba(255, 255, 255, .1); border: 1px solid var(--hp-line);
    border-radius: 999px; padding: 4px 10px; cursor: pointer; }
.hp-btn:hover, .hp-btn.primary { background: var(--hp-acc); color: var(--hp-ink); border-color: var(--hp-acc); }
.hp-busy::after { content: ''; display: inline-block; width: 8px; height: 8px; margin-left: 6px; vertical-align: -1px; border: 1.5px solid var(--hp-acc);
    border-right-color: transparent; border-radius: 50%; animation: pgSpin .8s linear infinite; }
/* New project form */
.hp-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 11px 16px; align-content: start; padding: 2px; font-size: 10.5px; }
.hp-form label { display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; margin: 0; color: #fff; font-size: 10.5px;
    font-weight: 600; letter-spacing: .02em; }
.hp-form label .opt { font-weight: 400; opacity: .7; }
.hp-form label .req { color: var(--hp-acc); }
.hp-form input, .hp-form select { font: 400 11.5px "Segoe UI", system-ui, sans-serif; height: 24px; box-sizing: border-box; padding: 0 7px; color: #fff;
    background: var(--hp-field); border: 1px solid var(--hp-line); border-radius: 4px; outline: none; width: 100%; }
.hp-form input::placeholder { color: rgba(255, 255, 255, .45); }
.hp-form input:focus, .hp-form select:focus { border-color: var(--hp-acc); box-shadow: 0 0 0 1px var(--hp-acc); }
.hp-form select option { color: #111; background: #fff; }
/* My Projects list (v0.30) */
.hp-list { display: flex; flex-direction: column; font-size: 13.5px; }
.hp-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.hp-table th { text-align: left; font-weight: 600; font-size: 12px; letter-spacing: .03em; opacity: .75; padding: 0 8px 5px; white-space: nowrap;
    border-bottom: 1px solid var(--hp-line); }
.hp-table td { padding: 0 8px; height: 29px; border-bottom: 1px solid rgba(255, 255, 255, .1); white-space: nowrap; }
.hp-table tbody tr:hover td { background: rgba(255, 255, 255, .07); }
.hp-table .num { text-align: right; }
.hp-table .hp-name { max-width: 330px; overflow: hidden; text-overflow: ellipsis; }
.hp-table .hp-name a { color: var(--hp-acc); font-weight: 600; text-decoration: none; }
.hp-table .hp-name a:hover { text-decoration: underline; }
.hp-table .hp-acts { text-align: right; }
.hp-table .hp-acts .hp-btn { padding: 2px 9px; font-size: 11.5px; margin-left: 4px; text-decoration: none; display: inline-block; }
.hp-btn.ghost { border-color: transparent; background: transparent; }
.hp-btn.ghost:hover { border-color: var(--hp-acc); }
.hp-btn.danger, .hp-btn.danger:hover { background: #c0392b; border-color: #e74c3c; color: #fff; }
.hp-pill { display: inline-block; margin-left: 5px; padding: 0 6px; border-radius: 8px; font-size: 10.5px; background: #fef3c7; color: #92400e; font-weight: 600; }
.hp-foot { margin-top: 8px; font-size: 11.5px; opacity: .7; }
.hp-empty { padding: 24px 4px; font-size: 14px; opacity: .85; }
/* hover hint (Import Block Scheme) */
.pg-home .home-tip { position: absolute; left: 0; top: 0; transform-origin: 0 0; box-sizing: border-box; padding: 7px 10px; font: 400 10px/1.45 "Segoe UI", system-ui, sans-serif;
    color: #eaf6ff; background: var(--hp-box); border: 1px solid var(--hp-line); border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .35);
    transition: opacity .3s ease; pointer-events: none; }
.pg-home .home-tip code { font-size: 9px; background: rgba(255, 255, 255, .14); color: #fff; padding: 0 3px; border-radius: 3px; }
/* blocks */
.pg-home .node.slot-node { cursor: default; }
.pg-home .node.slot-node .lift, .pg-home .node.open .lift { transform: none !important; }
.pg-home .node.slot-node:hover .poly-fill { filter: none; }
.pg-home .node.disabled { cursor: not-allowed; }
.pg-home .node.disabled .lift { opacity: .38; transform: none !important; }
.pg-home .node.disabled:hover .poly-fill { filter: none; }
.pg-home .node.busy .poly-fill { animation: hpPulse 1.1s ease-in-out infinite; }
@keyframes hpPulse { 50% { filter: brightness(1.6); } }
.pg-home .ai-hub { cursor: pointer; }
.pg-home .ai-hub .ai-ring { transition: stroke-width .2s; }
.pg-home .ai-hub .ai-dot { opacity: 0; transition: opacity .2s; }
.pg-home .ai-hub.on .ai-dot { opacity: 1; }
.pg-home .ai-hub.on .ai-ring { stroke: var(--acc); stroke-width: 2.4; filter: drop-shadow(0 0 4px var(--acc)); }
.pg-home .ai-hub:hover .ai-ring { stroke-width: 2.8; }
.pg-home .ai-hub.off { opacity: .35; cursor: not-allowed; }
.pg-home .ai-text { fill: #fff; font-family: "Segoe UI", system-ui, sans-serif; pointer-events: none; }
.pg-home .ai-labels .ai-off { opacity: .45; }
/* My Projects: the project just imported (v0.30) */
.grid tr.row-new td { animation: rowNew 4s ease 1 both; }
@keyframes rowNew { 0%, 45% { background: #fff1b8; } 100% { background: transparent; } }

/* ---------- v0.31: 'Engineering' home theme (data-theme C) - white drafting sheet, editor colours ---------- */
body.home-mode[data-home-theme="C"] .topbar { background: #111827; border-bottom-color: transparent; backdrop-filter: none; }
.pg-home[data-theme="C"] { color: #1f2937; }
.pg-home[data-theme="C"] .label, .pg-home[data-theme="C"] .ai-text { fill: #1f2937; }
.pg-home[data-theme="C"] .node:hover .poly-fill { filter: drop-shadow(0 10px 14px rgba(15, 23, 42, .16)); }
.pg-home[data-theme="C"] .node.busy .poly-fill { animation-name: hpPulseLight; }
@keyframes hpPulseLight { 50% { filter: brightness(.9); } }
.pg-home[data-theme="C"] .home-switcher { background: #111827; border-color: #111827; }
.pg-home[data-theme="C"] .home-switcher button.on { color: #111827; }
.pg-home[data-theme="C"] .home-back { color: #fff; background: #111827; border-color: #111827; }
.pg-home-slots[data-theme="C"] { color: #1f2937; }
.pg-home-slots[data-theme="C"] .hp-drop { box-shadow: 0 4px 14px rgba(15, 23, 42, .12); }
.pg-home-slots[data-theme="C"] .hp-line.hp-error { color: var(--danger); }
.pg-home-slots[data-theme="C"] .hp-form label { color: #374151; }
.pg-home-slots[data-theme="C"] .hp-form input, .pg-home-slots[data-theme="C"] .hp-form select { color: #1f2937; }
.pg-home-slots[data-theme="C"] .hp-form input::placeholder { color: #9ca3af; }
.pg-home-slots[data-theme="C"] .hp-btn { color: #1f2937; background: #fff; }
.pg-home-slots[data-theme="C"] .hp-btn:hover, .pg-home-slots[data-theme="C"] .hp-btn.primary { color: #fff; background: #111827; border-color: #111827; }
.pg-home-slots[data-theme="C"] .hp-btn.ghost { background: transparent; border-color: transparent; }
.pg-home-slots[data-theme="C"] .hp-btn.ghost:hover { color: #1f2937; background: transparent; border-color: #111827; }
.pg-home-slots[data-theme="C"] .hp-btn.danger, .pg-home-slots[data-theme="C"] .hp-btn.danger:hover { background: #c0392b; border-color: #e74c3c; color: #fff; }
.pg-home-slots[data-theme="C"] .hp-table td { border-bottom-color: var(--line); }
.pg-home-slots[data-theme="C"] .hp-table tbody tr:hover td { background: #f3f4f6; }
.pg-home .home-tips[data-theme="C"] .home-tip { color: #1f2937; box-shadow: 0 6px 18px rgba(15, 23, 42, .12); }
.pg-home .home-tips[data-theme="C"] .home-tip code { background: #f1f3f5; color: #1f2937; }

/* v0.31: project tables - sort by clicking a column title, Find field */
.hp-table th.hp-sort { cursor: pointer; user-select: none; }
.hp-table th.hp-sort:hover { opacity: 1; color: var(--hp-acc); }
.hp-table th.hp-find { opacity: 1; text-align: right; padding-bottom: 4px; }
.hp-table th.hp-find label { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; margin: 0; font-weight: 600; font-size: 12px; color: inherit; white-space: nowrap; }
.hp-find input { font: 400 11.5px "Segoe UI", system-ui, sans-serif; height: 22px; width: 260px; box-sizing: border-box; padding: 0 7px; color: #fff;
    background: var(--hp-field); border: 1px solid var(--hp-line); border-radius: 4px; outline: none; }
.hp-find input::placeholder { color: rgba(255, 255, 255, .45); }
.hp-find input:focus { border-color: var(--hp-acc); box-shadow: 0 0 0 1px var(--hp-acc); }
.hp-table td.hp-none { opacity: .75; font-style: italic; }
.pg-home-slots[data-theme="C"] .hp-find input { color: #1f2937; }
.pg-home-slots[data-theme="C"] .hp-find input::placeholder { color: #9ca3af; }
table.grid th.sortable { cursor: pointer; user-select: none; }
table.grid th.sortable:hover { color: var(--accent); }
table.grid th.find-cell { text-align: right; font-weight: 600; }
table.grid th.find-cell label { display: inline-flex; flex-direction: row; align-items: center; gap: 8px; margin: 0; color: inherit; font-size: 12px; white-space: nowrap; }
table.grid th.find-cell input { width: 240px; font-weight: 400; padding: 3px 7px; }

/* ================================================================
   v0.32: home screen Library → Frames / Symbols / Media (LibraryPanel.razor)
   ================================================================ */
.hp-lib { gap: 6px; font-size: 12px; }
.hp-lib label { margin: 0; color: inherit; }
.hp-lib-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding-bottom: 7px; border-bottom: 1px solid var(--hp-line); }
.hp-lib-bar .hp-lib-set, .hp-lib-bar .hp-lib-findbox { flex-direction: row; align-items: center; gap: 7px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.hp-lib select, .hp-lib input:not([type=checkbox]):not([type=color]):not([type=file]) {
    font: 400 12px "Segoe UI", system-ui, sans-serif; height: 25px; box-sizing: border-box; padding: 0 7px; color: #fff; width: auto;
    background: var(--hp-field); border: 1px solid var(--hp-line); border-radius: 4px; outline: none; }
.hp-lib select { min-width: 220px; }
.hp-lib select option { color: #111; background: #fff; }
.hp-lib input::placeholder { color: rgba(255, 255, 255, .45); }
.hp-lib select:focus, .hp-lib input:focus { border-color: var(--hp-acc); box-shadow: 0 0 0 1px var(--hp-acc); }
.hp-lib-findbox input { width: 190px; }
.hp-lib-in { width: 190px; }
.hp-lib-gap { flex: 1; }
.hp-lib .hp-btn { font-size: 12px; text-decoration: none; display: inline-flex; align-items: center; gap: 4px; line-height: 1.2; }
/* the main buttons: bigger, filled, easy to notice */
.hp-lib .hp-lib-main { font-size: 13px; padding: 5px 14px; background: var(--hp-acc); color: var(--hp-ink); border-color: var(--hp-acc); }
.hp-lib .hp-lib-main:hover { filter: brightness(1.12); }
.hp-lib .hp-lib-rm:not(:disabled) { background: #c0392b; border-color: #e74c3c; color: #fff; }
.hp-lib .hp-btn:disabled, .hp-lib .hp-btn.hp-disabled { opacity: .35; cursor: not-allowed; filter: none; }
.hp-lib-up { position: relative; overflow: hidden; cursor: pointer; }
.hp-lib-up input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; font-size: 0; }
.hp-lib-note { display: flex; align-items: flex-start; gap: 10px; padding: 6px 10px; font-size: 11.5px; line-height: 1.4;
    border: 1px solid var(--hp-line); border-radius: 6px; background: rgba(255, 255, 255, .06); }
.hp-lib-note > :first-child { flex: 1; }
.hp-lib-warn { border-color: #e74c3c; background: rgba(231, 76, 60, .12); }
.hp-lib-w { margin-top: 3px; color: #ffd0c8; }
.hp-lib-acts { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hp-lib-close { padding: 1px 7px; }
.hp-lib .hp-msgs { font-size: 11.5px; }
.hp-lib .hp-error { color: #ffb4a8; font-weight: 600; }
.hp-lib .hp-pill { margin-left: 5px; font-size: 9.5px; font-weight: 700; padding: 0 6px; border-radius: 8px; vertical-align: 1px;
    background: var(--hp-acc); color: var(--hp-ink); }
.hp-link { background: none; border: none; padding: 0; color: var(--hp-acc); font: inherit; cursor: pointer; text-decoration: underline; }
/* items: a scrolling body */
.hp-lib-body { flex: 1; min-height: 0; overflow: auto; padding: 2px 4px 2px 0; }
.hp-lib-group { margin: 8px 0 5px; font-size: 11.5px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; opacity: .8; }
.hp-lib-group span { font-weight: 400; opacity: .7; margin-left: 4px; }
.hp-lib-grid { display: grid; gap: 10px; }
.hp-lib-grid.hp-frames { grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); }
.hp-lib-grid.hp-symbols { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.hp-card { display: flex; flex-direction: column; gap: 3px; padding: 6px; border: 1.5px solid var(--hp-line); border-radius: 7px; cursor: pointer;
    user-select: none; background: rgba(255, 255, 255, .04); transition: border-color .15s, box-shadow .15s; }
.hp-card:hover { border-color: var(--hp-acc); }
.hp-card.hp-sel { border-color: var(--hp-acc); box-shadow: 0 0 0 2px var(--hp-acc); background: rgba(255, 255, 255, .12); }
.hp-card-pic { background: #fff; border-radius: 4px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.hp-frames .hp-card-pic { height: 170px; }
.hp-symbols .hp-card-pic { height: 78px; padding: 4px; }
.hp-card-pic svg { width: 100%; height: 100%; display: block; }
.hp-card-name { font-weight: 700; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp-card-sub { font-size: 10.5px; opacity: .72; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* media table */
.hp-media tbody tr.hp-row { cursor: pointer; user-select: none; }
.hp-media tbody tr.hp-sel td { background: rgba(255, 255, 255, .16); box-shadow: inset 0 1px 0 var(--hp-acc), inset 0 -1px 0 var(--hp-acc); }
.hp-media tbody tr.hp-sel td:first-child { box-shadow: inset 3px 0 0 var(--hp-acc), inset 0 1px 0 var(--hp-acc), inset 0 -1px 0 var(--hp-acc); }
.hp-media .hp-code { font-weight: 700; }
.hp-media .swatch { width: 12px; height: 12px; vertical-align: -1px; border: 1px solid rgba(255, 255, 255, .5); }
.hp-media th.hp-find input { width: 220px; }
/* media Add / Edit form with the colour palette */
.hp-lib-form { display: grid; grid-template-columns: 130px 1.6fr 1fr 1fr 1fr 110px 120px; gap: 8px 12px; align-items: end; padding: 8px 10px;
    border: 1px solid var(--hp-acc); border-radius: 7px; background: rgba(255, 255, 255, .06); }
.hp-lib-form .hp-lib-ftitle { grid-column: 1 / -1; font-weight: 700; font-size: 13px; }
.hp-lib-form > label { display: flex; flex-direction: column; gap: 3px; font-size: 11px; font-weight: 600; }
.hp-lib-form > label input:not([type=checkbox]), .hp-lib-form > label select { width: 100% !important; min-width: 0 !important; }
.hp-lib-form > label .req { color: var(--hp-acc); }
.hp-lib-form > label.hp-check { flex-direction: row; align-items: center; gap: 6px; height: 25px; white-space: nowrap; }
.hp-lib-form > label.hp-check input { width: auto; margin: 0; }
.hp-lib-form input:disabled { opacity: .6; }
.hp-lib-pal { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: 11px; font-weight: 600; }
.hp-lib-pal > span:first-child { margin-right: 4px; }
.hp-sw { width: 24px; height: 24px; padding: 0; border-radius: 5px; border: 2px solid rgba(255, 255, 255, .35); cursor: pointer; }
.hp-sw:hover { transform: scale(1.12); }
.hp-sw.on { border-color: var(--hp-acc); box-shadow: 0 0 0 2px var(--hp-acc); }
.hp-lib-pal label.hp-sw-custom { flex-direction: row; align-items: center; gap: 5px; margin-left: 8px; font-size: 11px; cursor: pointer; }
.hp-sw-custom input[type=color] { width: 30px; height: 24px; padding: 0; border: 1px solid var(--hp-line); border-radius: 4px; background: none; cursor: pointer; }
.hp-sw-now { margin-left: 10px; font-weight: 400; font-family: Consolas, monospace; }
.hp-sw-now .swatch { width: 14px; height: 14px; vertical-align: -2px; }
.hp-lib-form .hp-lib-acts { grid-column: 1 / -1; }
/* the enlarged frame / symbol (double-click): 60% of the screen height, X at the top right */
.hp-zoom-back { position: absolute; inset: 0; z-index: 5; pointer-events: auto; display: flex; align-items: center; justify-content: center;
    background: rgba(0, 0, 0, .45); animation: hpFade .2s ease both; }
.hp-zoom { position: relative; height: 60vh; max-width: 92vw; box-sizing: border-box; display: flex; flex-direction: column; padding: 10px 12px 12px;
    background: var(--hp-box); border: 1.5px solid var(--hp-acc); border-radius: 10px; box-shadow: 0 18px 50px rgba(0, 0, 0, .5); }
.hp-zoom-head { display: flex; align-items: center; gap: 12px; padding: 0 2px 8px; font-size: 14px; white-space: nowrap; }
.hp-zoom-head > span { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.hp-zoom-sub { font-size: 12px; opacity: .75; margin-left: 6px; }
.hp-zoom-x { flex: none; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--hp-line); background: rgba(255, 255, 255, .1); color: inherit;
    font-size: 15px; cursor: pointer; line-height: 1; }
.hp-zoom-x:hover { background: #c0392b; border-color: #e74c3c; color: #fff; }
.hp-zoom-pic { flex: 1; min-height: 0; background: #fff; border-radius: 6px; padding: 8px; display: flex; }
.hp-zoom-pic { overflow: hidden; }
.hp-zoom-pic svg { width: 100%; height: 100%; display: block; cursor: zoom-in; }
.hp-zoom-pic svg.hp-zoomed { cursor: grab; }
.hp-zoom-pic svg.hp-panning { cursor: grabbing; }
.hp-zoom-hint { font-size: 11px; opacity: .65; white-space: nowrap; }
@keyframes hpFade { from { opacity: 0; } to { opacity: 1; } }
/* Engineering (light) theme */
.pg-home-slots[data-theme="C"] .hp-lib select, .pg-home-slots[data-theme="C"] .hp-lib input:not([type=checkbox]):not([type=color]):not([type=file]) { color: #1f2937; }
.pg-home-slots[data-theme="C"] .hp-lib input::placeholder { color: #9ca3af; }
.pg-home-slots[data-theme="C"] .hp-lib .hp-lib-main { background: #111827; color: #fff; border-color: #111827; }
.pg-home-slots[data-theme="C"] .hp-lib .hp-lib-rm:not(:disabled) { background: #c0392b; border-color: #e74c3c; }
.pg-home-slots[data-theme="C"] .hp-lib-note { background: #f9fafb; }
.pg-home-slots[data-theme="C"] .hp-lib-warn { background: #fef2f2; }
.pg-home-slots[data-theme="C"] .hp-lib-w, .pg-home-slots[data-theme="C"] .hp-lib .hp-error { color: #b91c1c; }
.pg-home-slots[data-theme="C"] .hp-card { background: #fff; }
.pg-home-slots[data-theme="C"] .hp-card.hp-sel { background: #f3f4f6; }
.pg-home-slots[data-theme="C"] .hp-card-pic, .pg-home-slots[data-theme="C"] .hp-zoom-pic { border: 1px solid #e5e7eb; }
.pg-home-slots[data-theme="C"] .hp-media tbody tr.hp-sel td { background: #e5e7eb; }
.pg-home-slots[data-theme="C"] .hp-media .swatch { border-color: #cfd4da; }
.pg-home-slots[data-theme="C"] .hp-sw { border-color: #d1d5db; }
.pg-home-slots[data-theme="C"] .hp-lib-form, .pg-home-slots[data-theme="C"] .hp-zoom { background: #fff; }
.pg-home-slots[data-theme="C"] .hp-zoom-back { background: rgba(15, 23, 42, .35); }
.pg-home-slots[data-theme="C"] .hp-pill { color: #fff; }

/* ================================================================
   v0.33: home screen Library → Unit Types & Rules (UnitTypesPanel.razor)
   ================================================================ */
.hp-ut { font-size: 12.5px; }
.hp-ut-body { display: flex; flex-direction: column; gap: 12px; }
.hp-ut-main { display: grid; grid-template-columns: 240px minmax(0, 0.9fr) minmax(0, 1.25fr); gap: 14px; height: 500px; flex: none; }
.hp-ut-list, .hp-ut-mid, .hp-ut-right { min-height: 0; display: flex; flex-direction: column; }
/* left: list */
.hp-ut-list { border: 1px solid var(--hp-line); border-radius: 7px; padding: 6px; background: rgba(255, 255, 255, .04); }
.hp-ut-tools { display: flex; flex-direction: column; gap: 5px; padding-bottom: 6px; border-bottom: 1px solid var(--hp-line); }
.hp-ut-tools input { width: 100% !important; }
.hp-ut-sort { font-size: 11.5px; opacity: .9; display: flex; gap: 10px; align-items: center; }
.hp-ut-sort .hp-link { text-decoration: none; opacity: .75; }
.hp-ut-sort .hp-link.on { opacity: 1; font-weight: 700; text-decoration: underline; }
.hp-ut-items { flex: 1; min-height: 0; overflow: auto; padding-top: 2px; }
.hp-ut-item { display: flex; align-items: center; gap: 6px; padding: 4px 6px; margin: 1px 0; border-radius: 5px; cursor: pointer; user-select: none;
    border: 1px solid transparent; }
.hp-ut-item:hover { background: rgba(255, 255, 255, .08); }
.hp-ut-item.on { background: rgba(255, 255, 255, .14); border-color: var(--hp-acc); }
.hp-ut-item.hp-sel { box-shadow: inset 3px 0 0 var(--hp-acc); }
.hp-ut-item input[type=checkbox] { margin: 0; width: auto; flex: none; cursor: pointer; }
.hp-ut-item .swatch { width: 11px; height: 11px; margin: 0; }
.hp-ut-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hp-ut-cat { font-size: 10.5px; opacity: .65; white-space: nowrap; }
.hp-ut-tag { font-size: 9.5px; opacity: .7; border: 1px solid var(--hp-line); border-radius: 7px; padding: 0 5px; white-space: nowrap; }
.hp-ut-list .hp-lib-group { margin: 7px 2px 2px; font-size: 10.5px; }
.hp-ut-list .hp-foot { margin-top: 4px; }
/* middle: title, description, preview */
.hp-ut-title { display: flex; align-items: baseline; gap: 7px; font-size: 16px; flex-wrap: wrap; }
.hp-ut-title .swatch { width: 13px; height: 13px; margin: 0; align-self: center; }
.hp-ut-id { opacity: .6; font-weight: 600; }
.hp-ut-desc { font-size: 12px; line-height: 1.4; opacity: .88; margin: 4px 0 8px; max-height: 66px; overflow: auto; }
.hp-ut-preview { flex: 1; min-height: 0; background: #fff; border-radius: 6px; border: 1px dashed var(--hp-line); padding: 6px; display: flex; overflow: hidden; }
.hp-ut-preview svg { width: 100%; height: 100%; display: block; }
.hp-ut-pmsgs { margin-top: 5px; max-height: 60px; overflow: auto; }
/* right: ports and parameters */
.hp-ut-right { overflow: auto; padding-right: 3px; }
.hp-ut-h { font-weight: 700; font-size: 13px; margin: 8px 0 4px; display: flex; align-items: baseline; gap: 10px; }
.hp-ut-h:first-child { margin-top: 0; }
.hp-ut-hint { font-size: 11px; font-weight: 400; opacity: .65; }
.hp-ut-save { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-height: 30px; padding: 3px 8px; border-radius: 6px; border: 1px dashed var(--hp-line); }
.hp-ut-save.dirty { border: 1px solid var(--hp-acc); background: rgba(255, 255, 255, .08); font-weight: 600; }
.hp-ut-tab { font-size: 11.5px; table-layout: fixed; }
.hp-ut-tab th { font-size: 10.5px; padding: 0 4px 4px; }
.hp-ut-tab td { height: 25px; padding: 0 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hp-ut-tab code { font-size: 10.5px; }
/* v0.33 fix: formulas in the read-only tables - the page's light code background made them unreadable on the dark themes */
.pg-home-slots .hp-lib code { background: rgba(255, 255, 255, .12); color: inherit; }
.pg-home-slots[data-theme="C"] .hp-lib code { background: #f1f3f5; color: #1f2937; }
.hp-ut-tab tr.hp-ut-opt td { opacity: .65; }
.hp-lib .hp-ut-tab .hp-c { height: 21px; font-size: 11px; padding: 0 4px; width: 100%; min-width: 0; border-color: transparent; background: transparent; }
.hp-lib .hp-ut-tab .hp-c:hover { border-color: var(--hp-line); }
.hp-lib .hp-ut-tab .hp-c:focus { border-color: var(--hp-acc); background: var(--hp-field); }
.hp-lib .hp-ut-tab select.hp-c { min-width: 0; padding: 0 1px; }
.hp-lib .hp-ut-tab .hp-c:disabled { opacity: .3; }
.hp-ut-tab .hp-c-id { font-weight: 600; }
.hp-ut-tab .hp-c-f { font-family: Consolas, monospace; }
.hp-ut-tab .hp-c-chk { text-align: center; }
.hp-ut-tab .hp-c-chk input { width: auto; margin: 0; }
.hp-x { border: none; background: none; color: inherit; opacity: .5; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 3px; }
.hp-x:hover { opacity: 1; color: #e74c3c; }
/* bottom: rule file */
.hp-ut-rule { display: flex; flex-direction: column; gap: 6px; padding-top: 8px; border-top: 1px solid var(--hp-line); }
.hp-ut-rule .hp-ut-h { margin: 0; }
.hp-lib textarea.hp-ut-code { font: 12px/1.45 Consolas, "Cascadia Mono", monospace; height: 380px; resize: vertical; white-space: pre; overflow: auto;
    color: #1f2937; background: #fff; border: 1px solid var(--hp-line); border-radius: 6px; padding: 8px 10px; box-sizing: border-box; width: 100%; }
.hp-lib textarea.hp-ut-code[readonly] { background: #f3f4f6; }
/* Add / Edit pop-up */
.hp-pop { position: relative; width: 760px; max-width: 92vw; box-sizing: border-box; padding: 10px 14px 14px; color: inherit;
    background: var(--hp-box); border: 1.5px solid var(--hp-acc); border-radius: 10px; box-shadow: 0 18px 50px rgba(0, 0, 0, .5); }
.hp-pop .hp-lib-form.hp-pop-form { grid-template-columns: 1fr 1.4fr 1fr 0.8fr; border: none; background: none; padding: 4px 0 0; }
.hp-pop-form > label, .hp-pop-form .hp-lib-pal { font-size: 12px; }
.hp-pop-form .hp-full { grid-column: 1 / -1; }
.hp-pop-form textarea { font: 12px "Segoe UI", system-ui, sans-serif; color: #fff; background: var(--hp-field); border: 1px solid var(--hp-line);
    border-radius: 4px; padding: 5px 7px; resize: vertical; width: 100%; box-sizing: border-box; }
.hp-pop-form > label.hp-check { flex-direction: row; align-items: center; gap: 7px; font-weight: 400; height: auto; white-space: normal; }
.hp-pop-form > label.hp-check input { width: auto; margin: 0; }
/* Engineering (light) theme */
.pg-home-slots[data-theme="C"] .hp-ut-list { background: #fff; }
.pg-home-slots[data-theme="C"] .hp-ut-item:hover { background: #f3f4f6; }
.pg-home-slots[data-theme="C"] .hp-ut-item.on { background: #eef0f3; }
.pg-home-slots[data-theme="C"] .hp-ut-save.dirty { background: #f9fafb; }
.pg-home-slots[data-theme="C"] .hp-pop, .pg-home-slots[data-theme="C"] .hp-pop-form textarea { background: #fff; color: #1f2937; }
.pg-home-slots[data-theme="C"] .hp-lib .hp-ut-tab .hp-c { color: #1f2937; }

/* ================================================================
   v0.34: rule drawing editor (RuleEditor.razor + ruleedit.js) - icons left, drawing, symbol library right
   ================================================================ */
.hp-ut-pbar { display: flex; align-items: center; gap: 8px; margin-top: 5px; }
.hp-ut-preview { cursor: zoom-in; }
.hp-redit-back { z-index: 6; }
.hp-redit { position: relative; width: 94vw; height: calc(100% - 40px); max-height: 92vh; box-sizing: border-box; display: flex; flex-direction: column; gap: 6px;
    padding: 10px 12px 8px; background: var(--hp-box); border: 1.5px solid var(--hp-acc); border-radius: 10px; box-shadow: 0 18px 50px rgba(0, 0, 0, .5); }
.hp-redit .hp-zoom-head { padding-bottom: 2px; }
.hp-redit-dirty { font-size: 12px; font-weight: 600; color: var(--hp-acc); }
.hp-redit-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 46px minmax(0, 1fr) 250px; gap: 8px; }
/* icon bar */
.hp-redit-tools { display: flex; flex-direction: column; gap: 5px; align-items: center; padding: 6px 0; border: 1px solid var(--hp-line); border-radius: 8px; }
.hp-ic { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; padding: 0; border-radius: 7px; cursor: pointer;
    color: inherit; background: rgba(255, 255, 255, .06); border: 1px solid transparent; }
.hp-ic:hover:not(:disabled) { border-color: var(--hp-acc); }
.hp-ic.on { background: var(--hp-acc); color: var(--hp-ink); }
.hp-ic.danger:hover:not(:disabled) { background: #c0392b; border-color: #e74c3c; color: #fff; }
.hp-ic:disabled { opacity: .3; cursor: not-allowed; }
.hp-ic-sep { width: 26px; height: 1px; background: var(--hp-line); margin: 3px 0; }
/* drawing */
.hp-redit-canvas { position: relative; min-width: 0; min-height: 0; background: #fff; border-radius: 8px; overflow: hidden; border: 1px solid var(--hp-line); cursor: default; }
.hp-redit-canvas.panning { cursor: grabbing; }
.hp-redit-canvas.drop-ok { box-shadow: inset 0 0 0 2px var(--hp-acc); }
.hp-redit[data-tool="pipe"] .hp-redit-canvas { cursor: crosshair; }
.hp-redit.busy .hp-redit-canvas { cursor: progress; }
.re-svg { width: 100%; height: 100%; display: block; user-select: none; }
.re-item rect { fill: transparent; stroke: transparent; stroke-width: .5; }
.re-item.can-drag { cursor: move; }
.re-item.locked { cursor: not-allowed; }
.re-item:hover rect { stroke: #2563eb; stroke-dasharray: 1.2 .8; fill: rgba(37, 99, 235, .05); }
.re-item.locked:hover rect { stroke: #9ca3af; }
.re-item.on rect { stroke: #2563eb; stroke-width: .7; stroke-dasharray: none; fill: rgba(37, 99, 235, .08); }
.re-item.locked.on rect { stroke: #f59e0b; fill: rgba(245, 158, 11, .08); }
.re-line .re-hit { fill: none; stroke: transparent; stroke-width: 3; cursor: pointer; }
.re-line .re-mark { fill: none; stroke: transparent; stroke-width: .9; pointer-events: none; }
.re-line:hover .re-mark { stroke: rgba(37, 99, 235, .55); }
.re-line.on .re-mark { stroke: #2563eb; }
.re-line.drop .re-mark { stroke: #16a34a; stroke-width: 1.4; }
.re-group rect { fill: none; stroke: #9333ea; stroke-width: .4; stroke-dasharray: 2 1.2; }
.re-group text { font: 600 3px "Segoe UI", system-ui, sans-serif; fill: #9333ea; }
.re-port { fill: #16a34a; stroke: #fff; stroke-width: .35; cursor: pointer; }
.re-port:hover { r: 2.4; fill: #22c55e; }
.re-rubber { stroke: #16a34a; stroke-width: .6; stroke-dasharray: 1.5 1; }
.re-mask { fill: rgba(255, 255, 255, .7); }
.re-drag { fill: rgba(37, 99, 235, .1); stroke: #2563eb; stroke-width: .6; stroke-dasharray: 1.5 1; }
.re-drag-t { font: 600 2.8px "Segoe UI", system-ui, sans-serif; fill: #2563eb; }
/* symbol library */
.hp-redit-lib { display: flex; flex-direction: column; gap: 5px; min-height: 0; border: 1px solid var(--hp-line); border-radius: 8px; padding: 6px; }
.hp-redit-libhead { font-weight: 700; font-size: 12.5px; }
.hp-redit-lib input, .hp-redit-lib select { width: 100% !important; }
.hp-redit-syms { flex: 1; min-height: 0; overflow: auto; display: grid; grid-template-columns: repeat(3, 1fr); gap: 5px; align-content: start; }
.hp-redit-sym { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 3px; border-radius: 5px; border: 1px solid var(--hp-line);
    cursor: grab; user-select: none; }
.hp-redit-sym:hover { border-color: var(--hp-acc); }
.hp-redit-sym.ro { cursor: default; }
.hp-redit-pic { width: 100%; height: 42px; background: #fff; border-radius: 3px; display: flex; pointer-events: none; }
.hp-redit-pic svg { width: 100%; height: 100%; }
.hp-redit-symname { font-size: 9px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; pointer-events: none; }
.re-libghost { position: fixed; z-index: 1000; width: 56px; pointer-events: none; opacity: .85; background: #fff; color: #111; border: 1.5px solid #2563eb;
    border-radius: 6px; box-shadow: 0 6px 18px rgba(0, 0, 0, .3); }
/* bottom line */
.hp-redit-foot { display: flex; align-items: center; gap: 12px; min-height: 22px; font-size: 12px; flex-wrap: wrap; }
.hp-redit-lock { color: #f59e0b; font-weight: 600; }
.re-status { margin-left: auto; font-size: 11.5px; opacity: .85; }
.re-status.err { color: #ff8a80; opacity: 1; font-weight: 600; }
/* Engineering (light) theme */
.pg-home-slots[data-theme="C"] .hp-redit { background: #fff; }
.pg-home-slots[data-theme="C"] .hp-ic { background: #f3f4f6; }
.pg-home-slots[data-theme="C"] .hp-ic.on { background: #111827; color: #fff; }
.pg-home-slots[data-theme="C"] .hp-redit-lock { color: #b45309; }
.pg-home-slots[data-theme="C"] .re-status.err { color: #b91c1c; }

/* v0.35: admin editing the PidGen default */
.hp-lib-note.hp-lib-admin { border-color: #f59e0b; background: rgba(245, 158, 11, .14); }
.pg-home-slots[data-theme="C"] .hp-lib-note.hp-lib-admin { background: #fffbeb; }

/* ================================================================
   v0.36: block scheme editor (.editor) and P&ID page (.pidview) in the home screen's theme.
   <html data-ui-theme="A|B|C"> is set by pidgen.js / home.js. Blueprint (A) and Hologram (B) = dark panels;
   Engineering (C) = the white look with the home screen's black accents. The drawing areas (.canvas, .sheet-view)
   keep their own Light / Blueprint look: the colour variables are reset there.
   ================================================================ */
html[data-ui-theme="A"] :is(.editor, .pidview) {
    --bg: #0a1f3d; --panel: #0f2a4f; --line: rgba(160, 210, 255, .18); --line-strong: rgba(160, 210, 255, .34);
    --text: #e6f1ff; --muted: #9bb8d8; --accent: #8fd0ff; --accent-weak: rgba(143, 208, 255, .16);
    --danger: #ff8a80; --warn: #ffcf70; --ok: #7ee2a8;
    --ink: #062040; --field: #0a2242; --btn: rgba(255, 255, 255, .06); --btn-hover: rgba(255, 255, 255, .13); --thead: #12325c;
}
html[data-ui-theme="B"] :is(.editor, .pidview) {
    --bg: #04191f; --panel: #062a33; --line: rgba(160, 255, 240, .16); --line-strong: rgba(160, 255, 240, .32);
    --text: #e8fffb; --muted: #8fc9bf; --accent: #b6ff6a; --accent-weak: rgba(182, 255, 106, .14);
    --danger: #ff8a80; --warn: #ffd27a; --ok: #9cf5b8;
    --ink: #04222b; --field: #03202a; --btn: rgba(255, 255, 255, .06); --btn-hover: rgba(255, 255, 255, .12); --thead: #08343f;
}
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) { background: var(--bg); color: var(--text); color-scheme: dark; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn { background: var(--btn); color: var(--text); border-color: var(--line-strong); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn:hover { background: var(--btn-hover); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn.primary { background: var(--accent); border-color: var(--accent); color: var(--ink); font-weight: 600; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn.primary:hover { filter: brightness(1.12); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn.ghost { background: transparent; border-color: transparent; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn.ghost:hover { background: var(--btn-hover); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .btn.danger { color: var(--danger); border-color: rgba(255, 138, 128, .45); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) :is(input, select, textarea) { background: var(--field); color: var(--text); border-color: var(--line-strong); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) :is(input, select, textarea):focus { outline-color: var(--accent-weak); border-color: var(--accent); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) select option { background: #fff; color: #111827; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) input::placeholder { color: var(--muted); opacity: .8; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) input.cell { background: transparent; border-color: transparent; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) input.cell:hover { background: var(--field); border-color: var(--line-strong); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) select.auto-value { color: var(--muted); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) label { color: var(--text); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) :is(code, kbd, .tag-pill) { background: var(--btn-hover); color: inherit; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .palette-item { background: var(--btn); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) :is(.calc-box, .column-chooser) { background: var(--btn); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) table.grid th,
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) table.grid tfoot tr.totals td { background: var(--thead); color: var(--text); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .data-table-edit th { color: var(--muted); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .check-panel { background: rgba(245, 158, 11, .12); border-bottom-color: rgba(245, 158, 11, .4); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .check-panel .close { color: var(--text); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .msgbar { background: rgba(34, 197, 94, .1); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .msgbar.warning { background: rgba(245, 158, 11, .13); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .msgbar.error { background: rgba(239, 68, 68, .15); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .selection-bar { background: var(--accent-weak); border-color: var(--line-strong); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .selection-bar.empty { background: transparent; border-color: transparent; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .selection-bar .help { background: var(--accent-weak); color: var(--accent); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .lock-banner { background: rgba(245, 158, 11, .16); color: #ffe2a8; border-bottom-color: rgba(245, 158, 11, .45); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .lock-banner.lost { background: rgba(239, 68, 68, .18); color: #ffd0cb; border-color: rgba(239, 68, 68, .5); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .edit-pill { background: rgba(245, 158, 11, .2); color: #ffe2a8; }
/* the top bar on these two pages */
html[data-ui-theme="A"] .app:has(.editor, .pidview) .topbar { background: #071a33; border-bottom: 1px solid rgba(160, 210, 255, .22); }
html[data-ui-theme="B"] .app:has(.editor, .pidview) .topbar { background: #031419; border-bottom: 1px solid rgba(160, 255, 240, .2); }
html[data-ui-theme="A"] .app:has(.editor, .pidview) .topbar nav a.active, html[data-ui-theme="A"] .app:has(.editor, .pidview) .topbar nav a:hover { background: rgba(143, 208, 255, .16); }
html[data-ui-theme="B"] .app:has(.editor, .pidview) .topbar nav a.active, html[data-ui-theme="B"] .app:has(.editor, .pidview) .topbar nav a:hover { background: rgba(182, 255, 106, .14); }
html[data-ui-theme="A"] .app:has(.editor, .pidview) .topbar .brand svg { color: #8fd0ff; }
html[data-ui-theme="B"] .app:has(.editor, .pidview) .topbar .brand svg { color: #b6ff6a; }
/* Engineering (C): the white look with the home screen's black accents */
html[data-ui-theme="C"] :is(.editor, .pidview) { --accent: #111827; --accent-weak: #eef0f3; }
html[data-ui-theme="C"] :is(.editor, .pidview) .btn.primary:hover { background: #1f2937; border-color: #1f2937; }
html[data-ui-theme="C"] :is(.editor, .pidview) a.crumb:hover { color: #111827; }
html[data-ui-theme="C"] :is(.editor, .pidview) .selection-bar { background: #f3f4f6; border-color: #d1d5db; }
html[data-ui-theme="C"] :is(.editor, .pidview) .selection-bar.empty { background: transparent; border-color: transparent; }
html[data-ui-theme="C"] :is(.editor, .pidview) .selection-bar .help { background: #e5e7eb; color: #111827; }
/* the drawing areas keep their own look (Light / Blueprint): original colours inside them */
html[data-ui-theme] :is(.editor, .pidview) :is(.canvas, .sheet-view) {
    --bg: #f6f7f9; --panel: #ffffff; --line: #e3e6ea; --line-strong: #cfd4da; --text: #1f2937; --muted: #6b7280;
    --accent: #2563eb; --accent-weak: #e8efff; --danger: #b91c1c; --warn: #b45309; --ok: #15803d;
    color: var(--text); color-scheme: light;
}
html[data-ui-theme] :is(.editor, .pidview) .sheet-view { border-color: var(--line-strong); }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .canvas :is(input, select, textarea) { background: #fff; color: #1f2937; border-color: #cfd4da; }
html:is([data-ui-theme="A"], [data-ui-theme="B"]) :is(.editor, .pidview) .canvas label { color: #374151; }

/* v0.37: P&ID view - properties of the block (block scheme unit) of the selected equipment, panel at the right edge */
.pid-props { min-height: 0; }
.pid-props-head { display: flex; align-items: center; gap: 6px; margin: -2px 0 8px; }
.pid-props-head .grow { flex: 1; }
.pid-props-status { background: var(--accent-weak, #eef2ff); border-radius: 4px; padding: 4px 6px; margin: 0 0 8px; }

/* ================================================================
   v0.42: accounts, guests, workspaces, admin
   ================================================================ */
.pg-home .locked { opacity: .35; cursor: not-allowed; }
.pg-home .locked * { cursor: not-allowed; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.topbar .guest-pill { padding: 2px 9px; border-radius: 9px; background: #374151; color: #fde68a; font-weight: 600; }
.topbar .ws-name { color: #cbd5e1; }
.topbar .ws-select { width: auto; max-width: 220px; height: 26px; padding: 0 6px; background: #1f2937; color: #e5e7eb; border-color: #374151; font-size: 12px; }
.user-menu { position: fixed; top: 50px; right: 16px; z-index: 50; display: flex; flex-direction: column; gap: 8px; min-width: 220px; box-shadow: 0 8px 24px rgba(0,0,0,.18); }
.user-menu form { margin: 0; }
.user-menu .btn { justify-content: flex-start; }
.guest-bar { display: flex; align-items: center; gap: 10px; padding: 5px 16px; background: #fffbeb; color: #78350f; border-bottom: 1px solid #fde68a; font-size: 12.5px; flex: 0 0 auto; }
.guest-bar span { flex: 1 1 auto; }
.lock-banner.sample { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.hp-pill.sample, .edit-pill.sample { background: #dbeafe; color: #1e40af; }
.error-text { color: var(--danger); }
.acct-page { display: flex; justify-content: center; align-items: flex-start; padding: 56px 16px; }
.acct-card { width: 420px; max-width: 100%; }
.acct-card h1 { margin: 0 0 12px; font-size: 20px; }
.acct-form label { display: block; margin: 0 0 12px; font-size: 13px; }
.acct-form label input { margin-top: 4px; }
.acct-form label.check { display: flex; align-items: center; gap: 8px; }
.acct-form label.check input { width: auto; margin: 0; }
.acct-form .validation-message { color: var(--danger); font-size: 12px; margin: -8px 0 10px; }
.acct-msg { padding: 8px 10px; border-radius: var(--radius); margin-bottom: 12px; font-size: 13px; }
.acct-msg.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }
.acct-msg.ok { background: #f0fdf4; color: #166534; border: 1px solid #bbf7d0; }
.admin h2 { margin-top: 0; }
.admin h3 { margin: 18px 0 8px; font-size: 14px; }
.admin table.grid td { vertical-align: top; }
.admin table.grid select, .admin table.grid input { width: auto; }
.admin-msg { display: flex; align-items: center; gap: 10px; color: #166534; }
.admin-msg.error { color: #991b1b; }
.admin-link input { font-family: ui-monospace, monospace; font-size: 12px; min-width: 520px; }
.member-pill { display: inline-flex; align-items: center; gap: 4px; margin: 0 6px 4px 0; padding: 1px 8px; border-radius: 9px; background: #f3f4f6; font-size: 12px; }

body.home-mode .guest-bar { position: relative; z-index: 10; }
