/* ==========================================================================
   ShortCircuit - stylesheet v3 (dark + light themes)
   One definition per component (the old file stacked several override
   layers on top of each other). Device / terminal-block geometry is now
   calculated in JavaScript, so this file only handles appearance.
   Every color comes from the theme variables below, so dark and light
   themes stay complete: add new colors as variables in BOTH themes.
   ========================================================================== */

:root
{
    --app-background: #10161f;
    --canvas-background: #121b26;
    --grid-line: rgba(52, 70, 87, 0.22);

    --panel-background: #18222e;
    --panel-raised: #22303d;
    --panel-hover: #293949;
    --panel-sunken: #0c151f;

    --border-color: #344657;
    --border-soft: #263746;

    --text-primary: #e8eef4;
    --text-secondary: #9baabd;
    --text-muted: #7d8da2;

    --accent: #24c8ff;
    --accent-dark: #1685aa;
    --accent-soft: rgba(36, 200, 255, 0.16);

    --success: #46c78b;
    --warning: #f4ae3d;
    --danger: #f06464;

    --sidebar-background: #111a26;
    --icon-tile-background: #0e1c29;
    --icon-tile-border: #2d465d;
    --note-background: #0d1722;
    --toggle-track: #344457;
    --toggle-knob: #a8b6c6;
    --block-background: rgba(13, 22, 33, .98);
    --terminal-background: #18293a;
    --terminal-border: #a9bed1;
    --wire-casing: rgba(205, 220, 235, .28);
    --device-shadow: 0 4px 14px rgba(0, 0, 0, .28);
    --menu-shadow: 0 8px 24px rgba(0, 0, 0, .42);
    --overlay: rgba(4, 9, 15, .62);
    --on-accent: #07121a;
    --type-power: #ff7a7a; --type-ground: #b0b8c2; --type-input: #7ad0ff; --type-output: #8ce99a; --type-relay: #ffd36e;
    color-scheme: dark;

    --command-bar-height: 44px;
    --status-bar-height: 26px;
    --tool-rail-width: 64px;
    --tool-panel-width: 270px;
    --properties-width: 300px;

    --workspace-zoom: 1;
    --zoomed-grid-size: 20px;
}

:root[data-theme="light"]
{
    --app-background: #e9eef3;
    --canvas-background: #f7f9fb;
    --grid-line: rgba(60, 84, 108, .12);

    --panel-background: #ffffff;
    --panel-raised: #edf1f5;
    --panel-hover: #e2e9f0;
    --panel-sunken: #f3f6f9;

    --border-color: #c3cfda;
    --border-soft: #dbe3ea;

    --text-primary: #15202b;
    --text-secondary: #44566a;
    --text-muted: #607285;

    --accent: #0a84b8;
    --accent-dark: #086a94;
    --accent-soft: rgba(10, 132, 184, .13);

    --success: #1f9d63;
    --warning: #b7740c;
    --danger: #cf3b3b;

    --sidebar-background: #f4f7fa;
    --icon-tile-background: #e6f3fa;
    --icon-tile-border: #b5d7e8;
    --note-background: #eef3f7;
    --toggle-track: #c2ccd6;
    --toggle-knob: #ffffff;
    --block-background: #f1f5f8;
    --terminal-background: #ffffff;
    --terminal-border: #5f7489;
    --wire-casing: rgba(20, 32, 44, .32);
    --device-shadow: 0 3px 10px rgba(20, 40, 60, .12);
    --menu-shadow: 0 8px 24px rgba(20, 40, 60, .18);
    --overlay: rgba(20, 32, 44, .35);
    --on-accent: #ffffff;
    --type-power: #c62828; --type-ground: #4a5562; --type-input: #0b6fa4; --type-output: #1e7d32; --type-relay: #9a6a00;
    color-scheme: light;
}

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

html, body
{
    width: 100%;
    height: 100%;
    margin: 0;
    overflow: hidden;
    background: var(--app-background);
    color: var(--text-primary);
    font-family: "Segoe UI", Arial, sans-serif;
}

button, input, textarea, select { font: inherit; }
button:focus-visible, [tabindex]:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- App frame ---------- */
#appShell { width: 100%; height: 100%; display: flex; flex-direction: column; }
#appBody { flex: 1; min-width: 0; min-height: 0; display: flex; overflow: hidden; }

/* ---------- Command bar ---------- */
#commandBar
{
    position: relative;
    z-index: 100;
    height: var(--command-bar-height);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 10px;
    background: var(--panel-background);
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .22);
}

.command-bar-brand { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 0 1 auto; overflow: hidden; }

.app-logo { width: 28px; height: 28px; flex-shrink: 0; }
.app-logo-bg { fill: var(--accent); }
.app-logo-mark { fill: var(--on-accent); }
.app-logo-trace { stroke: var(--on-accent); stroke-width: 2; stroke-linecap: round; fill: none; }
.application-name-accent { color: var(--accent); }

.project-location
{
    display: flex; align-items: center; gap: 7px; min-width: 0;
    color: var(--text-secondary); font-size: 12px; white-space: nowrap; overflow: hidden;
}
.project-location > span { overflow: hidden; text-overflow: ellipsis; }
.application-name { color: var(--text-primary); font-weight: 700; font-size: 14px; letter-spacing: .01em; flex-shrink: 0; }
.breadcrumb-separator { color: var(--text-muted); flex-shrink: 0; }
#breadcrumbProject { color: var(--text-primary); max-width: 260px; }
#dirtyIndicator { color: var(--warning); font-size: 18px; line-height: 1; flex-shrink: 0; }
#dirtyIndicator[hidden] { display: none; }

.command-group, .zoom-controls { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.command-divider { width: 1px; height: 24px; margin: 0 4px; background: var(--border-color); flex-shrink: 0; }
.command-bar-spacer { flex: 1; min-width: 8px; }

.command-button, .icon-button, .zoom-display
{
    min-height: 30px;
    border: 1px solid transparent; border-radius: 4px;
    background: transparent; color: var(--text-secondary);
    cursor: pointer;
}
.command-button { display: flex; align-items: center; gap: 6px; padding: 0 9px; white-space: nowrap; }
.command-button:hover:not(:disabled), .icon-button:hover, .zoom-display:hover
{
    background: var(--panel-hover); color: var(--text-primary); border-color: var(--border-color);
}
.command-button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-dark); }
.command-icon { font-size: 14px; }
.command-label { font-size: 12px; }
.icon-button { width: 30px; }
.zoom-display { width: 52px; font-size: 12px; }

/* ---------- Tool rail ---------- */
#toolRail
{
    width: var(--tool-rail-width); flex-shrink: 0;
    display: flex; flex-direction: column; gap: 4px;
    padding: 8px 5px;
    background: var(--panel-background);
    border-right: 1px solid var(--border-color);
    z-index: 80;
}
.rail-button
{
    min-height: 52px;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
    border: 1px solid transparent; border-radius: 5px;
    background: transparent; color: var(--text-secondary); cursor: pointer;
}
.rail-button:hover { background: var(--panel-hover); color: var(--text-primary); }
.rail-button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-dark); }
.rail-icon { font-size: 17px; }
.rail-label { font-size: 10px; }
.rail-spacer { flex: 1; }

/* ---------- Tool panel ---------- */
#toolbar
{
    width: var(--tool-panel-width); flex: 0 0 var(--tool-panel-width);
    overflow-x: hidden; overflow-y: auto;
    background: var(--sidebar-background);
    border-right: 1px solid var(--border-color);
    scrollbar-color: var(--border-color) transparent; scrollbar-width: thin;
}
#toolbar { position: relative; }

.tool-panel-content { display: none; padding: 16px 14px 24px; }
.tool-panel-content.active { display: block; }
.tool-panel-header { margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border-soft); }
.tool-panel-header h2 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.2; }
.tool-panel-header p { margin: 5px 0 0; color: var(--text-muted); font-size: 11px; line-height: 1.4; }

.tool-section { margin-bottom: 18px; }
.tool-section[hidden] { display: none; }
.tool-section-title
{
    margin-bottom: 8px; color: var(--text-muted);
    font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}

.tool-panel-search { margin-bottom: 18px; }
.tool-panel-search input, .tool-field input, .tool-field textarea
{
    width: 100%; height: 34px; padding: 0 10px;
    background: var(--panel-sunken); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 4px;
    font-size: 12px; outline: none;
}
.tool-field textarea { height: 64px; padding: 8px 10px; resize: vertical; }
.tool-field { display: block; margin-bottom: 10px; }
.tool-field > span { display: block; margin-bottom: 4px; color: var(--text-secondary); font-size: 11px; }
.tool-panel-search input:focus, .tool-field input:focus, .tool-field textarea:focus
{
    border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft);
}

