        *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
        :root {
            --primary: #2ED9A0;
            --primary-dark: #1FB787;
            --primary-light: #E8FBF4;
            --primary-soft: #E8FBF4;
            --primary-hover: #1FB787;
            --accent: #2ED9A0;
            --accent-hover: #1FB787;
            --accent-soft: #E8FBF4;
            --success: #15a34a;
            --success-hover: #15803d;
            --danger: #dc2626;
            --warning: #c2820f;
            --bg: #fbfcfd;
            --bg-soft: #eef1f5;
            --card: #ffffff;
            --card-hover: #f6f8fb;
            --input-bg: #ffffff;
            --text: #1c2530;
            --text-primary: #1c2530;
            --text-secondary: #51606f;
            --text-muted: #76828f;
            --border: #e4e8ee;
            --border-strong: #cdd4dd;
            --flow-dc: #2563eb;
            --flow-ac: #ef4444;
            --flow-dc-glow: rgba(37, 99, 235, 0.52);
            --flow-ac-glow: rgba(239, 68, 68, 0.52);
            --flow-source: #2563eb;
            --flow-load: #2563eb;
            --select-menu-bg: #ffffff;
            --select-option-text: #1c2530;
            --select-option-hover: #1FB787;
            --select-option-hover-text: #ffffff;
            --chart-grid: rgba(148, 163, 184, 0.22);
            --chart-axis: #76828f;
            --chart-tooltip-bg: #ffffff;
            --chart-tooltip-text: #1c2530;
            --sidebar-bg: #161d2b;
            --sidebar-text: #cbd3df;
            --sidebar-muted: #7c8794;
            --sidebar-active: rgba(46, 217, 160, 0.30);
            --flow-board-bg: #ffffff;
            --flow-board-dot: #d0d7e0;
            --node-bg: rgba(255,255,255,0.96);
            --node-empty-bg: rgba(255,255,255,0.6);
            --radius: 12px;
            --radius-sm: 8px;
            --shadow: 0 1px 2px rgba(28,37,48,0.05), 0 1px 1px rgba(28,37,48,0.03);
            --shadow-lg: 0 14px 28px -12px rgba(28,37,48,0.12), 0 4px 8px -4px rgba(28,37,48,0.06);
            --shadow-glow-primary: 0 0 0 rgba(37,99,235,0);
            --shadow-glow-accent: 0 0 14px rgba(46,217,160,0.20);
            /* Theme axes added for FAT_FE parity: font family + glass blur (the opacity engine
               in app.js overrides --dock-bg / --dock-border / --glass-blur on <body> at runtime). */
            --font-display: Calibri, 'Carlito', 'Libre Franklin', 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, sans-serif;
            --glass-blur: 16px;
        }
        /* Font toggle: Calibri (default, premium) <-> Roboto (matches FAT_FE). */
        body[data-font="roboto"] {
            --font-display: 'Roboto', 'Calibri', 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Arial, sans-serif;
        }
        body[data-theme="night"] {
            --primary: #7FE9C8;
            --primary-dark: #2ED9A0;
            --primary-light: rgba(127, 233, 200, 0.18);
            --primary-soft: rgba(127, 233, 200, 0.18);
            --primary-hover: #A6F0DA;
            --accent: #7FE9C8;
            --accent-hover: #A6F0DA;
            --accent-soft: rgba(127, 233, 200, 0.18);
            --success: #22c55e;
            --success-hover: #16a34a;
            --danger: #f05252;
            --warning: #e0a82e;
            --bg: #12161d;
            --bg-soft: #161d29;
            --card: #1a2230;
            --card-hover: #222c3d;
            --input-bg: #141b27;
            --text: #eef2f8;
            --text-primary: #eef2f8;
            --text-secondary: #aab6c7;
            --text-muted: #7d8a9c;
            --border: #2b3647;
            --border-strong: #3c4a5e;
            --flow-dc: #4f8cff;
            --flow-ac: #f87171;
            --flow-dc-glow: rgba(79, 140, 255, 0.85);
            --flow-ac-glow: rgba(248, 113, 113, 0.85);
            --flow-source: #4f8cff;
            --flow-load: #4f8cff;
            --select-menu-bg: #1a2230;
            --select-option-text: #eef2f8;
            --select-option-hover: #1FB787;
            --select-option-hover-text: #ffffff;
            --chart-grid: rgba(170, 182, 199, 0.16);
            --chart-axis: #aab6c7;
            --chart-tooltip-bg: #1a2230;
            --chart-tooltip-text: #eef2f8;
            --sidebar-bg: #0a0f17;
            --sidebar-text: #d2d9e4;
            --sidebar-muted: #7d8a9c;
            --sidebar-active: rgba(46, 217, 160, 0.28);
            --flow-board-bg: #131a25;
            --flow-board-dot: rgba(79, 140, 255, 0.40);
            --node-bg: rgba(26, 34, 48, 0.96);
            --node-empty-bg: rgba(26, 34, 48, 0.62);
            --shadow: 0 2px 10px rgba(0,0,0,0.40), 0 1px 3px rgba(0,0,0,0.28);
            --shadow-lg: 0 18px 44px rgba(0,0,0,0.48), 0 0 20px rgba(46,217,160,0.14);
            --shadow-glow-primary: 0 0 18px rgba(46,217,160,0.32), 0 0 36px rgba(46,217,160,0.14);
            --shadow-glow-accent: 0 0 18px rgba(46,217,160,0.26), 0 0 36px rgba(46,217,160,0.10);
        }
        body[data-theme="presentation"] {
            --primary: #5b92ff;
            --primary-dark: #3b78f0;
            --primary-light: rgba(91, 146, 255, 0.20);
            --primary-soft: rgba(91, 146, 255, 0.20);
            --primary-hover: #7aa6ff;
            --accent: #5b92ff;
            --accent-hover: #7aa6ff;
            --accent-soft: rgba(91, 146, 255, 0.20);
            --success: #2dd06a;
            --success-hover: #22c55e;
            --danger: #ff5a5a;
            --warning: #eab234;
            --bg: #0e1117;
            --bg-soft: #161b23;
            --card: #181e27;
            --card-hover: #212834;
            --input-bg: #161b23;
            --text: #f3f5f8;
            --text-primary: #f3f5f8;
            --text-secondary: #b3bcc9;
            --text-muted: #828d9b;
            --border: #2d343e;
            --border-strong: #404956;
            --flow-dc: #5b92ff;
            --flow-ac: #ff5a5a;
            --flow-dc-glow: rgba(91, 146, 255, 0.90);
            --flow-ac-glow: rgba(255, 90, 90, 0.90);
            --flow-source: #5b92ff;
            --flow-load: #5b92ff;
            --select-menu-bg: #181e27;
            --select-option-text: #f3f5f8;
            --select-option-hover: #3b78f0;
            --select-option-hover-text: #ffffff;
            --chart-grid: rgba(179, 188, 201, 0.14);
            --chart-axis: #b3bcc9;
            --chart-tooltip-bg: #161b23;
            --chart-tooltip-text: #f3f5f8;
            --sidebar-bg: #0a0d12;
            --sidebar-text: #eef1f6;
            --sidebar-muted: #828d9b;
            --sidebar-active: rgba(91, 146, 255, 0.30);
            --flow-board-bg: #11151c;
            --flow-board-dot: rgba(91, 146, 255, 0.50);
            --node-bg: rgba(24, 30, 39, 0.97);
            --node-empty-bg: rgba(24, 30, 39, 0.64);
            --shadow: 0 4px 16px rgba(0,0,0,0.42), 0 0 14px rgba(91,146,255,0.10);
            --shadow-lg: 0 24px 56px rgba(0,0,0,0.50), 0 0 24px rgba(91,146,255,0.16);
            --shadow-glow-primary: 0 0 20px rgba(91,146,255,0.32), 0 0 44px rgba(91,146,255,0.14);
            --shadow-glow-accent: 0 0 20px rgba(91,146,255,0.26), 0 0 44px rgba(91,146,255,0.10);
        }
        body {
            font-family: var(--font-display);
            background: var(--bg);
            color: var(--text);
            line-height: 1.6;
            transition: background 0.22s ease, color 0.22s ease;
        }
        .app-shell { display: flex; min-height: 100vh; }
        .app-sidebar {
            width: 248px; flex-shrink: 0; background: var(--sidebar-bg); color: var(--sidebar-text);
            display: flex; flex-direction: column; padding: 22px 14px;
            position: sticky; top: 0; height: 100vh; overflow-y: auto;
            box-shadow: inset -1px 0 0 rgba(255,255,255,0.04);
            transition: background 0.22s ease, color 0.22s ease;
        }
        .app-sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
        .app-sidebar .brand-mark {
            width: 32px; height: 32px; overflow: hidden;
            display: flex; align-items: center; justify-content: center;
        }
        .app-sidebar .brand-mark img { width: 100%; height: 100%; object-fit: contain; display: block; }
        .app-sidebar .brand-text { display: flex; flex-direction: column; line-height: 1.15; }
        .app-sidebar .brand-text strong { color: #f1f5f9; font-size: 14px; font-weight: 800; letter-spacing: 0.1px; }
        .app-sidebar .brand-text span { color: var(--sidebar-muted); font-size: 11px; font-weight: 600; }
        .theme-switcher {
            position: relative; display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px;
            margin: 0 4px 14px; padding: 4px; border: 1px solid rgba(148, 163, 184, 0.18);
            border-radius: 999px; background: rgba(255,255,255,0.06); overflow: hidden;
        }
        .theme-switcher::before {
            content: ""; position: absolute; top: 4px; bottom: 4px; left: 4px;
            width: calc((100% - 8px) / 3); border-radius: 999px;
            background: var(--accent); box-shadow: var(--shadow-glow-accent);
            transform: translateX(calc(var(--theme-index, 0) * 100%));
            transition: transform 0.22s ease, background 0.22s ease, box-shadow 0.22s ease;
        }
        .theme-switcher[data-theme-active="night"] { --theme-index: 1; }
        .theme-switcher[data-theme-active="auto"] { --theme-index: 2; }
        .theme-option {
            position: relative; z-index: 1; border: none; background: transparent; color: var(--sidebar-text);
            display: inline-flex; align-items: center; justify-content: center; gap: 4px;
            min-height: 30px; border-radius: 999px; cursor: pointer; font: inherit;
            font-size: 11px; font-weight: 800; opacity: 0.72; transition: color 0.16s ease, opacity 0.16s ease;
        }
        .theme-option.active { color: #ffffff; opacity: 1; }
        .theme-option span:first-child { font-size: 13px; line-height: 1; }
        .nav-list { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
        .nav-item {
            display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 8px;
            border: none; background: transparent; color: var(--sidebar-text); cursor: pointer;
            font-size: 13.5px; font-weight: 600; text-align: left; width: 100%;
            transition: background 0.12s, color 0.12s;
        }
        .nav-item:hover { background: rgba(148, 163, 184, 0.10); color: #f1f5f9; }
        .nav-item.active { background: var(--sidebar-active); color: #ffffff; font-weight: 700; box-shadow: inset 4px 0 0 var(--primary); }
        .nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: 0.85; }
        .nav-item.active svg { opacity: 1; color: #93c5fd; }
        /* Coloured PNG icons (full-colour, not tinted by currentColor like the SVGs). */
        .nav-item img.nav-icon { width: 20px; height: 20px; flex-shrink: 0; object-fit: contain; }
        /* Nested items inside a group sit slightly indented and use a smaller font. */
        .nav-item-nested { padding-left: 22px; font-size: 13px; }
        /* Group header: small uppercase label with a chevron. Clicking it toggles the group. */
        .nav-group-header {
            display: flex; align-items: center; gap: 8px; width: 100%;
            padding: 12px 12px 6px; border: none; background: transparent;
            color: var(--sidebar-muted); font-size: 10.5px; font-weight: 800; letter-spacing: 0.08em;
            text-transform: uppercase; cursor: pointer; text-align: left;
            transition: color 0.12s;
        }
        .nav-group-header:hover { color: #cbd5e1; }
        .nav-group-chevron {
            display: inline-flex; align-items: center; justify-content: center;
            width: 14px; height: 14px; font-size: 10px;
            transition: transform 0.15s;
        }
        .nav-group-header.collapsed .nav-group-chevron { transform: rotate(-90deg); }
        .nav-group { display: flex; flex-direction: column; gap: 2px; overflow: hidden; }
        .nav-group.collapsed { max-height: 0; padding: 0; margin: 0; }
        .app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

        /* --- Collapsible sidebar: toggle button --- */
        .sidebar-toggle-btn {
            margin-left: auto; flex-shrink: 0; width: 28px; height: 28px; padding: 0;
            display: inline-flex; align-items: center; justify-content: center;
            border: 1px solid rgba(148,163,184,0.22); border-radius: 8px; cursor: pointer;
            background: rgba(255,255,255,0.06); color: var(--sidebar-text); transition: background 0.14s ease;
        }
        .sidebar-toggle-btn:hover { background: rgba(148,163,184,0.18); color: #f1f5f9; }
        .sidebar-toggle-btn svg { width: 16px; height: 16px; }

        /* When collapsed: hide the sidebar entirely; main fills the width. */
        .app-shell.sidebar-collapsed .app-sidebar { display: none; }
        .app-shell.sidebar-collapsed .app-main { padding-bottom: 96px; }

        /* Dock / floating-control surface colours, themed. Day = light glass; Night/Present = dark glass. */
        :root {
            --dock-bg: rgba(255,255,255,0.62); --dock-border: rgba(0,0,0,0.10);
            --dock-fg: #334155; --dock-sep: rgba(0,0,0,0.16); --dock-control-bg: rgba(0,0,0,0.05);
            --dock-shadow: 0 14px 44px rgba(15,23,42,0.18);
        }
        body[data-theme="night"], body[data-theme="presentation"] {
            --dock-bg: rgba(22,27,38,0.55); --dock-border: rgba(255,255,255,0.16);
            --dock-fg: #e2e8f0; --dock-sep: rgba(255,255,255,0.28); --dock-control-bg: rgba(255,255,255,0.08);
            --dock-shadow: 0 14px 44px rgba(0,0,0,0.42);
        }

        /* --- Floating top-right controls (collapsed state) --- */
        .floating-controls {
            display: none; position: fixed; top: 14px; right: 16px; z-index: 60;
            align-items: center; gap: 10px; padding: 7px 9px; border-radius: 999px;
            background: var(--dock-bg); backdrop-filter: blur(16px) saturate(140%);
            -webkit-backdrop-filter: blur(16px) saturate(140%);
            border: 1px solid var(--dock-border); box-shadow: var(--dock-shadow);
        }
        /* Bottom-dock is the standard layout and theme now lives in the gear (map-settings) panel,
           so the floating burger + the legacy day/night/auto switcher are retired from view.
           Markup is kept (and still wired via the compat shim) for easy rollback. */
        .app-shell.sidebar-collapsed .floating-controls { display: none; }
        #theme-switcher { display: none; }
        .floating-controls .theme-switcher { margin: 0; background: var(--dock-control-bg); border-color: var(--dock-border); }
        /* Collapsed view shows theme icons only — hide the Day/Night/Present text labels. */
        .floating-controls .theme-option { color: var(--dock-fg); min-width: 30px; }
        .floating-controls .theme-option span:last-child { display: none; }
        .floating-controls .theme-option span:first-child { font-size: 15px; }
        .floating-btn {
            width: 34px; height: 34px; padding: 0; display: inline-flex; align-items: center; justify-content: center;
            border: 1px solid var(--dock-border); border-radius: 50%; cursor: pointer;
            background: var(--dock-control-bg); color: var(--dock-fg); transition: background 0.14s ease;
        }
        .floating-btn:hover { filter: brightness(1.15); }
        .floating-btn svg { width: 18px; height: 18px; }

        /* --- macOS-style dock (collapsed state) --- */
        .app-dock {
            display: none; position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 60;
            align-items: flex-end; gap: 8px; padding: 8px 12px; border-radius: 22px;
            background: var(--dock-bg); backdrop-filter: blur(20px) saturate(150%);
            -webkit-backdrop-filter: blur(20px) saturate(150%);
            border: 1px solid var(--dock-border); box-shadow: var(--dock-shadow);
            max-width: calc(100vw - 32px); overflow: visible;
        }
        .app-shell.sidebar-collapsed .app-dock { display: flex; }
        .dock-item {
            position: relative; width: 50px; height: 50px; flex-shrink: 0; padding: 5px;
            border: none; background: transparent; cursor: pointer;
            display: flex; align-items: center; justify-content: center;
            transition: transform 0.16s cubic-bezier(0.2,0.8,0.3,1.3);
        }
        .dock-item img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.25)); }
        .dock-item svg { width: 60%; height: 60%; stroke: var(--dock-fg); fill: none; }
        .dock-item:hover { transform: translateY(-10px) scale(1.16); }
        .dock-item:active { transform: translateY(-4px) scale(1.05); }
        /* Running/active indicator dot, macOS style. */
        .dock-item.active::before {
            content: ""; position: absolute; bottom: -4px; left: 50%; transform: translateX(-50%);
            width: 4px; height: 4px; border-radius: 50%; background: var(--dock-fg); opacity: 0.85;
        }
        /* Hover tooltip with the full name, above the icon. Follows the active theme. */
        .dock-item[data-label]::after {
            content: attr(data-label); position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translateX(-50%);
            background: var(--select-menu-bg); color: var(--text-primary); border: 1px solid var(--border-strong);
            font-size: 12px; font-weight: 600; letter-spacing: 0.2px;
            padding: 5px 10px; border-radius: 7px; white-space: nowrap; pointer-events: none;
            opacity: 0; transition: opacity 0.12s ease; box-shadow: var(--shadow);
        }
        .dock-item:hover::after { opacity: 1; }
        .dock-sep { width: 1px; align-self: stretch; margin: 6px 5px; background: var(--dock-sep); border-radius: 1px; }
        /* Responsive container width: previous default was 1280 — bumping to 1400 for a little more breathing room without overflow. */
        .container { max-width: 1400px; width: 100%; margin: 0 auto; padding: 28px 32px; }
        /* `.builder-grid` left as a no-op wrapper — it just renders as a block so the form and results stack vertically as before. */
        .builder-grid { display: block; }
        .page-title {
            margin-bottom: 22px; padding: 18px 22px; border-radius: var(--radius);
            background-color: var(--dock-bg); border: 1px solid var(--dock-border); box-shadow: var(--shadow);
            backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
        }
        .page-title-row { display: flex; align-items: center; gap: 14px; }
        .page-title-icon { width: 40px; height: 40px; flex-shrink: 0; object-fit: contain; }
        .page-title h1 { font-size: clamp(26px, 2.6vw, 34px); font-weight: 700; letter-spacing: -0.01em; color: var(--text); line-height: 1.15; }
        .page-title p { font-size: 13.5px; color: var(--text-muted); margin-top: 4px; }
        @media (max-width: 900px) {
            .app-shell { flex-direction: column; }
            .app-sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; padding: 12px; }
            .app-sidebar .brand { width: 100%; padding: 6px 10px 10px; }
            .nav-list { flex-direction: row; flex-wrap: wrap; gap: 4px; width: 100%; }
            .nav-item { flex: 1 1 auto; min-width: 130px; }
            .container { padding: 18px; }
        }
        /* Legacy classes kept so any old refs don't break */
        .module-strip { display: none; }
        .module-pill { display: none; }
        .module-content { display: none; }
        .module-content.active { display: block; }
        .tabs { display: inline-flex; gap: 2px; margin-bottom: 22px; background: var(--card); border-radius: var(--radius); padding: 5px; box-shadow: var(--shadow); border: 1px solid var(--border); }
        .tab-btn {
            padding: 9px 20px; border: none; background: transparent; border-radius: var(--radius-sm);
            cursor: pointer; font-size: 13.5px; font-weight: 600; color: var(--text-secondary);
            transition: background 0.15s, color 0.15s;
        }
        .tab-btn.active { background: var(--primary); color: white; }
        .tab-btn:hover:not(.active) { background: var(--primary-soft); color: var(--text); }
        .tab-content { display: none; }
        .tab-content.active { display: block; }
        .card {
            background: var(--card); border-radius: var(--radius); padding: 22px;
            box-shadow: var(--shadow); margin-bottom: 18px; border: 1px solid var(--border);
        }
        .card h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; color: var(--text); letter-spacing: -0.01em; }
        .card h3 { font-size: 14px; font-weight: 700; margin-bottom: 12px; color: var(--text); }
        .card-header { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
        .card-header h2 { margin: 0; }
        .card-header .card-icon { width: 22px; height: 22px; color: var(--primary); flex-shrink: 0; }
        .card-sub { font-size: 12.5px; color: var(--text-muted); margin-top: -8px; margin-bottom: 16px; }
        .form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
        .form-group { display: flex; flex-direction: column; gap: 6px; }
        .form-group label { font-size: 13px; font-weight: 600; color: var(--text-secondary); }
        .form-group input, .form-group select, .form-group textarea {
            padding: 9px 13px; border: 1px solid var(--border-strong); border-radius: 14px;
            font-size: 14px; transition: border-color 0.15s, box-shadow 0.15s; outline: none;
            background-color: var(--input-bg); color: var(--text);
        }
        .form-group input:hover, .form-group select:hover, .form-group textarea:hover { border-color: var(--border-strong); }
        .form-group input:focus, .form-group select:focus, .form-group textarea:focus {
            border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
        }
        /* Custom select chevron — applies to every <select> in the app */
        select {
            -webkit-appearance: none; -moz-appearance: none; appearance: none;
            padding-right: 36px !important;
            min-width: 0;
            width: 100%;
            border-radius: 14px !important;
            line-height: 1.25;
            white-space: normal;
            text-overflow: clip;
            overflow: visible;
            color-scheme: light;
            box-shadow: inset 0 1px 0 rgba(255,255,255,0.05);
            background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1.5L6 6.5L11 1.5' stroke='%2364748b' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
            background-repeat: no-repeat;
            background-position: right 13px center;
            background-size: 12px 8px;
            cursor: pointer;
        }
        select:hover {
            background-color: var(--card-hover);
            border-color: var(--primary);
        }
        body[data-theme="night"] select,
        body[data-theme="presentation"] select { color-scheme: dark; }
        select option {
            background: var(--select-menu-bg);
            color: var(--select-option-text);
            font: inherit;
            min-height: 28px;
            padding: 5px 10px;
            line-height: 1.18;
            font-size: 13.5px;
            white-space: normal;
            border-radius: 9px;
        }
        select option:checked,
        select option:hover,
        select option:focus {
            background: var(--select-option-hover) !important;
            color: var(--select-option-hover-text) !important;
        }
        select:open {
            border-color: var(--primary);
            border-radius: 14px !important;
            box-shadow: 0 0 0 3px var(--primary-soft);
        }
        select::-ms-expand { display: none; }
        @supports (appearance: base-select) {
            select {
                appearance: base-select;
                background-image: none;
            }
            select::picker(select) {
                appearance: base-select;
                background: var(--select-menu-bg);
                color: var(--select-option-text);
                border: 1px solid var(--border-strong);
                border-radius: 16px;
                box-shadow: var(--shadow-lg);
                padding: 5px;
                margin-top: 6px;
                max-height: min(340px, 68vh);
                overflow-y: auto;
                scrollbar-width: thin;
                scrollbar-color: var(--border-strong) transparent;
            }
            select option {
                border-radius: 11px;
                min-height: 30px;
                padding: 5px 10px;
                margin: 1px 0;
            }
            select option::checkmark {
                font-size: 12px;
                margin-inline-end: 8px;
            }
            select option:checked,
            select option:hover,
            select option:focus {
                background: var(--select-option-hover) !important;
                color: var(--select-option-hover-text) !important;
            }
        }
        /* Standalone select (outside .form-group) — apply input look directly */
        .select-inline {
            padding: 8px 36px 8px 13px !important;
            border: 1px solid var(--border-strong);
            border-radius: 14px;
            font-size: 13.5px; font-weight: 600; color: var(--text);
            background-color: var(--input-bg);
            outline: none;
            transition: border-color 0.15s, box-shadow 0.15s;
            min-width: 140px;
            width: max-content;
            max-width: 100%;
        }
        .select-inline:hover { border-color: var(--primary); background-color: var(--card-hover); }
        .select-inline:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
        .form-group textarea { min-height: 120px; font-family: monospace; font-size: 12px; resize: vertical; }
        .btn {
            padding: 10px 18px; border: 1px solid transparent; border-radius: var(--radius-sm); cursor: pointer;
            font-size: 13.5px; font-weight: 600; transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
            display: inline-flex; align-items: center; justify-content: center; gap: 8px;
            line-height: 1.2;
        }
        .btn:focus-visible { outline: 2px solid rgba(46, 217, 160, 0.45); outline-offset: 2px; }
        .btn-primary { background: var(--primary); color: white; }
        .btn-primary:hover { background: var(--primary-hover); box-shadow: var(--shadow-glow-primary); }
        .btn-success { background: var(--success); color: #ffffff; }
        .btn-success:hover { background: var(--success-hover); }
        .btn-danger { background: var(--danger); color: white; }
        .btn-danger:hover { background: #b91c1c; }
        .btn-outline { background: var(--card); color: var(--primary); border: 1px solid var(--border-strong); }
        .btn-outline:hover { background: var(--primary-light); border-color: var(--primary); }
        .btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
        .btn-ghost:hover { background: var(--primary-soft); color: var(--text); }
        .btn-icon { width: 32px; height: 32px; padding: 0; border-radius: 8px; }
        .btn-sm { padding: 6px 12px; font-size: 12px; }
        .btn-group { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
        .action-row { align-items: flex-end; gap: 12px; }
        .action-row .profile-count { flex: 0 0 92px; }
        .action-row .profile-count select { height: 40px; width: 100%; }
        .action-row .btn { height: 40px; padding: 0 18px; white-space: nowrap; }
        .action-row .btn-primary { min-width: 172px; justify-content: center; }
        .profile-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
        .library-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; }
        .library-sections { display: flex; flex-direction: column; gap: 26px; }
        .library-section { background: transparent; padding: 0; box-shadow: none; }
        /* Custom HTML legend for the Energy Flow Timeline — white "pills" on a soft bar. */
        .chart-legend {
            display: flex; flex-wrap: wrap; justify-content: center; gap: 8px;
            margin-top: 12px; padding: 10px 12px; border-radius: 14px; background: var(--dock-control-bg);
        }
        .chart-legend-pill {
            display: inline-flex; align-items: center; gap: 8px; padding: 6px 13px;
            border: 1px solid var(--dock-border); border-radius: 999px; cursor: pointer; font: inherit;
            font-size: 12px; font-weight: 600; color: var(--text-primary);
            background: var(--dock-bg); box-shadow: 0 1px 3px rgba(15,23,42,0.12);
            transition: opacity 0.14s ease, box-shadow 0.14s ease, transform 0.1s ease;
        }
        .chart-legend-pill:hover { box-shadow: 0 2px 6px rgba(15,23,42,0.20); }
        .chart-legend-pill:active { transform: scale(0.97); }
        .chart-legend-pill.hidden { opacity: 0.42; }
        .chart-legend-pill.hidden .clp-label { text-decoration: line-through; }
        .clp-marker { width: 14px; height: 14px; flex-shrink: 0; box-sizing: border-box; }
        .clp-marker.clp-square { border-radius: 4px; }
        .clp-marker.clp-circle { border-radius: 50%; }
        .clp-marker.clp-dashed { border-radius: 4px; background: transparent !important; border: 2px dashed currentColor; }

        .library-section h3 {
            font-size: 18px; font-weight: 800; margin-bottom: 14px; color: var(--text); letter-spacing: -0.01em;
            display: inline-flex; align-items: center; gap: 10px; width: fit-content;
            padding: 10px 16px; border-radius: var(--radius);
            background-color: var(--dock-bg); border: 1px solid var(--dock-border); box-shadow: var(--shadow);
            backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
        }
        .library-section h3 span { color: var(--text-muted); font-size: 13px; font-weight: 600; }
        .library-section-icon { width: 26px; height: 26px; object-fit: contain; flex-shrink: 0; }
        .profile-card {
            background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
            padding: 18px; transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
            position: relative; display: flex; flex-direction: column; gap: 12px;
        }
        .profile-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
        .profile-card .pc-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
        .profile-card h4 { font-size: 15px; font-weight: 700; color: var(--text); line-height: 1.25; flex: 1; }
        .profile-card .pc-actions { display: flex; gap: 4px; flex-shrink: 0; }
        .profile-card .pc-actions button {
            width: 28px; height: 28px; padding: 0; border: 1px solid transparent; background: transparent;
            border-radius: 6px; cursor: pointer; color: var(--text-muted);
            display: inline-flex; align-items: center; justify-content: center;
            transition: background 0.12s, color 0.12s, border-color 0.12s;
        }
        .profile-card .pc-actions button:hover { background: var(--primary-soft); color: var(--text); }
        .profile-card .pc-actions button.danger:hover { color: var(--danger); background: rgba(220, 38, 38, 0.08); }
        .profile-card .badge {
            display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px;
            font-size: 11px; font-weight: 700; background: var(--primary-light); color: var(--primary);
            align-self: flex-start;
        }
        /* PEAK / TOTAL stat boxes */
        .profile-card .pc-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
        .profile-card .pc-stat { background: var(--bg-soft); border-radius: 10px; padding: 12px 14px; min-width: 0; }
        .profile-card .pc-stat-label { font-size: 11px; font-weight: 700; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-muted); margin-bottom: 5px; }
        .profile-card .pc-stat-value { font-size: 22px; font-weight: 800; color: var(--primary); line-height: 1.05; }
        .profile-card .pc-stat-value.neutral { color: var(--text); }
        .profile-card .pc-stat-unit { font-size: 12px; font-weight: 600; color: var(--text-muted); }
        /* Meta rows: label left, value right-aligned */
        .profile-card .pc-meta { font-size: 12px; display: flex; flex-direction: column; gap: 5px; padding-top: 12px; border-top: 1px solid var(--border); }
        .profile-card .pc-meta-row { display: flex; justify-content: space-between; gap: 12px; }
        .profile-card .pc-meta-row span:first-child { color: var(--text-muted); flex-shrink: 0; }
        .profile-card .pc-meta-row span:last-child { color: var(--text-secondary); font-weight: 600; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

        /* Profile Library module tab bar */
        .library-tabs { display: flex; flex-wrap: wrap; gap: 4px; padding: 5px; margin-bottom: 22px; background: var(--bg-soft); border: 1px solid var(--border); border-radius: 12px; width: fit-content; max-width: 100%; }
        .library-tab {
            display: inline-flex; align-items: center; gap: 7px; padding: 8px 16px; border: none; background: transparent;
            border-radius: 8px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 700; color: var(--text-secondary);
            transition: background 0.14s ease, color 0.14s ease;
        }
        .library-tab:hover:not(.active) { background: var(--card); color: var(--text); }
        .library-tab.active { background: var(--primary); color: #fff; box-shadow: var(--shadow-glow-primary); }
        .library-tab-icon { width: 17px; height: 17px; object-fit: contain; }
        .library-tab-count { font-weight: 600; opacity: 0.8; }
        .library-toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
        .library-search { flex: 1; position: relative; }
        .library-search svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
        .library-search input {
            width: 100%; padding: 11px 14px 11px 38px; border: 1px solid var(--border-strong);
            border-radius: var(--radius-sm); font-size: 14px; background: var(--input-bg); color: var(--text);
            outline: none; transition: border-color 0.15s, box-shadow 0.15s;
        }
        .library-search input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
        .stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
        .stat-card {
            background: var(--card); border-radius: var(--radius); padding: 18px;
            box-shadow: var(--shadow); text-align: center; min-width: 0; overflow: hidden;
        }
        .stat-card .value {
            font-size: clamp(18px, 2vw, 28px); font-weight: 800; color: var(--primary);
            line-height: 1.15; max-width: 100%; overflow-wrap: anywhere; word-break: break-word;
        }
        .stat-card .label { font-size: 12px; color: var(--text-secondary); margin-top: 4px; font-weight: 600; }
        .stats-grid.stats-compact { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-top: 14px; margin-bottom: 0; }
        .stats-compact .stat-card { padding: 10px 12px; }
        .stats-compact .stat-card .value { font-size: clamp(14px, 1.2vw, 18px); }
        .stats-compact .stat-card .label { font-size: 10px; margin-top: 2px; }
        .chart-container { position: relative; height: 400px; margin-top: 16px; }
        .vehicle-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 12px; }
        .vehicle-table th, .vehicle-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
        .vehicle-table th { background: var(--bg-soft); font-weight: 700; color: var(--text-secondary); font-size: 12px; text-transform: uppercase; }
        .vehicle-table tr:hover { background: var(--primary-light); }
        .table-wrap { max-height: 400px; overflow-y: auto; border: 1px solid var(--border); border-radius: 8px; }
        .toast {
            position: fixed; bottom: 24px; right: 24px; padding: 14px 22px; border-radius: 10px;
            color: white; font-weight: 600; font-size: 14px; z-index: 999;
            box-shadow: var(--shadow-lg); animation: slideIn 0.3s ease;
        }
        .toast.success { background: var(--success); color: #ffffff; }
        .toast.error { background: var(--danger); color: #ffffff; }
        @keyframes slideIn { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
        .empty-state { text-align: center; padding: 48px 20px; color: var(--text-secondary); }
        .empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: 0.4; }
        .vehicle-select-row { display: flex; gap: 12px; align-items: end; margin-bottom: 12px; }
        .vehicle-select-row .form-group { flex: 1; }
        .ev-action-panel { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
        .ev-action-panel .profile-count { width: min(120px, 100%); margin-bottom: 2px; }
        .ev-availability-header {
            display: flex; align-items: flex-end; justify-content: space-between;
            gap: 16px; flex-wrap: wrap; margin-top: 2px; margin-bottom: 16px;
        }
        .ev-availability-header h3 { margin: 0; }
        .ev-preset-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: flex-end; }
        .ev-action-footer { display: flex; justify-content: flex-end; gap: 12px; flex-wrap: wrap; margin-top: 2px; }
        .ev-action-footer .btn-primary { min-width: 224px; }
        .slider-group { display: flex; align-items: center; gap: 12px; }
        .slider-group input[type="range"] { flex: 1; }
        .slider-group .slider-val { font-weight: 700; min-width: 40px; text-align: center; }
        input[type="range"] {
            --range-pct: 0%;
            -webkit-appearance: none;
            appearance: none;
            height: 28px;
            background: transparent;
            cursor: pointer;
            accent-color: var(--primary);
        }
        input[type="range"]:focus { outline: none; }
        input[type="range"]::-webkit-slider-runnable-track {
            height: 14px;
            border-radius: 999px;
            background: linear-gradient(to right, var(--primary) 0 var(--range-pct), var(--dock-border) var(--range-pct) 100%);
            box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.10);
        }
        input[type="range"]::-webkit-slider-thumb {
            -webkit-appearance: none;
            appearance: none;
            width: 22px;
            height: 22px;
            margin-top: -4px;
            border-radius: 50%;
            background: var(--primary);
            border: 3px solid #ffffff;
            box-shadow: 0 2px 6px rgba(15, 23, 42, 0.24), var(--shadow-glow-primary);
        }
        input[type="range"]:focus-visible::-webkit-slider-thumb {
            box-shadow: 0 0 0 4px var(--primary-soft), var(--shadow-glow-primary);
        }
        input[type="range"]::-moz-range-track {
            height: 14px;
            border-radius: 999px;
            background: var(--dock-border);
            box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.10);
        }
        input[type="range"]::-moz-range-progress {
            height: 14px;
            border-radius: 999px;
            background: linear-gradient(to right, var(--primary), var(--primary-hover));
        }
        input[type="range"]::-moz-range-thumb {
            width: 16px;
            height: 16px;
            border-radius: 50%;
            background: var(--primary);
            border: 3px solid #ffffff;
            box-shadow: 0 2px 6px rgba(15, 23, 42, 0.24), var(--shadow-glow-primary);
        }
        body[data-theme="night"] input[type="range"]::-webkit-slider-runnable-track,
        body[data-theme="presentation"] input[type="range"]::-webkit-slider-runnable-track {
            background: linear-gradient(to right, var(--primary) 0 var(--range-pct), var(--dock-border) var(--range-pct) 100%);
        }
        body[data-theme="night"] input[type="range"]::-moz-range-track,
        body[data-theme="presentation"] input[type="range"]::-moz-range-track {
            background: var(--dock-border);
        }
        .availability-editor {
            border: 1px solid var(--dock-border); border-radius: 8px; padding: 14px 14px 10px;
            background: var(--dock-control-bg);
            overflow-x: auto;
        }
        /* Hourly availability sliders — pill-shaped track with gradient fill and a custom circular thumb.
           Implemented via a rotated horizontal range inside a fixed-height wrapper so we keep full control over the
           track + thumb (native vertical sliders ignore custom thumb styling in many browsers). */
        .hourly-grid {
            display: grid; grid-template-columns: repeat(24, minmax(0, 1fr));
            gap: clamp(2px, 0.4vw, 10px); width: 100%; align-items: end; margin-top: 12px;
            padding-top: 24px; padding-bottom: 4px;
        }
        .hour-control { display: flex; flex-direction: column; align-items: center; gap: 8px; min-width: 0; }
        .hour-control .hour-value {
            font-size: 11px; font-weight: 800; color: var(--text); line-height: 1; white-space: nowrap;
            text-align: center;
        }
        .hour-control.is-zero .hour-value { visibility: hidden; }
        .hour-slider-wrap {
            position: relative;
            width: 100%; max-width: 26px;
            height: 180px;
        }
        .hour-slider-track {
            position: absolute; top: 0; bottom: 0; left: 50%; transform: translateX(-50%);
            width: 14px; border-radius: 999px;
            background: var(--dock-border);
            overflow: hidden;
            pointer-events: none;
        }
        .hour-slider-fill {
            position: absolute; left: 0; right: 0; bottom: 0;
            height: calc(var(--val, 100) * 1%);
            background: linear-gradient(to top, var(--primary-soft), var(--primary));
            border-radius: 999px;
            transition: height 0.06s linear;
        }
        .hour-slider-thumb {
            position: absolute; left: 50%; transform: translate(-50%, 50%);
            bottom: calc(var(--val, 100) * 1%);
            width: 20px; height: 20px; border-radius: 50%;
            background: var(--primary);
            border: 3px solid #ffffff;
            box-shadow: 0 1px 3px rgba(15, 23, 42, 0.2);
            pointer-events: none;
            transition: bottom 0.06s linear;
        }
        .hour-control.is-zero .hour-slider-thumb {
            background: #fff;
            border: 2px solid #cbd5e1;
            box-shadow: 0 1px 2px rgba(15, 23, 42, 0.1);
        }
        /* The actual input sits invisibly on top, taking the full wrapper area so dragging works. */
        .hour-slider-wrap input[type="range"] {
            position: absolute; left: 50%; top: 50%;
            width: 180px; height: 26px;
            transform: translate(-50%, -50%) rotate(-90deg);
            transform-origin: center;
            -webkit-appearance: none; appearance: none;
            background: transparent; margin: 0; padding: 0; cursor: pointer;
            opacity: 0; /* hidden visually; we draw the track and thumb ourselves */
        }
        .hour-slider-wrap input[type="range"]:focus { outline: none; }
        .hour-control .hour-label {
            font-size: 10.5px; color: var(--text-muted); font-weight: 600; letter-spacing: 0.02em;
        }
        .system-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 18px; align-items: start; margin-top: 18px; }
        .system-sidebar { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 12px; }
        .unit-layout { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 18px; align-items: start; }
        /* The saved-microgrids list can grow without bound; keep the column tidy by scrolling the
           list internally (so the 3 columns stay balanced) instead of stretching the whole page. */
        #unit-library-list { max-height: 62vh; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding-right: 6px; }

        /* ── Themed scrollbars, app-wide (follow day/night) — replaces the OS default everywhere:
           the whole page and every scroll area (results, profiles, runs, modes, library, microgrid…). ── */
        * { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
        ::-webkit-scrollbar { width: 10px; height: 10px; }
        ::-webkit-scrollbar-track { background: transparent; }
        ::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
        ::-webkit-scrollbar-thumb:hover { background: var(--primary); background-clip: padding-box; }
        .system-panel { position: relative; display: flex; flex-direction: column; gap: 14px; }
        .system-panel select[multiple] { min-height: 110px; }
        .flow-board {
            position: relative; min-height: 560px; border: 1px solid var(--border); border-radius: 10px;
            background-color: var(--flow-board-bg);
            background-image: radial-gradient(var(--flow-board-dot) 1.1px, transparent 1.1px);
            background-size: 14px 14px; overflow: hidden;
            box-shadow: var(--shadow); transition: background-color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
        }
        /* AC / DC bus legend, floated in the gap ABOVE the simulation card's top-right (not inside
           it). Absolute so it takes no layout space — the flow board stays level with the Source
           Priority card. */
        .flow-bus-legend {
            position: absolute; top: calc(50% - 132px); left: 50%; transform: translateX(-50%); z-index: 4;
            display: inline-flex; gap: 14px; align-items: center; width: fit-content;
            padding: 5px 12px; border-radius: 999px;
            background: var(--dock-bg); border: 1px solid var(--dock-border); box-shadow: var(--dock-shadow);
            backdrop-filter: blur(10px) saturate(140%); -webkit-backdrop-filter: blur(10px) saturate(140%);
            font-size: 12px; font-weight: 700; color: var(--text);
        }
        .flow-bus-legend .fbl-item { display: inline-flex; align-items: center; gap: 7px; }
        .flow-bus-legend .fbl-line {
            width: 22px; height: 0; border-top: 3px dashed var(--flow-ac); border-radius: 3px;
        }
        .flow-bus-legend .fbl-line.dc { border-top-color: var(--flow-dc); }
        .flow-bus-legend .fbl-line.ac { border-top-color: var(--flow-ac); }
        .flow-node {
            position: absolute; width: 132px; min-height: 112px; border: 1px solid var(--border);
            border-radius: 10px; background: var(--node-bg); box-shadow: var(--shadow);
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            text-align: center; padding: 10px; z-index: 2; color: var(--text);
            transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
        }
        .flow-node.inverter { left: calc(50% - 78px); top: calc(50% - 92px); width: 156px; min-height: 174px; cursor: pointer; font: inherit; color: inherit; }
        button.flow-node.inverter:hover { border-color: var(--primary); box-shadow: var(--shadow-lg), var(--shadow-glow-primary); }
        button.flow-node.inverter:focus { outline: 2px solid var(--primary); outline-offset: 2px; }
        .inverter-warning { margin-top: 6px; padding: 4px 8px; border-radius: 6px; background: #fef3c7; color: #92400e; font-size: 11px; font-weight: 800; line-height: 1.2; }
        .stat-card.stat-warn { border: 1px solid var(--warning); background: linear-gradient(180deg, rgba(245,158,11,0.16) 0%, var(--card) 72%); }
        .stat-card.stat-warn .label { color: #92400e; font-weight: 800; }
        .system-port-node {
            position: absolute; width: 138px; min-height: 116px; border: 1px solid var(--border);
            border-radius: 10px; background: var(--node-bg); box-shadow: var(--shadow);
            display: flex; flex-direction: column; align-items: center; justify-content: center;
            text-align: center; padding: 10px; z-index: 2; cursor: pointer; color: var(--text);
            transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, box-shadow 0.22s ease;
        }
        .system-port-node:hover { border-color: var(--primary); box-shadow: var(--shadow-lg), var(--shadow-glow-primary); }
        .system-port-node.dc { border-top: 4px solid var(--flow-dc); }
        .system-port-node.ac { border-top: 4px solid var(--flow-ac); }
        .system-port-node.empty { border-style: dashed; background: var(--node-empty-bg); opacity: 0.72; }
        .system-port-node.empty .node-title { color: var(--text-secondary); }
        .node-icon { width: 52px; height: 52px; margin-bottom: 6px; color: var(--primary); display: flex; align-items: center; justify-content: center; }
        .node-icon img { display: block; max-width: 100%; max-height: 100%; }
        .node-title { font-size: 14px; font-weight: 800; line-height: 1.15; }
        .node-value { font-size: 12px; color: var(--text-secondary); margin-top: 4px; line-height: 1.2; }
        .port-badge { position: absolute; top: 7px; left: 8px; font-size: 10px; font-weight: 900; color: var(--text-secondary); }
        .port-popover {
            position: absolute; right: 18px; top: 18px; width: 300px; z-index: 5;
            background: var(--card); border: 1px solid var(--border); border-radius: 10px;
            box-shadow: var(--shadow-lg); padding: 14px; display: none;
        }
        .port-popover.active { display: block; }
        .flow-svg { position: absolute; inset: 0; width: 100%; height: 100%; z-index: 1; pointer-events: none; }
        .flow-line { fill: none; stroke-width: 3; stroke-linecap: round; stroke-dasharray: 8 7; opacity: 0.2; animation: flowDash 0.8s linear infinite; }
        .flow-line.dc { stroke: var(--flow-dc); }
        .flow-line.ac { stroke: var(--flow-ac); }
        .flow-line.idle { opacity: 0.12; animation: none; }
        .flow-line.reverse { animation: flowDashReverse 0.8s linear infinite; }
        .flow-svg.paused .flow-line { animation-play-state: paused !important; }
        .port-connected {
            position: absolute; bottom: 6px; right: 8px;
            background: var(--success); color: #ffffff; font-size: 9px; font-weight: 800;
            padding: 2px 7px; border-radius: 999px;
            opacity: 0; transform: translateY(2px);
            transition: opacity 0.2s, transform 0.2s;
            pointer-events: none;
        }
        .port-connected.show { opacity: 1; transform: translateY(0); }
        @keyframes flowDash { to { stroke-dashoffset: -30; } }
        @keyframes flowDashReverse { to { stroke-dashoffset: 30; } }
        .timeline-row { display: flex; align-items: center; gap: 12px; margin-top: 14px; }
        .timeline-row input[type="range"] { flex: 1; }
        .mode-window-scroll {
            max-height: min(58vh, 520px);
            overflow-y: auto;
            padding-right: 4px;
            margin-right: -4px;
            scrollbar-width: thin;
            scrollbar-color: var(--border-strong) transparent;
        }
        .mode-window-scroll::-webkit-scrollbar { width: 7px; }
        .mode-window-scroll::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 999px; }
        .mode-window-actions {
            position: sticky;
            bottom: 0;
            z-index: 3;
            background: var(--card);
            border-top: 1px solid var(--border);
            padding-top: 10px;
            margin-top: 10px;
        }
        .mode-set-btn {
            background: #2ED9A0 !important;
            color: #ffffff !important;
            border: 1px solid #1FB787 !important;
        }
        .mode-set-btn:hover {
            background: #1FB787 !important;
            color: #fff !important;
            border-color: #17976F !important;
        }
        .mode-delete-btn {
            background: #fef2f2 !important;
            color: #dc2626 !important;
            border-color: #fca5a5 !important;
            transition: background 0.15s, color 0.15s, border-color 0.15s;
        }
        .mode-delete-btn:hover {
            background: #fee2e2 !important;
            color: #b91c1c !important;
            border-color: #f87171 !important;
        }
        .mode-window-footer {
            display: flex;
            justify-content: flex-end;
            gap: 6px;
            margin-top: 8px;
            padding-top: 8px;
            border-top: 1px dashed var(--border);
        }
        @media (max-width: 980px) {
            .system-layout { grid-template-columns: 1fr; }
            .system-sidebar { position: static; }
            .flow-board { min-height: 680px; }
            .port-popover { position: static; width: auto; margin: 12px; }
            .mode-window-scroll { max-height: 420px; }
        }
        .loading { display: inline-block; width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.3); border-radius: 50%; border-top-color: white; animation: spin 0.6s linear infinite; }
        @keyframes spin { to { transform: rotate(360deg); } }
        /* Profile preview modal */
        .profile-modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 24px; }
        .profile-modal-backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, 0.55); backdrop-filter: blur(2px); }
        .profile-modal-card { position: relative; background: var(--card); color: var(--text); border: 1px solid var(--border); border-radius: 14px; box-shadow: var(--shadow-lg); width: min(820px, 100%); max-height: 90vh; overflow-y: auto; padding: 22px 24px; }
        .profile-modal-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border-bottom: 1px solid var(--border); padding-bottom: 12px; }
        /* Per-module saved profiles list */
        .module-saved-profiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
        .saved-profile-row {
            background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 12px;
            display: flex; flex-direction: column; gap: 6px; transition: border-color 0.15s, box-shadow 0.15s;
        }
        .saved-profile-row:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
        .saved-profile-row .sp-name { font-weight: 700; font-size: 13.5px; color: var(--text); line-height: 1.25; }
        .saved-profile-row .sp-meta { font-size: 11.5px; color: var(--text-muted); }
        .saved-profile-row .sp-actions { display: flex; gap: 6px; margin-top: 6px; }
        .saved-profile-row .sp-actions button { padding: 5px 10px; font-size: 11.5px; }
        .priority-source-icon {
            width: 34px; height: 34px; flex: 0 0 34px;
            display: inline-flex; align-items: center; justify-content: center;
        }
        .priority-source-icon img,
        .priority-source-icon svg { display: block; max-width: 100%; max-height: 100%; }
        .priority-source-icon.compact { width: 24px; height: 24px; flex-basis: 24px; }
        body[data-theme="night"] .btn-success,
        body[data-theme="presentation"] .btn-success { color: #ffffff; }
        body[data-theme="night"] .card,
        body[data-theme="night"] .profile-card,
        body[data-theme="presentation"] .card,
        body[data-theme="presentation"] .profile-card { box-shadow: var(--shadow); }
        body[data-theme="night"] .card:hover,
        body[data-theme="night"] .profile-card:hover,
        body[data-theme="presentation"] .card:hover,
        body[data-theme="presentation"] .profile-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-lg); }
        body[data-theme="night"] .flow-line.dc:not(.idle) {
            filter: saturate(1.2) drop-shadow(0 0 5px var(--flow-dc-glow)) drop-shadow(0 0 15px var(--flow-dc-glow));
        }
        body[data-theme="night"] .flow-line.ac:not(.idle) {
            filter: saturate(1.2) drop-shadow(0 0 5px var(--flow-ac-glow)) drop-shadow(0 0 15px var(--flow-ac-glow));
        }
        body[data-theme="presentation"] .flow-line.dc:not(.idle) {
            filter: saturate(1.28) drop-shadow(0 0 6px var(--flow-dc-glow)) drop-shadow(0 0 17px var(--flow-dc-glow));
        }
        body[data-theme="presentation"] .flow-line.ac:not(.idle) {
            filter: saturate(1.28) drop-shadow(0 0 6px var(--flow-ac-glow)) drop-shadow(0 0 17px var(--flow-ac-glow));
        }
        body[data-theme="night"] .flow-line.dc,
        body[data-theme="presentation"] .flow-line.dc { stroke: var(--flow-dc); }
        body[data-theme="night"] .flow-line.ac,
        body[data-theme="presentation"] .flow-line.ac { stroke: var(--flow-ac); }
        body[data-theme="presentation"] .flow-board { min-height: 640px; box-shadow: var(--shadow-lg), inset 0 0 50px rgba(11, 109, 255, 0.08); }
        body[data-theme="presentation"] .system-port-node,
        body[data-theme="presentation"] .flow-node { transform: scale(1.02); }
        body[data-theme="presentation"] .stat-card .value { font-size: clamp(22px, 2.3vw, 32px); }
        body[data-theme="night"] [style*="background:#fff"],
        body[data-theme="night"] [style*="background: #fff"],
        body[data-theme="night"] [style*="background:#f8fafc"],
        body[data-theme="night"] [style*="background:#f1f5f9"],
        body[data-theme="presentation"] [style*="background:#fff"],
        body[data-theme="presentation"] [style*="background: #fff"],
        body[data-theme="presentation"] [style*="background:#f8fafc"],
        body[data-theme="presentation"] [style*="background:#f1f5f9"] {
            background: var(--card) !important;
        }
        body[data-theme="night"] [style*="color:#334155"],
        body[data-theme="night"] [style*="color: #334155"],
        body[data-theme="presentation"] [style*="color:#334155"],
        body[data-theme="presentation"] [style*="color: #334155"] {
            color: var(--text-secondary) !important;
        }
        @media (max-width: 900px) {
            .theme-switcher { width: 100%; max-width: 360px; margin: 0 8px 10px; }
        }

        /* ===================================================================
           Live map backdrop + glassmorphism. The whole app floats over a Google
           Map; surfaces use the same translucent-blur treatment as the dock.
           =================================================================== */
        .map-bg { position: fixed; inset: 0; z-index: -2; overflow: hidden; pointer-events: none; }
        .map-bg iframe { width: 100%; height: 100%; border: 0; }
        .map-bg .mapboxgl-canvas, .map-bg canvas { width: 100% !important; height: 100% !important; }
        .map-bg .mapboxgl-ctrl-logo, .map-bg .mapboxgl-ctrl-attrib { display: none !important; }

        /* Map settings button + panel (mirrors the main FAT app's map settings). */
        .map-settings { position: fixed; top: 14px; right: 14px; z-index: 60; }
        .map-settings-btn {
            width: 42px; height: 42px; display: flex; align-items: center; justify-content: center;
            border-radius: 10px; cursor: pointer; color: var(--dock-fg);
            background: var(--dock-bg); border: 1px solid var(--dock-border);
            backdrop-filter: blur(16px) saturate(140%); -webkit-backdrop-filter: blur(16px) saturate(140%);
            box-shadow: 0 6px 20px rgba(0,0,0,0.28); transition: color .15s ease, border-color .15s ease;
        }
        /* Accent colour (visible on both light and dark glass) instead of white, which vanished on
           the day-theme light button. The 45° rotate on hover matches FAT_FE's gear button. */
        .map-settings-btn:hover { color: var(--primary); border-color: var(--primary); }
        .map-settings-btn svg { width: 20px; height: 20px; transition: transform .3s ease; }
        .map-settings-btn:hover svg { transform: rotate(45deg); }
        .map-settings-panel {
            position: absolute; top: 50px; right: 0; width: 232px; padding: 14px; color: var(--dock-fg);
            background: var(--dock-bg); border: 1px solid var(--dock-border); border-radius: 12px;
            backdrop-filter: blur(20px) saturate(150%); -webkit-backdrop-filter: blur(20px) saturate(150%);
            box-shadow: 0 12px 40px rgba(0,0,0,0.45);
        }
        .map-settings-panel[hidden] { display: none; }
        /* Match FAT_FE MapControls: bordered sections + muted, wide-tracked labels. */
        .ms-section { margin-bottom: 14px; padding-bottom: 14px; border-bottom: 1px solid var(--dock-border); }
        .ms-section:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: none; }
        .ms-label { font-size: 10px; font-weight: 600; letter-spacing: 1.5px; text-transform: uppercase; opacity: .75; margin-bottom: 10px; }
        .ms-btn-row { display: flex; gap: 6px; }
        .ms-time-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
        .ms-btn {
            flex: 1; padding: 8px 6px; border-radius: 8px; cursor: pointer; font-size: 12px; font-weight: 600;
            background: var(--dock-control-bg); color: var(--dock-fg); border: 1px solid var(--dock-border);
            display: flex; flex-direction: column; align-items: center; gap: 3px; transition: border-color .14s ease, background .14s ease;
        }
        .ms-btn .ms-ico { font-size: 15px; }
        .ms-btn.ms-time { padding: 7px 0; }
        .ms-btn:hover:not(:disabled) { border-color: var(--primary); }
        .ms-btn.active { background: rgba(46, 217, 160, 0.14); color: var(--text-primary); border-color: var(--primary); }
        .ms-btn:disabled { cursor: default; }
        .ms-value { float: right; font-weight: 800; color: var(--primary); font-variant-numeric: tabular-nums; opacity: 1; }
        .ms-range { width: 100%; accent-color: var(--primary); cursor: pointer; }
        /* Sun-sync toggle (System Simulator playback bar): highlights when active. */
        #sim-auto-theme-btn { white-space: nowrap; }
        #sim-auto-theme-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
        .ms-toggle-row { display: flex; align-items: center; justify-content: space-between; padding: 5px 0; }
        .ms-toggle-row span { font-size: 12.5px; }
        .ms-switch { position: relative; width: 38px; height: 21px; flex-shrink: 0; cursor: pointer; }
        .ms-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
        .ms-slider { position: absolute; inset: 0; border-radius: 999px; background: rgba(148,163,184,.35); transition: background .18s ease; }
        .ms-slider::before { content: ''; position: absolute; height: 15px; width: 15px; left: 3px; top: 3px; border-radius: 50%; background: #fff; transition: transform .18s ease; }
        .ms-switch input:checked + .ms-slider { background: var(--primary); }
        .ms-switch input:checked + .ms-slider::before { transform: translateX(17px); }

        /* Let the map show through every structural container. */
        body, .app-shell, .app-main, .container, .tab-content, .builder-grid,
        .system-layout, .system-panel, .system-sidebar { background: transparent !important; }

        /* Frosted-glass surfaces (same translucency/blur as the dock). */
        .card, .profile-card, .flow-board, .flow-node, .system-port-node, .profile-modal-card, .stat-card,
        .library-tabs, .saved-profile-row,
        input[type="text"], input[type="number"], input[type="password"], select, textarea {
            background-color: var(--dock-bg) !important;
            backdrop-filter: blur(var(--glass-blur, 16px)) saturate(140%);
            -webkit-backdrop-filter: blur(var(--glass-blur, 16px)) saturate(140%);
            border-color: var(--dock-border) !important;
        }
        /* Sidebar keeps light-on-dark text, so it always gets a dark glass regardless of theme. */
        .app-sidebar {
            background: rgba(16, 21, 33, 0.62) !important;
            backdrop-filter: blur(20px) saturate(150%);
            -webkit-backdrop-filter: blur(20px) saturate(150%);
        }
        /* Nested mini-boxes: lightly translucent so the glass layering stays subtle. */
        .pc-stat { background: var(--dock-control-bg) !important; }