.tool-button-stack { display: flex; flex-direction: column; gap: 7px; }
.tool-action-button
{
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 46px; padding: 8px 10px;
    background: var(--panel-background); color: var(--text-secondary);
    border: 1px solid var(--border-soft); border-radius: 5px;
    text-align: left; cursor: pointer;
    transition: background-color 100ms ease, border-color 100ms ease, color 100ms ease;
}
.tool-action-button:hover:not(:disabled) { background: var(--panel-hover); color: var(--text-primary); border-color: var(--border-color); }
.tool-action-button:active:not(:disabled) { transform: translateY(1px); }
.tool-action-icon
{
    width: 26px; min-width: 26px; height: 26px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--icon-tile-background); color: var(--accent);
    border: 1px solid var(--icon-tile-border); border-radius: 4px; font-size: 13px; font-weight: 600;
}
.tool-action-text { display: flex; flex-direction: column; flex: 1; gap: 2px; min-width: 0; }
.tool-action-text strong, .tool-action-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tool-action-text strong { font-size: 12px; font-weight: 600; }
.tool-action-text small { color: var(--text-muted); font-size: 10px; }
.tool-danger-button:hover:not(:disabled) { background: rgba(240,100,100,.12); color: var(--danger); border-color: rgba(240,100,100,.55); }
.tool-danger-button:hover:not(:disabled) .tool-action-icon { color: var(--danger); border-color: rgba(240,100,100,.45); }

.tool-segmented-control
{
    display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3px; padding: 3px;
    background: var(--panel-sunken); border: 1px solid var(--border-soft); border-radius: 5px;
}
.tool-mode-button
{
    height: 30px; padding: 0 8px;
    background: transparent; color: var(--text-muted);
    border: 1px solid transparent; border-radius: 3px; font-size: 11px; cursor: pointer;
}
.tool-mode-button:hover { background: var(--panel-background); color: var(--text-primary); }
.tool-mode-button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-dark); }

.tool-toggle-button
{
    width: 100%; min-height: 40px; margin-bottom: 6px;
    display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 10px;
    background: var(--panel-background); color: var(--text-secondary);
    border: 1px solid var(--border-soft); border-radius: 5px; font-size: 12px; text-align: left; cursor: pointer;
}
.tool-toggle-button:hover { background: var(--panel-hover); color: var(--text-primary); border-color: var(--border-color); }
.toggle-indicator { position: relative; width: 30px; min-width: 30px; height: 16px; background: var(--toggle-track); border-radius: 999px; transition: background-color 120ms ease; }
.toggle-indicator::after
{
    content: ""; position: absolute; top: 3px; left: 3px; width: 10px; height: 10px;
    background: var(--toggle-knob); border-radius: 50%; transition: left 120ms ease; box-shadow: 0 1px 2px rgba(0,0,0,.25);
}
.tool-toggle-button.active .toggle-indicator { background: var(--accent-dark); }
.tool-toggle-button.active .toggle-indicator::after { left: 17px; background: #ffffff; }

/* Notes and empty-state boxes keep the same 8 px from whatever sits above or below them, in every
   column (a flex stack already spaces its children with gap, so no extra margin there). */
.tool-panel-note, .tool-panel-empty
{
    margin: 8px 0;
    padding: 10px; background: var(--note-background); color: var(--text-muted);
    border: 1px solid var(--border-soft); border-radius: 4px; font-size: 11px; line-height: 1.5;
}
.tool-panel-note:first-child, .tool-panel-empty:first-child { margin-top: 0; }
.tool-panel-note:last-child, .tool-panel-empty:last-child { margin-bottom: 0; }
.tool-button-stack > .tool-panel-note, .tool-button-stack > .tool-panel-empty { margin: 0; }
.tool-panel-note kbd
{
    padding: 0 4px; border: 1px solid var(--border-color); border-radius: 3px;
    background: var(--panel-raised); color: var(--text-secondary); font-family: inherit; font-size: 10px;
}
.tool-panel-empty { text-align: center; }
.tool-panel-empty[hidden], .device-library-item[hidden] { display: none; }

.check-list { display: grid; gap: 6px; margin: 0; padding: 0; list-style: none; }
.check-list li
{
    padding: 7px 9px; border-radius: 4px; font-size: 11px; line-height: 1.4;
    background: var(--panel-background); border: 1px solid var(--border-soft); border-left-width: 3px;
    cursor: pointer;
}
.check-list li:hover { background: var(--panel-hover); }
.check-list li.check-error { border-left-color: var(--danger); }
.check-list li.check-warning { border-left-color: var(--warning); }
.check-list li.check-ok { border-left-color: var(--success); cursor: default; }

/* ---------- Workspace / canvas ---------- */
#workspace
{
    position: relative;
    flex: 1; min-width: 0; min-height: 0;
    display: flex; flex-direction: column;
    background: var(--canvas-background);
}
#viewport
{
    position: relative;
    flex: 1; min-height: 0;
    overflow: auto;
    background-color: var(--canvas-background);
    background-image:
        linear-gradient(var(--grid-line) 1px, transparent 1px),
        linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
    background-size: var(--zoomed-grid-size) var(--zoomed-grid-size);
    background-attachment: local;
    scrollbar-color: var(--border-color) transparent;
    outline: none;
}
#viewport.panning { cursor: grabbing; }
#viewport.space-pan { cursor: grab; }
#viewport.wire-mode .device { cursor: crosshair; }
#canvasSizer { position: relative; }
#canvas
{
    position: absolute; left: 0; top: 0;
    transform: scale(var(--workspace-zoom));
    transform-origin: 0 0;
}
#wireLayer
{
    position: absolute; left: 0; top: 0;
    overflow: visible;
    pointer-events: none;
    z-index: 10;
}
#emptyCanvasHint
{
    position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%);
    max-width: 360px; padding: 18px 22px; text-align: center;
    color: var(--text-muted); font-size: 13px; line-height: 1.6;
    border: 1px dashed var(--border-color); border-radius: 8px;
    pointer-events: none;
}
#emptyCanvasHint[hidden] { display: none; }
#emptyCanvasHint strong { display: block; margin-bottom: 4px; color: var(--text-secondary); font-size: 14px; }

/* ---------- Status bar ---------- */
#statusBar
{
    height: var(--status-bar-height); flex-shrink: 0;
    display: flex; align-items: center; gap: 16px; padding: 0 12px;
    background: var(--panel-background); border-top: 1px solid var(--border-color);
    color: var(--text-muted); font-size: 11px; white-space: nowrap; overflow: hidden;
}
#statusHint { flex: 1; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
#statusBar .status-warning { color: var(--warning); }

/* ---------- Devices ---------- */
.device
{
    position: absolute;
    background: var(--panel-background);
    color: var(--text-primary);
    border-radius: 6px;               /* outline drawn with box-shadow so children line up exactly with the device edge */
    box-shadow: 0 0 0 1px var(--border-color), var(--device-shadow);
    cursor: move;
    user-select: none;
    z-index: 20;
    transition: border-color 100ms ease, box-shadow 100ms ease;
}
.device.selected-component { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft), 0 6px 18px rgba(0,0,0,.34); z-index: 22; }
/* splice: a junction dot on a wire (drag the ring to move it; the dot is its terminal) */
.device.splice-device { background: transparent; border-radius: 50%; box-shadow: none; z-index: 24; }
.device.splice-device:hover { box-shadow: 0 0 0 2px var(--accent-soft); }
.device.splice-device.selected-component { box-shadow: 0 0 0 2px var(--accent), 0 0 0 5px var(--accent-soft); }
.splice-block { position: absolute; inset: 0; border: 0; background: none; box-shadow: none; padding: 0; }
.terminal.splice-terminal { box-sizing: border-box; left: 50%; top: 50%; width: 12px; height: 12px; margin: -6px 0 0 -6px; border-width: 2px; border-color: var(--canvas-background); }
.device.dragging { opacity: .92; z-index: 30; box-shadow: 0 0 0 1px var(--accent), 0 12px 28px rgba(0,0,0,.5); }
.device.device-overlap { box-shadow: 0 0 0 1px var(--warning), 0 0 0 4px rgba(244,174,61,.22); }

.device-title
{
    position: absolute; left: 0; right: 0;
    padding: 0 12px;
    font-size: 13px; font-weight: 600; line-height: 20px;
    text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: none;
}
.device-subtitle
{
    position: absolute; left: 0; right: 0;
    padding: 0 12px;
    color: var(--text-muted); font-size: 10px; line-height: 14px; text-align: center;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: none;
}
.device-rule { position: absolute; left: 12px; right: 12px; height: 1px; background: var(--border-color); pointer-events: none; }
.device[data-block-drop-side="left"]   { box-shadow: inset 4px 0 0 var(--accent); }
.device[data-block-drop-side="right"]  { box-shadow: inset -4px 0 0 var(--accent); }
.device[data-block-drop-side="top"]    { box-shadow: inset 0 4px 0 var(--accent); }
.device[data-block-drop-side="bottom"] { box-shadow: inset 0 -4px 0 var(--accent); }

/* ---------- Terminal blocks ---------- */
.terminal-block
{
    position: absolute;
    background: var(--block-background);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    cursor: grab;
    touch-action: none;
    z-index: 2;
}
.terminal-block:active { cursor: grabbing; }
.terminal-block.selected-component { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.terminal-block.dragging-terminal-block { opacity: .7; }
.block-title
{
    position: absolute;
    color: var(--text-secondary);
    font-size: 9px; line-height: 12px; letter-spacing: .02em;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: none;
}
.terminal-block-left .block-title,
.terminal-block-right .block-title { writing-mode: vertical-rl; text-align: center; }
.terminal-block-left .block-title { transform: rotate(180deg); }

/* ---------- Terminals ---------- */
.terminal
{
    position: absolute;
    width: 14px; height: 14px;
    margin: -7px 0 0 -7px;            /* positioned by its centre */
    border: 2px solid var(--terminal-border);
    border-radius: 50%;
    background: var(--terminal-background);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, .5);
    cursor: pointer;
    z-index: 3;
}
.terminal:hover { border-color: var(--accent); transform: scale(1.18); }
.terminal-connected
{
    background: var(--terminal-wire-fill, var(--terminal-wire-color));
    border-color: var(--terminal-wire-color, var(--terminal-border));
    box-shadow: 0 0 0 2px var(--canvas-background), 0 0 0 3px var(--wire-casing);
}
.terminal.selected-component { outline: 2px solid var(--accent); outline-offset: 3px; }
.terminal.wire-start-terminal { outline: 2px solid #ff6b6b; outline-offset: 3px; background: #ff3b3b; }
#viewport.wire-mode .terminal { cursor: crosshair; }

.terminal-label
{
    position: absolute;
    color: var(--text-secondary);
    font-size: 9px; line-height: 12px;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    pointer-events: none;
}
.terminal-block-top .terminal-label,
.terminal-block-bottom .terminal-label { text-align: center; }
.terminal-block-left .terminal-label { text-align: left; }
.terminal-block-right .terminal-label { text-align: right; }
.terminal-type-Power  { --type-color: var(--type-power); }
.terminal-type-Ground { --type-color: var(--type-ground); }
.terminal-type-Input  { --type-color: var(--type-input); }
.terminal-type-Output { --type-color: var(--type-output); }
.terminal-type-Relay  { --type-color: var(--type-relay); }
.terminal.drop-target { outline: 3px solid var(--accent); outline-offset: 3px; transform: scale(1.25); }
.terminal-label.typed { color: var(--type-color); }

/* ---------- Wires ---------- */
#wireLayer .wire-casing { fill: none; stroke: var(--wire-casing); stroke-width: 6; stroke-linejoin: round; }
#wireLayer .wire-path { fill: none; stroke-width: 3; stroke-linejoin: round; }
#wireLayer .wire-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer; }
#wireLayer .wire-selected .wire-casing { stroke: var(--accent); stroke-width: 8; opacity: .9; }
#wireLayer .wire-selected .wire-path { stroke-width: 3.5; }
#wireLayer .wire-hover .wire-casing { stroke: rgba(36, 200, 255, .55); }
#wireLayer .splice-target .wire-casing { stroke: var(--accent); stroke-width: 9; }     /* a terminal dragged onto this wire will splice into it */
#wireLayer .wire-warning .wire-casing { stroke: rgba(244, 174, 61, .7); stroke-dasharray: 6 4; }
#wireLayer .wire-label
{
    fill: var(--text-primary);
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 11px;
    paint-order: stroke;
    stroke: var(--canvas-background);
    stroke-width: 4px;
    stroke-linejoin: round;
    pointer-events: none;
}
#wireLayer .wire-label.selected { fill: var(--accent); }
#wireLayer .hop-marker { fill: none; pointer-events: none; stroke-linecap: round; stroke-linejoin: round; }
#wireLayer .wire-preview { fill: none; stroke: var(--danger); stroke-width: 2; stroke-dasharray: 6 4; }

/* ---------- Properties panel (docked, never covers the canvas) ---------- */
#propertiesPanel
{
    width: var(--properties-width); flex: 0 0 var(--properties-width);
    display: flex; flex-direction: column;
    background: var(--sidebar-background);
    border-left: 1px solid var(--border-color);
    overflow: hidden;
}

.properties-header
{
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 14px; border-bottom: 1px solid var(--border-soft);
}
.properties-header h3 { margin: 0; font-size: 14px; font-weight: 600; }
#propertiesContent { flex: 1; overflow-y: auto; padding: 14px; overscroll-behavior: contain; font-size: 12px; }
#propertiesContent h4 { margin: 0 0 12px; font-size: 13px; color: var(--text-primary); }
#propertiesContent .muted { color: var(--text-muted); line-height: 1.5; }
.prop-field { display: block; margin-bottom: 12px; }
.prop-field > span { display: block; margin-bottom: 5px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.prop-field input, .prop-field textarea, .prop-field select
{
    width: 100%; padding: 7px 9px;
    background: var(--panel-sunken); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 4px; font-size: 12px; outline: none;
}
.prop-field textarea { min-height: 60px; resize: vertical; }
.prop-field input:focus, .prop-field textarea:focus, .prop-field select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.prop-field .field-error { margin-top: 4px; color: var(--danger); font-size: 11px; }
.prop-field .field-hint { margin-top: 4px; color: var(--text-muted); font-size: 10px; line-height: 1.4; }
.prop-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.prop-row.single { grid-template-columns: 1fr; }
.prop-readonly { margin-bottom: 12px; padding: 7px 9px; border-radius: 4px; background: var(--panel-background); color: var(--text-secondary); font-size: 11px; line-height: 1.5; word-break: break-word; }

.property-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 4px; }
#propertiesPanel button.prop-button
{
    padding: 7px 12px; border-radius: 4px; cursor: pointer;
    background: var(--accent-dark); color: #fff; border: 1px solid var(--accent-dark); font-size: 12px;
}
#propertiesPanel button.prop-button:hover { background: var(--accent); color: var(--on-accent); }
#propertiesPanel button.secondary-action { background: var(--panel-raised); color: var(--text-primary); border-color: var(--border-color); }
#propertiesPanel button.secondary-action:hover { background: var(--panel-hover); color: var(--accent); border-color: var(--accent-dark); }
#propertiesPanel button.danger-action { background: transparent; color: var(--danger); border-color: rgba(240,100,100,.45); }
#propertiesPanel button.danger-action:hover { background: rgba(240,100,100,.14); color: var(--danger); }

#panelColorPalette { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.color-swatch
{
    height: 26px; border-radius: 4px; cursor: pointer;
    border: 1px solid var(--border-color);
    display: flex; align-items: center; justify-content: center;
}
.color-swatch.selected { outline: 2px solid var(--accent); outline-offset: 2px; }
.color-swatch span { font-size: 9px; font-weight: 700; color: #000; mix-blend-mode: normal; text-shadow: 0 0 2px #fff; }

.property-section-heading
{
    margin: 18px 0 8px; padding-top: 14px; border-top: 1px solid var(--border-soft);
    color: var(--text-secondary); font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
}
.device-terminal-tree { display: grid; gap: 7px; }
.device-tree-block { border: 1px solid var(--border-soft); border-radius: 5px; background: var(--panel-sunken); overflow: hidden; }
.device-tree-block > summary
{
    display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer;
    font-size: 12px; font-weight: 600; list-style-position: inside;
}
.device-tree-block > summary:hover { background: var(--panel-hover); }
.device-tree-block > summary span:first-of-type { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tree-count { min-width: 22px; padding: 2px 6px; border-radius: 999px; background: var(--panel-raised); color: var(--text-secondary); text-align: center; font-size: 10px; }
.device-tree-body { padding: 9px; border-top: 1px solid var(--border-soft); }
.tree-meta { color: var(--text-muted); font-size: 10px; text-transform: capitalize; }
.tree-actions { display: flex; gap: 6px; margin: 7px 0; }
#propertiesPanel button.compact-action { flex: 1; padding: 5px 7px; font-size: 10px; }
.terminal-tree-list { display: grid; gap: 4px; }
#propertiesPanel button.terminal-tree-item
{
    width: 100%; display: grid; grid-template-columns: 14px minmax(0,1fr) auto; align-items: center; gap: 7px;
    padding: 6px 7px; border-radius: 4px; cursor: pointer;
    background: var(--panel-background); color: var(--text-secondary); border: 1px solid var(--border-soft); text-align: left;
}
#propertiesPanel button.terminal-tree-item:hover { background: var(--panel-hover); color: var(--text-primary); }
.terminal-tree-dot { width: 11px; height: 11px; border: 1px solid var(--terminal-border); border-radius: 50%; background: var(--panel-raised); }
.terminal-tree-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.terminal-tree-item small { color: var(--text-muted); font-size: 9px; }
.tree-empty { padding: 8px; color: var(--text-muted); font-size: 10px; text-align: center; }
.tree-empty-panel { border: 1px dashed var(--border-color); border-radius: 5px; }
.connection-list { display: grid; gap: 4px; margin: 0 0 12px; padding: 0; list-style: none; }
.connection-list li { display: flex; align-items: center; gap: 7px; padding: 5px 7px; border-radius: 4px; background: var(--panel-background); font-size: 11px; color: var(--text-secondary); }
.connection-list .swatch-dot { width: 10px; height: 10px; border-radius: 50%; border: 1px solid var(--border-color); flex-shrink: 0; }

/* ---------- Context menus ---------- */
.context-menu
{
    display: none;
    position: fixed;
    min-width: 190px; max-width: calc(100vw - 16px); max-height: calc(100vh - 16px); overflow: auto;
    padding: 5px;
    background: var(--panel-background); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 6px;
    box-shadow: var(--menu-shadow);
    z-index: 1000;
    font-size: 12px;
}
.context-menu > div { padding: 8px 10px; border-radius: 4px; cursor: pointer; user-select: none; }
.context-menu > div:hover, .context-menu > div:focus-visible { background: var(--accent-soft); color: var(--accent); outline: none; }
.context-menu > div.menu-danger:hover { background: rgba(240,100,100,.14); color: var(--danger); }
.context-menu > hr { margin: 4px 2px; border: 0; border-top: 1px solid var(--border-soft); }
.context-menu .menu-sub { display: flex; gap: 4px; padding: 4px 6px 6px; }
.context-menu .menu-sub button
{
    flex: 1; padding: 4px 0; border-radius: 3px; cursor: pointer; font-size: 11px;
    background: var(--panel-raised); color: var(--text-secondary); border: 1px solid var(--border-soft);
}
.context-menu .menu-sub button:hover { color: var(--accent); border-color: var(--accent-dark); }
.context-menu .menu-sub-label { padding: 6px 10px 0; color: var(--text-muted); font-size: 10px; cursor: default; }
.context-menu .menu-sub-label:hover { background: none; color: var(--text-muted); }

/* ---------- Toasts & banners ---------- */
#toastHost
{
    position: fixed; right: 16px; bottom: calc(var(--status-bar-height) + 12px);
    display: flex; flex-direction: column; gap: 8px; z-index: 2000; pointer-events: none;
}
.toast
{
    max-width: 360px; padding: 10px 14px; border-radius: 6px;
    background: var(--panel-raised); color: var(--text-primary);
    border: 1px solid var(--border-color); border-left: 3px solid var(--accent);
    box-shadow: var(--menu-shadow); font-size: 12px; line-height: 1.45;
    animation: toast-in 160ms ease-out;
}
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }
.toast-warning { border-left-color: var(--warning); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

#recoveryBanner
{
    display: flex; align-items: center; gap: 12px; padding: 8px 14px;
    background: rgba(244,174,61,.12); border-bottom: 1px solid rgba(244,174,61,.4);
    color: var(--text-primary); font-size: 12px;
}
#recoveryBanner[hidden] { display: none; }
#recoveryBanner span { flex: 1; }
#recoveryBanner button
{
    padding: 4px 10px; border-radius: 4px; cursor: pointer; font-size: 12px;
    background: var(--panel-raised); color: var(--text-primary); border: 1px solid var(--border-color);
}
#recoveryBanner button.primary { background: var(--warning); color: #1b1305; border-color: var(--warning); }

/* ---------- Template library ---------- */
.template-item { position: relative; display: flex; align-items: stretch; gap: 4px; }
.template-item[hidden] { display: none; }
.template-item .device-library-item { flex: 1; min-width: 0; }
.template-menu-button
{
    width: 28px; flex-shrink: 0; border-radius: 5px; cursor: pointer; font-size: 16px; line-height: 1;
    background: var(--panel-background); color: var(--text-muted); border: 1px solid var(--border-soft);
}
.template-menu-button:hover { background: var(--panel-hover); color: var(--accent); border-color: var(--border-color); }
.tool-segmented-control.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }

/* ---------- Dialogs ---------- */
#modalHost { position: fixed; inset: 0; z-index: 3000; display: grid; place-items: center; background: var(--overlay); padding: 16px; }
#modalHost[hidden] { display: none; }
.modal
{
    width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto;
    padding: 18px 20px; border-radius: 8px;
    background: var(--panel-background); color: var(--text-primary);
    border: 1px solid var(--border-color); box-shadow: var(--menu-shadow);
    font-size: 13px; line-height: 1.5;
}
.modal h3 { margin: 0 0 12px; font-size: 16px; }
.modal p { margin: 0 0 10px; }
.modal .muted { color: var(--text-muted); font-size: 12px; }
.modal .prop-field { display: block; margin-bottom: 10px; }
.modal .prop-field > span { display: block; margin-bottom: 4px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.modal input, .modal textarea, .modal select
{
    width: 100%; padding: 7px 9px; border-radius: 4px; font-size: 13px; outline: none;
    background: var(--panel-sunken); color: var(--text-primary); border: 1px solid var(--border-color);
}
.modal textarea { min-height: 60px; resize: vertical; }
.modal input:focus, .modal textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.modal .field-error { margin: -6px 0 8px; color: var(--danger); font-size: 12px; }
.modal .field-hint { margin: -6px 0 8px; color: var(--warning); font-size: 12px; }
.modal-buttons { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 8px; margin-top: 16px; }
.modal-button
{
    padding: 7px 14px; border-radius: 4px; cursor: pointer; font-size: 13px;
    background: var(--panel-raised); color: var(--text-primary); border: 1px solid var(--border-color);
}
.modal-button:hover { background: var(--panel-hover); }
.modal-button.primary { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.modal-button.primary:hover { background: var(--accent); color: var(--on-accent); }
.modal-button.danger { color: var(--danger); border-color: rgba(240,100,100,.5); }
.import-warning-title { color: var(--warning); font-weight: 600; }
.import-warnings { max-height: 220px; overflow: auto; margin: 0 0 10px; padding: 8px 10px 8px 26px; border-radius: 4px; background: var(--panel-sunken); font-size: 12px; }

/* ---------- Field visibility (Settings) ---------- */
#appShell.hide-terminal-labels .terminal-label { display: none; }
#appShell.hide-block-titles .block-title { display: none; }
#appShell.hide-device-location .device-subtitle { display: none; }
#appShell.hide-terminal-types .terminal-label.typed { color: var(--text-secondary); }
#appShell.hide-grid #viewport { background-image: none; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Responsive ---------- */
@media (max-width: 1280px)
{
    :root { --tool-panel-width: 220px; --properties-width: 280px; }
    #breadcrumbProject { max-width: 160px; }
}
@media (max-width: 1100px)
{
    :root { --tool-panel-width: 200px; --properties-width: 240px; }
    .command-label { display: none; }
    .command-button { padding: 0 7px; }
    .application-name, .application-name + .breadcrumb-separator { display: none; }
}


/* ==========================================================================
   Phones and tablets (v5)
   JS sets #appShell.compact below 900 px wide or 500 px tall, plus
   .layout-bottom (portrait: tab bar at the bottom, panels slide up) or
   .layout-side (landscape: rail on the left, panels slide in from the sides).
   ========================================================================== */
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, .rail-button, .tool-action-button, .context-menu > div { touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
#viewport { touch-action: none; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; }

/* phone-only controls stay out of the desktop layout */
.rail-properties, .sheet-bar, #canvasControls, #selectionBar, #canvasHint { display: none; }
#canvasHint[hidden], #selectionBar[hidden] { display: none !important; }

@supports (height: 100dvh) { #appShell.compact { height: 100dvh; } }

#appShell.compact #commandBar
{
    height: calc(var(--command-bar-height) + env(safe-area-inset-top));
    padding: env(safe-area-inset-top) max(6px, env(safe-area-inset-right)) 0 max(6px, env(safe-area-inset-left));
    gap: 2px;
}
#appShell.compact .project-location,
#appShell.compact .zoom-controls,
#appShell.compact .zoom-controls + .command-divider,
#appShell.compact #themeToggleButton,
#appShell.compact .command-label { display: none; }
@media (max-width: 440px) { #appShell.compact #autoSortButton, #appShell.compact #aboutButton { display: none; } }   /* phones: Auto Sort is in the Wires panel */
#appShell.compact .command-bar-brand { flex: 0 0 auto; }
#appShell.compact .command-divider { margin: 0 2px; }
#appShell.compact .command-button { min-width: 40px; min-height: 40px; justify-content: center; padding: 0 6px; }
#appShell.compact .command-icon { font-size: 17px; }
#appShell.compact #statusBar { display: none; }

#appShell.compact #appBody { position: relative; }
#appShell.compact .rail-properties { display: flex; }

/* panels become sheets over the canvas */
#appShell.compact #toolbar,
#appShell.compact.tool-panel-collapsed #toolbar,
#appShell.compact #propertiesPanel,
#appShell.compact.properties-collapsed #propertiesPanel
{
    display: flex; flex-direction: column;
    position: absolute; z-index: 90;
    width: auto; flex: none;
    background: var(--sidebar-background);
    border: 1px solid var(--border-color);
    box-shadow: 0 -8px 28px rgba(0, 0, 0, .35);
    visibility: hidden;
    transition: transform .22s ease, visibility 0s linear .22s;
    overscroll-behavior: contain;
}
#appShell.compact #toolbar { overflow-y: auto; -webkit-overflow-scrolling: touch; }
#appShell.compact #toolbar .tool-panel-content { flex: none; }
#appShell.compact #propertiesContent { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
#appShell.compact[data-sheet="devices"] #toolbar,
#appShell.compact[data-sheet="wires"] #toolbar,
#appShell.compact[data-sheet="project"] #toolbar,
#appShell.compact[data-sheet="settings"] #toolbar,
#appShell.compact[data-sheet="logic"] #toolbar,
#appShell.compact[data-sheet="properties"] #propertiesPanel
{
    visibility: visible; transform: none;
    transition: transform .22s ease, visibility 0s;
}
#appShell.compact .sheet-bar
{
    display: flex; align-items: center; justify-content: center;
    position: sticky; top: 0; z-index: 2; flex: none;
    min-height: 40px; background: var(--sidebar-background);
}
#appShell.compact .sheet-grip { width: 40px; height: 4px; border-radius: 2px; background: var(--border-color); }
#appShell.compact .sheet-close { position: absolute; right: 8px; top: 4px; width: 36px; min-height: 32px; }
#appShell.compact .tool-panel-content { padding-top: 0; }
#appShell.compact .properties-header .icon-button { width: 40px; min-height: 36px; font-size: 16px; }

/* portrait: bottom tab bar, bottom sheets */
#appShell.layout-bottom #appBody { flex-direction: column; }
#appShell.layout-bottom #workspace { order: 1; }
#appShell.layout-bottom #toolRail
{
    order: 2; width: auto; flex-direction: row; gap: 2px;
    padding: 4px max(6px, env(safe-area-inset-right)) calc(4px + env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    border-right: 0; border-top: 1px solid var(--border-color);
}
#appShell.layout-bottom .rail-spacer { display: none; }
#appShell.layout-bottom .rail-button { flex: 1; min-height: 50px; gap: 2px; }
#appShell.layout-bottom #toolbar,
#appShell.layout-bottom #propertiesPanel
{
    left: 0; right: 0; bottom: calc(58px + env(safe-area-inset-bottom));
    height: min(64%, 620px);
    border-radius: 14px 14px 0 0; border-bottom: 0;
    transform: translateY(calc(100% + 70px));
}

/* landscape: rail stays on the left, panels slide in from the sides */
#appShell.layout-side #toolRail { padding-left: max(5px, env(safe-area-inset-left)); overflow-y: auto; }
#appShell.layout-side .rail-button { min-height: 44px; }
#appShell.layout-side #toolbar,
#appShell.layout-side #propertiesPanel { top: 0; bottom: 0; width: min(380px, 62vw); box-shadow: 0 0 28px rgba(0, 0, 0, .35); }
#appShell.layout-side #toolbar { left: calc(var(--tool-rail-width) + env(safe-area-inset-left)); border-radius: 0 12px 12px 0; transform: translateX(calc(-100% - var(--tool-rail-width) - 40px)); }
#appShell.layout-side #propertiesPanel { right: 0; border-radius: 12px 0 0 12px; padding-right: env(safe-area-inset-right); transform: translateX(calc(100% + 40px)); }
#appShell.layout-side .sheet-grip { display: none; }

/* floating canvas controls, hint and selection bar */
#appShell.compact #canvasControls
{
    display: flex; flex-direction: column; gap: 8px;
    position: absolute; z-index: 40; right: max(12px, env(safe-area-inset-right)); bottom: 72px;
}
.float-button
{
    width: 44px; height: 44px; border-radius: 22px;
    display: grid; place-items: center; font-size: 20px; line-height: 1;
    background: var(--panel-raised); color: var(--text-primary);
    border: 1px solid var(--border-color); box-shadow: 0 3px 10px rgba(0, 0, 0, .3); cursor: pointer;
}
.float-button.active { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
#appShell.compact #canvasHint
{
    display: block; position: absolute; z-index: 45; top: 10px; left: 50%; transform: translateX(-50%);
    width: max-content; max-width: calc(100% - 24px); padding: 8px 14px; border-radius: 18px;
    background: var(--panel-raised); color: var(--text-primary); border: 1px solid var(--accent-dark);
    box-shadow: 0 3px 12px rgba(0, 0, 0, .3); font-size: 13px; line-height: 1.35; text-align: center; pointer-events: none;
}
#appShell.compact #selectionBar
{
    display: flex; align-items: center; gap: 8px;
    position: absolute; z-index: 45; left: max(12px, env(safe-area-inset-left)); right: calc(max(12px, env(safe-area-inset-right)) + 56px); bottom: 12px;
    min-height: 52px; padding: 6px 6px 6px 14px; border-radius: 26px;
    background: var(--panel-raised); border: 1px solid var(--border-color); box-shadow: 0 4px 14px rgba(0, 0, 0, .35);
}
#selectionBarLabel { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; color: var(--text-primary); }
.selection-bar-button
{
    flex: none; min-width: 44px; height: 40px; padding: 0 14px; border-radius: 20px; cursor: pointer;
    background: var(--accent); color: var(--on-accent); border: 1px solid var(--accent); font-weight: 600;
}
.selection-bar-button.danger { padding: 0; background: transparent; color: var(--danger); border-color: rgba(240,100,100,.45); }
#appShell.compact #emptyCanvasHint { top: 38%; width: calc(100% - 48px); }
#appShell.compact ~ #toastHost, #appShell.compact + #toastHost { bottom: calc(80px + env(safe-area-inset-bottom)); left: 12px; right: 12px; align-items: center; }

/* touch screens: bigger targets, no iOS zoom on focus */
@media (pointer: coarse)
{
    #wireLayer .wire-hit { stroke-width: 22; }
    .context-menu > div { padding: 12px 14px; min-height: 44px; font-size: 15px; }
    .context-menu .menu-sub button { min-height: 40px; min-width: 52px; }
    input, textarea, select, .modal input, .modal textarea, .modal select,
    .tool-panel-search input, .tool-field input, .tool-field textarea { font-size: 16px !important; }
    .modal-button { min-height: 44px; padding: 10px 16px; font-size: 15px; }
    #propertiesPanel button.prop-button { min-height: 40px; }
    .tool-action-button { min-height: 52px; }
    .color-swatch { min-width: 30px; min-height: 30px; }
    .rail-button { min-height: 52px; }
    .tool-mode-button { min-height: 40px; }
    .template-menu-button { min-width: 40px; }
    #propertiesPanel button.compact-action { min-height: 38px; font-size: 12px; }
    #propertiesPanel button.terminal-tree-item { min-height: 40px; }
    .color-swatch { min-height: 36px; }
    #appShell.compact .sheet-close { width: 40px; min-height: 40px; top: 0; }
}
#appShell.compact ~ #modalHost .modal, #modalHost .modal { max-height: calc(100vh - 32px); }
@supports (height: 100dvh) { #modalHost .modal { max-height: calc(100dvh - 32px); } }

@media (prefers-reduced-motion: reduce)
{
    *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ---------- Print: just the drawing ---------- */
@media print
{
    html, body { overflow: visible; height: auto; background: #fff; }
    #commandBar, #toolRail, #toolbar, #propertiesPanel, #statusBar, .context-menu, #toastHost, #recoveryBanner, #emptyCanvasHint { display: none !important; }
    #appShell, #appBody, #workspace, #viewport { display: block; height: auto; overflow: visible; background: #fff; }
    #viewport { background-image: none; }
    .device, .terminal-block { box-shadow: none; }
}


/* ---------- Projects on the device (v3) ---------- */
.project-list { display: grid; gap: 6px; margin: 10px 0 0; padding: 0; list-style: none; }
.project-item { display: flex; align-items: stretch; gap: 4px; }
.project-open
{
    flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; padding: 7px 10px; text-align: left; cursor: pointer;
    background: var(--panel-background); color: var(--text-secondary); border: 1px solid var(--border-soft); border-radius: 5px;
}
.project-open:hover { background: var(--panel-hover); color: var(--text-primary); border-color: var(--border-color); }
.project-open strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); font-size: 12px; font-weight: 600; }
.project-open small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-muted); font-size: 10px; }
.project-item.current .project-open { border-color: var(--accent-dark); box-shadow: inset 3px 0 0 var(--accent); }
.project-item.damaged .project-open small { color: var(--danger); }
.project-badge { margin-left: 4px; padding: 0 5px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-size: 9px; font-weight: 700; text-transform: uppercase; vertical-align: 1px; }
.project-empty { padding: 9px 10px; border: 1px dashed var(--border-color); border-radius: 5px; color: var(--text-muted); font-size: 11px; line-height: 1.5; }

/* ---------- Multi-select (v3) ---------- */
#marquee
{
    position: absolute; z-index: 40; pointer-events: none;
    background: var(--accent-soft); border: 1px dashed var(--accent);
}
#marquee[hidden] { display: none; }
.align-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; margin-bottom: 10px; }
#propertiesPanel .align-grid button.prop-button { padding: 6px 4px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device.selected-component.device-overlap { box-shadow: 0 0 0 1px var(--accent), 0 0 0 4px var(--accent-soft), 0 0 0 6px rgba(244,174,61,.45); }

/* ==========================================================================
   v6: device editor, prebuilt blocks, quick colours, template drag, Load
   ========================================================================== */
.editor-toolbar { margin: -2px 0 12px; }
.editor-add-select
{
    width: 100%; padding: 7px 9px; border-radius: 4px; cursor: pointer;
    background: var(--panel-raised); color: var(--accent); border: 1px dashed var(--accent-dark); font-size: 12px; font-weight: 600;
}
.editor-add-select:hover, .editor-add-select:focus { border-style: solid; outline: none; }
.editor-section { margin-bottom: 10px; }
.editor-section > summary { display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; padding: 2px 0 8px; }
.editor-section > summary::-webkit-details-marker, .block-editor > summary::-webkit-details-marker, .block-group > summary::-webkit-details-marker { display: none; }
.editor-section > summary::before, .block-editor > summary::before, .block-group > summary::before
{
    content: "▸"; display: inline-block; width: 10px; color: var(--text-muted); font-size: 10px; transition: transform .12s;
}
.editor-section[open] > summary::before, .block-editor[open] > summary::before, .block-group[open] > summary::before { transform: rotate(90deg); }
.editor-section > summary h4, .editor-section > summary .property-section-heading { margin: 0 !important; }
.prop-check { display: flex; align-items: center; gap: 7px; margin: -2px 0 12px; color: var(--text-secondary); font-size: 12px; cursor: pointer; }
.prop-check small { color: var(--text-muted); font-size: 10px; }
.editor-add-row { display: grid; gap: 6px; margin-bottom: 8px; }
.editor-expand { display: flex; gap: 10px; justify-content: flex-end; margin: 0 0 6px; }
.editor-expand button { background: none; border: 0; padding: 2px 0; color: var(--text-muted); font-size: 10px; cursor: pointer; }
.editor-expand button:hover { color: var(--accent); }
.block-group { margin-bottom: 8px; border-left: 2px solid var(--accent-dark); padding-left: 6px; }
.block-group > summary { display: flex; align-items: center; gap: 6px; padding: 5px 2px; cursor: pointer; list-style: none; color: var(--text-primary); font-weight: 600; font-size: 12px; }
.block-group > summary span:first-of-type { flex: 1; }
.block-editor { margin-bottom: 6px; border: 1px solid var(--border-soft); border-radius: 5px; background: var(--panel-sunken); }
.block-editor.selected { border-color: var(--accent-dark); box-shadow: 0 0 0 1px var(--accent-soft); }
.block-editor > summary { display: flex; align-items: center; gap: 6px; padding: 7px 8px; cursor: pointer; list-style: none; font-size: 12px; }
.block-editor > summary:hover { background: var(--panel-hover); }
.block-summary-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-primary); font-weight: 600; }
.block-editor-body { padding: 4px 8px 8px; border-top: 1px solid var(--border-soft); }
.block-editor-body .prop-field { margin-bottom: 8px; }
.side-picker { display: flex; align-items: center; gap: 3px; margin: 0 0 8px; }
.side-picker > span { margin-right: 4px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.side-button
{
    flex: 1; padding: 4px 0; border-radius: 4px; cursor: pointer; font-size: 10px;
    background: var(--panel-raised); color: var(--text-secondary); border: 1px solid var(--border-color);
}
.side-button:hover { color: var(--text-primary); border-color: var(--accent-dark); }
.side-button.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-dark); }
.term-table { display: grid; gap: 4px; margin: 4px 0 8px; }
.term-row
{
    display: grid; grid-template-columns: 14px minmax(0, 1fr) 76px 20px 20px; gap: 4px; align-items: center;
    padding: 3px 4px; border-radius: 4px; border: 1px solid transparent;
}
.term-row.selected { background: var(--accent-soft); border-color: var(--accent-dark); }
.term-row input, .term-row select
{
    width: 100%; min-width: 0; padding: 4px 6px; border-radius: 3px; outline: none; font-size: 11px;
    background: var(--panel-background); color: var(--text-primary); border: 1px solid var(--border-color);
}
.term-row input:focus, .term-row select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.term-row .term-desc { grid-column: 2 / 6; padding: 3px 6px; font-size: 10px; color: var(--text-secondary); background: transparent; border-color: var(--border-soft); }
.term-dot { padding: 0; cursor: pointer; }
.term-icon { height: 22px; padding: 0; border-radius: 3px; cursor: pointer; background: none; border: 1px solid transparent; color: var(--text-muted); font-size: 12px; }
.term-icon:hover { color: var(--accent); border-color: var(--border-color); }
.term-icon.danger:hover { color: var(--danger); }
.term-connections { grid-column: 2 / 6; font-size: 10px; color: var(--text-secondary); line-height: 1.6; }
.term-connections .swatch-dot { display: inline-block; width: 8px; height: 8px; margin-right: 4px; border-radius: 50%; border: 1px solid var(--border-color); vertical-align: -1px; }
.compact-actions { gap: 6px; }
#propertiesPanel .compact-actions button.prop-button { padding: 5px 8px; font-size: 11px; }
#appShell:not(.hide-terminal-types) .term-row select.term-type { display: block; }

/* quick colour palette beside a new wire */
.quick-colors
{
    position: absolute; z-index: 60; display: grid; grid-template-columns: repeat(6, 22px); gap: 4px; padding: 6px;
    background: var(--panel-raised); border: 1px solid var(--border-color); border-radius: 8px; box-shadow: var(--menu-shadow);
}
.quick-colors[hidden] { display: none; }
.quick-swatch
{
    width: 22px; height: 22px; padding: 0; border-radius: 5px; cursor: pointer; position: relative;
    background: var(--swatch); border: 1px solid rgba(0, 0, 0, .45); box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .25);
}
.quick-swatch span { position: absolute; right: 1px; bottom: 0; font-size: 8px; font-weight: 700; color: #000; text-shadow: 0 0 2px #fff, 0 0 2px #fff; }
.quick-swatch:hover { transform: scale(1.12); }
.quick-swatch.selected { outline: 2px solid var(--accent); outline-offset: 1px; }

/* dragging a template from the library */
.library-ghost
{
    position: fixed; z-index: 4000; pointer-events: none; display: flex; align-items: flex-start; justify-content: center;
    padding-top: 6px; font-size: 11px; font-weight: 700; color: var(--text-primary);
    background: rgba(36, 200, 255, .08); border: 2px dashed var(--text-muted); border-radius: 6px; opacity: .9;
}
.library-ghost.valid { border-color: var(--accent); background: rgba(36, 200, 255, .16); }
body.library-dragging, body.library-dragging * { cursor: copy !important; user-select: none; }
.device-library-item { cursor: grab; }

/* Load dialog and renaming the project */
.load-list { display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; margin: 6px 0 12px; }
.load-item
{
    display: grid; gap: 2px; text-align: left; padding: 8px 10px; border-radius: 5px; cursor: pointer;
    background: var(--panel-raised); color: var(--text-primary); border: 1px solid var(--border-color);
}
.load-item:hover { border-color: var(--accent-dark); background: var(--panel-hover); }
.load-item.current { border-color: var(--accent-dark); }
.load-item small { color: var(--text-muted); font-size: 11px; }
#breadcrumbProject { cursor: text; border-radius: 3px; padding: 1px 3px; margin: -1px -3px; }
#breadcrumbProject:hover { background: var(--panel-hover); box-shadow: inset 0 -1px 0 var(--text-muted); }
.project-rename-input
{
    width: 220px; padding: 3px 6px; border-radius: 4px; font: inherit; font-size: 12px; outline: none;
    background: var(--panel-sunken); color: var(--text-primary); border: 1px solid var(--accent);
}
@media (pointer: coarse)
{
    .term-row { grid-template-columns: 18px minmax(0, 1fr) 84px 30px 30px; }
    .term-row input, .term-row select { min-height: 36px; font-size: 16px !important; }
    .term-icon { height: 34px; }
    .side-button { min-height: 36px; font-size: 12px; }
    .editor-add-select { min-height: 40px; font-size: 16px !important; }
    .quick-colors { grid-template-columns: repeat(6, 34px); }
    .quick-swatch { width: 34px; height: 34px; }
}


/* ==========================================================================
   v7: resizable / collapsible columns, device library groups, editor footer
   ========================================================================== */
/* drag handles between the columns (they overlap the borders, so they take no space) */
.panel-resizer
{
    flex: 0 0 8px; width: 8px; margin: 0 -4px; position: relative; z-index: 85;
    cursor: col-resize; touch-action: none; background: transparent;
}
.panel-resizer::after
{
    content: ""; position: absolute; top: 0; bottom: 0; left: 3px; width: 2px; border-radius: 1px;
    background: transparent; transition: background .12s;
}
.panel-resizer:hover::after, .panel-resizer.dragging::after { background: var(--accent); }
body.panel-resizing, body.panel-resizing * { cursor: col-resize !important; user-select: none !important; }
#appShell.tool-panel-collapsed #toolsResizer,
#appShell.properties-collapsed #propertiesResizer,
#appShell.compact .panel-resizer { display: none; }

/* collapse buttons and the slim strips a collapsed column leaves behind */
.panel-collapse-button { position: absolute; top: 12px; right: 8px; z-index: 3; width: 26px; min-height: 26px; }
.panel-strip { display: none; }
#appShell:not(.compact).tool-panel-collapsed #toolbar
{
    width: 34px; flex: 0 0 34px; overflow: hidden; cursor: pointer;
}
#appShell:not(.compact).tool-panel-collapsed #toolbar > :not(.panel-strip) { display: none; }
#appShell:not(.compact).tool-panel-collapsed .panel-strip,
#appShell:not(.compact).properties-collapsed .properties-header
{
    display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 10px 0; height: 100%; border: 0;
}
.panel-strip-label,
#appShell:not(.compact).properties-collapsed .properties-header h3
{
    writing-mode: vertical-rl; color: var(--text-secondary); font-size: 12px; font-weight: 600; letter-spacing: .04em; user-select: none;
}
#appShell:not(.compact).properties-collapsed #propertiesPanel { width: 34px; flex: 0 0 34px; cursor: pointer; }
#appShell:not(.compact).properties-collapsed #propertiesPanel:hover,
#appShell:not(.compact).tool-panel-collapsed #toolbar:hover { background: var(--panel-hover); }
#appShell:not(.compact).properties-collapsed #propertiesContent { display: none; }
#appShell:not(.compact).properties-collapsed .properties-header { order: -1; }
#appShell.compact .panel-collapse-button, #appShell.compact .panel-strip { display: none !important; }
/* the header text clears the collapse button */
.tool-panel-header { padding-right: 28px; }

/* device library: collapsible groups and subgroups */
.library-group { margin-bottom: 12px; }
.library-group[hidden], .library-subgroup[hidden] { display: none; }
.library-group > summary, .library-subgroup > summary
{
    display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none; user-select: none;
}
.library-group > summary::-webkit-details-marker, .library-subgroup > summary::-webkit-details-marker { display: none; }
.library-group > summary::before, .library-subgroup > summary::before
{
    content: "▸"; display: inline-block; width: 10px; color: var(--text-muted); font-size: 10px; transition: transform .12s;
}
.library-group[open] > summary::before, .library-subgroup[open] > summary::before { transform: rotate(90deg); }
.library-group > summary
{
    margin-bottom: 8px; color: var(--text-muted);
    font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.library-group > summary > span:first-of-type, .library-subgroup > summary > span:first-of-type { flex: 1; }
.library-group > summary:hover, .library-subgroup > summary:hover { color: var(--text-primary); }
.library-subgroup { margin: 0 0 8px 6px; padding-left: 8px; border-left: 2px solid var(--border-soft); }
.library-subgroup > summary { padding: 3px 0 6px; color: var(--text-secondary); font-size: 11px; font-weight: 600; }
.library-subgroup > .tool-button-stack { margin-bottom: 4px; }
.tool-panel-note.library-hidden-note { margin: 0 0 18px; }              /* same space as between sections */

/* properties: Add door above the terminal blocks, actions pinned to the bottom of the column */
.editor-door-row { margin: 0 0 12px; }
.editor-footer
{
    position: sticky; bottom: -14px; z-index: 4;
    margin: 12px -14px -14px; padding: 10px 14px 12px;
    background: var(--sidebar-background); border-top: 1px solid var(--border-soft);
    box-shadow: 0 -6px 12px rgba(0, 0, 0, .12);
}
.editor-footer .prop-button { flex: 1 1 auto; }
#appShell.compact .editor-footer { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.modal-warning { color: var(--warning, #f4ae3d); }
/* Free edition: paid features carry a PRO badge (gone in the full version) */
.free-edition .tool-action-button[data-pro] { position: relative; padding-right: 44px; }
.free-edition .tool-action-button[data-pro]::after { position: absolute; top: 50%; right: 8px; transform: translateY(-50%); margin: 0; }
.free-edition .tool-action-button[data-pro]::after,
.free-edition [data-pro] .command-label::after,
.free-edition .context-menu > [data-pro]::after
{
    content: "PRO"; margin-left: 6px; padding: 1px 5px; border-radius: 999px; vertical-align: 1px;
    background: var(--accent-soft); color: var(--accent); font-size: 9px; font-weight: 700; letter-spacing: .06em;
}
.tool-unlock-button { border-color: var(--accent-dark); }
.tool-unlock-button .tool-action-icon { color: var(--accent); }
/* Unlock window */
.unlock-reason { padding: 8px 10px; border-radius: 6px; background: var(--accent-soft); color: var(--text-primary); }
.unlock-list { margin: 8px 0 12px; padding-left: 18px; display: grid; gap: 7px; }
.unlock-list li b { display: block; color: var(--text-primary); }
.unlock-list li small { color: var(--text-secondary); font-size: 12px; }
.unlock-soon { margin: 10px 0; padding: 8px 10px; border: 1px dashed var(--border-color); border-radius: 6px; color: var(--text-secondary); }
.modal .unlock-notify { margin-top: 4px; }
/* About window (theme colours only, so it follows dark / light) */
.about-button { font-size: 16px; }
.about-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.about-logo { width: 44px; height: 44px; border-radius: 10px; flex: 0 0 auto; }
.about-name { font-size: 18px; font-weight: 700; color: var(--text-primary); }
.about-version { color: var(--text-muted); font-size: 12px; }
.about-section { margin: 14px 0 6px; color: var(--text-muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.about-list { margin: 0 0 10px; padding-left: 18px; display: grid; gap: 5px; color: var(--text-secondary); }
.modal .about-feedback { margin-top: 16px; padding-top: 4px; border-top: 1px solid var(--border-soft); }
.modal .about-feedback a { color: var(--accent); }
.about-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.modal .about-action { display: block; padding: 9px 10px; border: 1px solid var(--border-color); border-radius: 6px; background: var(--panel-sunken);
    color: var(--text-primary); text-align: center; text-decoration: none; font-weight: 600; font-size: 12px; }
.modal .about-action:hover { border-color: var(--accent); color: var(--accent); }
.link-button { padding: 0; border: 0; background: none; color: var(--accent); font: inherit; text-decoration: underline; cursor: pointer; }
@media (max-width: 420px) { .about-actions { grid-template-columns: 1fr; } }
/* first-visit disclaimer: theme colours only, so it follows dark / light */
.disclaimer-list { margin: 10px 0; padding-left: 18px; display: grid; gap: 8px; color: var(--text-secondary); }
.disclaimer-list li { line-height: 1.45; }
.disclaimer-list b { color: var(--text-primary); }
#propertiesContent:has(> .editor-footer) { display: flex; flex-direction: column; }
#propertiesContent:has(> .editor-footer) > * { flex-shrink: 0; }
#propertiesContent > .editor-footer { margin-top: auto; }
#appShell:not(.compact).properties-collapsed .properties-header { justify-content: flex-start; }
#appShell:not(.compact).properties-collapsed .properties-header h3 { order: 2; }


/* ==========================================================================
   v8: popups for blocks and doors, block reordering, door logic planner
   ========================================================================== */
.editor-add-button
{
    width: 100%; padding: 7px 9px; border-radius: 4px; cursor: pointer; text-align: left;
    background: var(--panel-raised); color: var(--accent); border: 1px dashed var(--accent-dark); font-size: 12px; font-weight: 600;
}
.editor-add-button:hover, .editor-add-button:focus-visible { border-style: solid; outline: none; background: var(--accent-soft); }

/* Add terminal block popup */
.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; margin-top: 10px; }
.preset-card
{
    display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 10px 11px; text-align: left; cursor: pointer;
    background: var(--panel-sunken); color: var(--text-primary); border: 1px solid var(--border-color); border-radius: 6px; font-size: 12px;
}
.preset-card:hover, .preset-card:focus-visible { border-color: var(--accent); background: var(--accent-soft); outline: none; }
.preset-card strong { font-size: 13px; }
.preset-terms { display: flex; flex-wrap: wrap; gap: 3px; }
.preset-term { padding: 1px 5px; border-radius: 3px; background: var(--panel-raised); color: var(--text-secondary); font-size: 10px; font-family: ui-monospace, Menlo, Consolas, monospace; }

/* radio cards (Add door, Plan a door) */
.choice-cards { display: grid; gap: 8px; margin: 10px 0 14px; }
.choice-card
{
    display: flex; align-items: flex-start; gap: 10px; padding: 10px 11px; cursor: pointer;
    background: var(--panel-sunken); border: 1px solid var(--border-color); border-radius: 6px;
}
.choice-card:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.choice-card input { margin-top: 2px; accent-color: var(--accent); }
.choice-card span { display: flex; flex-direction: column; gap: 3px; }
.choice-card strong { font-size: 13px; color: var(--text-primary); }
.choice-card small { color: var(--text-muted); font-size: 11px; line-height: 1.4; }
.door-count input { max-width: 120px; }
#modal:has(.preset-grid) { width: min(640px, calc(100vw - 32px)); }

/* drop position while dragging a terminal block */
.block-drop-marker { position: absolute; z-index: 6; background: var(--accent); border-radius: 2px; box-shadow: 0 0 0 2px var(--accent-soft); pointer-events: none; }

/* door logic planner */
.logic-top-actions { margin-bottom: 10px; }
.logic-totals { margin: 0 0 10px; color: var(--text-muted); font-size: 11px; line-height: 1.4; }
.logic-door { margin-bottom: 8px; border: 1px solid var(--border-soft); border-radius: 6px; background: var(--panel-sunken); }
.logic-door[open] { border-color: var(--accent-dark); }
.logic-door > summary { display: flex; align-items: center; gap: 8px; padding: 9px 10px; cursor: pointer; list-style: none; }
.logic-door > summary::-webkit-details-marker { display: none; }
.logic-door > summary::before { content: "▸"; color: var(--text-muted); font-size: 10px; transition: transform .12s; }
.logic-door[open] > summary::before { transform: rotate(90deg); }
.logic-door-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; font-size: 12px; color: var(--text-primary); }
.logic-badge { padding: 1px 7px; border-radius: 999px; font-size: 10px; font-weight: 700; }
.logic-badge.ok { background: rgba(60, 200, 120, .16); color: #4cd38a; }
.logic-badge.fail { background: rgba(240, 100, 100, .16); color: var(--danger); }
.logic-badge.warn { background: rgba(244, 174, 61, .18); color: #f4ae3d; }
.logic-badge.missing { background: var(--panel-raised); color: var(--text-muted); }
.logic-door-body { padding: 4px 10px 10px; border-top: 1px solid var(--border-soft); }
.logic-sub { margin: 12px 0 6px; color: var(--text-muted); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.logic-sub small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.logic-row { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.logic-field { display: block; margin-bottom: 6px; }
.logic-field > span { display: block; margin-bottom: 3px; color: var(--text-secondary); font-size: 10px; font-weight: 600; }
.logic-field input, .logic-field select, .logic-field textarea
{
    width: 100%; padding: 5px 7px; background: var(--panel-background); color: var(--text-primary);
    border: 1px solid var(--border-color); border-radius: 4px; font-size: 11px; outline: none;
}
.logic-field textarea { min-height: 46px; resize: vertical; }
.logic-field input:focus, .logic-field select:focus, .logic-field textarea:focus { border-color: var(--accent); }
.logic-field.small input { max-width: 90px; }
.logic-checks { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 5px; }
.logic-check
{
    display: flex; gap: 8px; padding: 7px 8px; border-radius: 5px; cursor: pointer;
    background: var(--panel-background); border: 1px solid var(--border-soft); border-left-width: 3px;
}
.logic-check:hover, .logic-check:focus-visible { background: var(--panel-hover); outline: none; }
.logic-check.focused { box-shadow: 0 0 0 2px #f4ae3d; }
.logic-check.ok, .logic-check.info { border-left-color: #4cd38a; }
.logic-check.fail { border-left-color: var(--danger); }
.logic-check.warn { border-left-color: #f4ae3d; }
.logic-check.missing, .logic-check.na { border-left-color: var(--border-color); opacity: .85; }
.logic-icon
{
    flex: 0 0 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 11px; font-weight: 700;
    background: var(--panel-raised); color: var(--text-muted);
}
.logic-check.ok .logic-icon, .logic-check.info .logic-icon { background: rgba(60, 200, 120, .18); color: #4cd38a; }
.logic-check.fail .logic-icon { background: rgba(240, 100, 100, .18); color: var(--danger); }
.logic-check.warn .logic-icon { background: rgba(244, 174, 61, .2); color: #f4ae3d; }
.logic-check-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.logic-check-text strong { font-size: 11px; color: var(--text-primary); line-height: 1.35; }
.logic-check-text small { font-size: 10px; color: var(--text-secondary); line-height: 1.45; }
.logic-actions { display: flex; justify-content: flex-end; }
.tool-mini-button { padding: 4px 9px; border-radius: 4px; background: transparent; border: 1px solid var(--border-color); color: var(--text-secondary); font-size: 11px; cursor: pointer; }
.tool-mini-button.danger { color: var(--danger); border-color: rgba(240, 100, 100, .45); }
.tool-mini-button.danger:hover { background: rgba(240, 100, 100, .14); }

/* the logic layer on the drawing: only the open door's devices and wires stay bright */
#canvas.logic-layer .device { transition: opacity .15s; }
#canvas.logic-layer .device:not(.logic-in) { opacity: .2; }
#canvas.logic-layer #wireLayer [data-wire-id]:not(.logic-in):not(.logic-focus) { opacity: .1; }
#canvas.logic-layer .device.logic-in { box-shadow: 0 0 0 2px rgba(36, 200, 255, .35); }
#wireLayer [data-wire-id].logic-focus .wire-casing { stroke: #f4ae3d; stroke-width: 9; }
#wireLayer text.logic-focus { fill: #f4ae3d; }
.terminal.logic-focus { outline: 3px solid #f4ae3d; outline-offset: 3px; z-index: 5; }
.logic-door-body { container-type: inline-size; }
/* collapsible door-plan sections: Reader, Lock, Exit, Monitoring */
.logic-expand { display: flex; justify-content: flex-end; gap: 6px; margin: 4px 0 8px; }
.logic-section { margin-bottom: 8px; border: 1px solid var(--border-soft); border-radius: 5px; background: var(--panel-background); }
.logic-section > summary { display: flex; align-items: center; gap: 8px; padding: 7px 10px; cursor: pointer; list-style: none; }
.logic-section > summary::-webkit-details-marker { display: none; }
.logic-section > summary::before { content: "▸"; color: var(--text-muted); font-size: 10px; transition: transform .12s; }
.logic-section[open] > summary::before { transform: rotate(90deg); }
.logic-section-title { flex: 1; color: var(--text-secondary); font-size: 10px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
.logic-section-body { padding: 2px 10px 8px; border-top: 1px solid var(--border-soft); }
.logic-section-body > .logic-field:first-child { margin-top: 8px; }
.logic-section-body .logic-checks { margin: 8px 0 0; }
.logic-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border-color); flex: 0 0 auto; }
.logic-dot.ok { background: #4cd38a; }
.logic-dot.fail { background: var(--danger); }
.logic-dot.warn { background: #f4ae3d; }
.logic-door-body > .logic-checks { margin: 2px 0 8px; }
.logic-notes { margin-top: 4px; }
/* crash bar / mechanical egress option */
.logic-check-option { display: flex; align-items: flex-start; gap: 8px; margin: 2px 0 4px; cursor: pointer; }
.logic-check-option input { width: auto; height: auto; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
.logic-check-option span { display: flex; flex-direction: column; gap: 2px; color: var(--text-primary); font-size: 11px; font-weight: 600; }
.logic-check-option small { color: var(--text-muted); font-size: 10px; font-weight: 400; line-height: 1.4; }
/* acknowledged problems turn green */
.logic-check.ack { border-left-color: #4cd38a; }
.logic-check.ack .logic-icon { background: rgba(60, 200, 120, .18); color: #4cd38a; }
.logic-check.ack em { font-style: normal; color: #4cd38a; }
.logic-ack { align-self: flex-start; margin-top: 3px; padding: 2px 8px; border-radius: 4px; border: 1px solid var(--border-color); background: transparent; color: var(--text-secondary); font-size: 10px; cursor: pointer; }
.logic-ack:hover { border-color: var(--accent); color: var(--accent); }
@container (max-width: 300px) { .logic-row { grid-template-columns: 1fr; gap: 0; } }
.choice-card input[type="radio"] { width: auto; height: auto; flex: 0 0 auto; margin: 2px 0 0; padding: 0; box-shadow: none; }
.choice-card span { flex: 1; text-align: left; }
#doorNumbersHint { color: var(--text-muted); }
