        /* --- Crompton design tokens --- */
        :root {
            --navy: #0f1e33;
            --navy-2: #16294a;
            --primary: #1f6fbf;
            --primary-hover: #185a9d;
            --primary-light: #eaf2fb;
            --secondary: #5e6e82;
            --accent: #3f8edb;

            --bg-body: #eef2f7;
            --bg-surface: #ffffff;
            --bg-muted: #f4f7fb;

            --text-main: #0f1e33;
            --text-sub: #5e6e82;

            --border-color: #d6dfea;
            --border-hover: #b6c5d8;

            --success-color: #18865a;
            --warning-color: #b45309;
            --danger-color: #b42335;

            --shadow-xs: 0 1px 2px rgba(21, 32, 40, 0.04);
            --shadow-sm: 0 2px 8px rgba(21, 32, 40, 0.06);
            --shadow-md: 0 8px 20px rgba(21, 32, 40, 0.08);
            --shadow-lg: 0 16px 32px rgba(21, 32, 40, 0.1);
            --shadow-xl: 0 24px 48px rgba(21, 32, 40, 0.12);

            --radius-sm: 6px;
            --radius-md: 10px;
            --radius-lg: 14px;
            --font-sans: "Inter", "Segoe UI", system-ui, sans-serif;
            --font-display: "Inter", "Segoe UI", system-ui, sans-serif;
            --focus-ring: 0 0 0 3px rgba(31, 111, 191, 0.25);
        }

        /* --- Base Reset & Typography --- */
        * { box-sizing: border-box; }
        body {
          font-family: var(--font-sans);
          background: var(--bg-body);
          min-height: 100vh;
          color: var(--text-main);
          margin: 0;
          padding: 20px;
          line-height: 1.55;
          -webkit-font-smoothing: antialiased;
          text-rendering: optimizeLegibility;
        }
        body::before {
          content: '';
          position: fixed;
          inset: 0;
          background-image:
            none;
          background-size: 48px 48px;
          mask-image: radial-gradient(ellipse at center, black 35%, transparent 80%);
          pointer-events: none;
          z-index: 0;
        }

        h1, h2, h3, h4, h5, h6 {
          margin: 0 0 0.75rem 0;
          font-weight: 700;
          color: var(--text-main);
          letter-spacing: -0.02em;
          line-height: 1.25;
        }
        h1 { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.025em; }
        p { margin: 0 0 1rem 0; color: var(--text-sub); }

        /* --- Layout --- */
        .container {
            max-width: 1280px;
            margin: 0 auto;
            background: var(--bg-surface);
            display: flex;
            flex-direction: column;
            min-height: calc(100vh - 40px);
            padding: 32px 40px;
            box-shadow: var(--shadow-lg);
            border-radius: var(--radius-lg);
            position: relative;
            z-index: 1;
            border: 1px solid var(--border-color);
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 24px;
            margin-bottom: 28px;
            border-bottom: 1px solid var(--border-color);
            padding-bottom: 20px;
        }
        /* --- App bar (navy) --- */
        .app-bar {
            display: grid;
            grid-template-columns: auto minmax(0, 1fr) auto;
            align-items: center;
            gap: 20px;
            margin: -32px -40px 24px;
            padding: 14px 28px;
            background: var(--navy);
            color: #fff;
            border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        }
        .app-brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
        .app-brand img { height: 30px; width: auto; filter: invert(1); mix-blend-mode: screen; }
        .app-brand-text { display: flex; flex-direction: column; line-height: 1.2; border-left: 1px solid rgba(255,255,255,0.18); padding-left: 14px; }
        .app-brand-text strong { font-size: 0.98rem; font-weight: 700; color: #fff; }
        .app-brand-text span { font-size: 0.72rem; color: #9fb3c8; letter-spacing: 0.04em; }
        .app-project { display: flex; gap: 10px; justify-content: center; min-width: 0; }
        .app-project label { display: flex; flex-direction: column; gap: 2px; font-size: 0.66rem; letter-spacing: 0.12em; text-transform: uppercase; color: #9fb3c8; font-weight: 600; min-width: 0; }
        .app-project input {
            width: 100%; min-width: 0; padding: 6px 10px; border-radius: 6px;
            border: 1px solid rgba(255,255,255,0.16); background: var(--navy-2); color: #fff;
            font: 600 0.88rem/1.2 var(--font-sans); letter-spacing: 0; text-transform: none;
        }
        .app-project input::placeholder { color: #7f93ab; font-weight: 500; }
        .app-project input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(63, 142, 219, 0.3); }
        .app-project .app-project-name { flex: 1 1 260px; max-width: 360px; }
        .app-project .app-project-job { flex: 0 1 150px; }
        .app-menus { display: flex; align-items: center; gap: 8px; }
        .app-menu { position: relative; }
        .app-menu > summary {
            list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 8px;
            padding: 7px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.16);
            color: #fff; font-weight: 600; font-size: 0.86rem; white-space: nowrap;
        }
        .app-menu > summary::-webkit-details-marker { display: none; }
        .app-menu > summary:hover, .app-menu[open] > summary { background: var(--navy-2); }
        .app-menu > summary::after { content: '▾'; font-size: 0.75rem; color: #9fb3c8; }
        .app-avatar {
            width: 24px; height: 24px; border-radius: 999px; background: var(--accent); color: #fff;
            display: inline-flex; align-items: center; justify-content: center; font-size: 0.75rem; font-weight: 800;
        }
        .app-menu-panel {
            position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px;
            background: #fff; color: var(--text-main); border: 1px solid var(--border-color);
            border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; display: flex; flex-direction: column;
        }
        .app-menu-panel .app-menu-meta { padding: 8px 10px 10px; border-bottom: 1px solid var(--border-color); margin-bottom: 4px; font-size: 0.8rem; color: var(--text-sub); }
        .app-menu-panel .app-menu-meta strong { display: block; color: var(--text-main); font-size: 0.86rem; overflow: hidden; text-overflow: ellipsis; }
        .app-menu-panel a, .app-menu-panel button {
            display: flex !important; width: 100%; justify-content: flex-start; align-items: center;
            padding: 8px 10px; border: 0; border-radius: 6px; background: none; box-shadow: none;
            color: var(--text-main); font: 500 0.88rem/1.3 var(--font-sans); text-decoration: none; cursor: pointer; text-align: left;
        }
        .app-menu-panel a:hover, .app-menu-panel button:hover { background: var(--bg-muted); color: var(--primary); }
        .app-menu-panel a::after { content: '↗'; margin-left: auto; color: var(--text-sub); font-size: 0.8rem; }
        .app-menu-panel [style*="display: none"], .app-menu-panel [style*="display:none"] { display: none !important; }
        .app-menu-panel .is-danger { color: var(--danger-color); }
        .app-intro { margin: 0 0 18px; }
        .app-intro h1 { font-size: clamp(1.35rem, 2vw, 1.7rem); margin: 0 0 4px; }
        .app-intro p { margin: 0; font-size: 0.95rem; }
        @media (max-width: 900px) {
            .app-bar { grid-template-columns: 1fr auto; margin: -18px -16px 18px; padding: 12px 16px; border-radius: 10px 10px 0 0; }
            .app-project { grid-column: 1 / -1; order: 3; justify-content: stretch; }
            .app-project .app-project-name { max-width: none; flex: 1 1 auto; }
            .app-project .app-project-job { flex: 0 0 38%; }
            .app-brand-text span { display: none; }
        }
        @media (max-width: 560px) {
            .app-brand-text { display: none; }
            .app-menu > summary { padding: 6px 10px; }
        }
        .header-brand {
            display: flex;
            align-items: center;
            gap: 12px;
            margin-bottom: 10px;
        }
        .header-mark {
            background: var(--primary);
            color: #fff;
            width: 34px;
            height: 34px;
            display: inline-flex;
            align-items: center;
            justify-content: center;
            border-radius: 8px;
            font-weight: 700;
            font-size: 1.05rem;
            flex-shrink: 0;
        }
        .header-eyebrow {
            font-weight: 600;
            color: var(--primary);
            font-size: 0.78rem;
            text-transform: uppercase;
            letter-spacing: 0.12em;
        }
        .header h1 {
            font-size: clamp(1.45rem, 2.2vw, 1.85rem);
            color: var(--text-main);
            margin: 0 0 8px;
            max-width: 18ch;
        }
        .header-lead {
            font-size: 0.98rem;
            max-width: 42rem;
            margin: 0;
            color: var(--text-sub);
        }
        .header-actions {
            display: flex;
            flex-wrap: wrap;
            justify-content: flex-end;
            align-items: center;
            gap: 8px;
            flex-shrink: 0;
            max-width: 420px;
        }

        /* --- Components: Buttons --- */
        .btn {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            padding: 10px 18px;
            font-weight: 600;
            text-align: center;
            border-radius: var(--radius-sm);
            cursor: pointer;
            border: 1px solid transparent;
            font-size: 0.92rem;
            font-family: inherit;
            transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
            background: var(--primary);
            color: white;
            box-shadow: var(--shadow-xs);
            text-decoration: none;
            gap: 8px;
        }
        .btn:hover {
            background: var(--primary-hover);
            box-shadow: var(--shadow-sm);
        }
        .btn:active { box-shadow: none; }
        .btn:focus-visible {
            outline: none;
            box-shadow: var(--focus-ring);
        }

        .btn-outline {
            background: white;
            border: 1px solid var(--border-color);
            color: var(--text-main);
            box-shadow: none;
        }
        .btn-outline:hover {
            background: var(--bg-muted);
            border-color: var(--border-hover);
            color: var(--text-main);
        }

        .btn-link {
            display: inline-flex;
            align-items: center;
            gap: 6px;
            color: var(--primary);
            font-weight: 600;
            background: transparent;
            padding: 8px 12px;
            border-radius: var(--radius-sm);
            box-shadow: none;
            border: none;
        }
        .btn-link:hover { background: var(--primary-light); text-decoration: none; }

        .btn-auto { width: auto; min-width: 120px; }
        .btn-sm {
            padding: 6px 12px;
            font-size: 0.82rem;
        }
        .btn:disabled,
        .page-nav-btn:disabled {
            opacity: 0.45;
            cursor: not-allowed;
            transform: none;
            box-shadow: none;
        }

        /* --- Components: Forms --- */
        .form-group { margin-bottom: 16px; }
        .form-group label {
            display: block;
            margin-bottom: 6px;
            font-weight: 600;
            font-size: 0.86rem;
            color: #334155;
        }
        .form-group input, .form-group select, .toolbar-search {
          width: 100%;
          padding: 10px 12px;
          border: 1px solid var(--border-color);
          border-radius: var(--radius-sm);
          font-size: 0.95rem;
          font-family: inherit;
          background: #fff;
          transition: border-color 0.15s, box-shadow 0.15s;
          color: var(--text-main);
        }
        .form-group input:focus, .form-group select:focus, .toolbar-search:focus {
          outline: none;
          border-color: var(--primary);
          box-shadow: var(--focus-ring);
        }
        .input-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
            gap: 16px;
            margin-bottom: 20px;
        }
        .form-row-3 {
            display: grid;
            grid-template-columns: repeat(3, minmax(0, 1fr));
            gap: 16px;
        }
        .input-grid.two-col {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }
        .readonly { background: var(--bg-muted); color: var(--text-sub); pointer-events: none; border-color: #e2e8f0; }
        .formula-note {
          margin-top: 6px;
          font-size: 0.82rem;
          color: #475569;
          font-family: 'Cambria Math', 'Times New Roman', serif;
          line-height: 1.35;
        }
        .res-formula {
          margin: -4px 0 12px 0;
          font-size: 0.82rem;
          color: #94a3b8;
          font-family: 'Cambria Math', 'Times New Roman', serif;
          text-align: right;
          line-height: 1.35;
        }

        /* --- Components: Cards & Panels --- */
        .card,
        .panel {
          background: white;
          border: 1px solid var(--border-color);
          padding: 22px;
          border-radius: var(--radius-md);
          box-shadow: var(--shadow-xs);
          margin-bottom: 20px;
        }
        .card > h3:first-child,
        .panel > h3:first-child {
          margin-top: 0;
        }
        .card-quiet {
          background: var(--bg-muted);
          border: 1px solid var(--border-color);
          box-shadow: none;
        }
        .filter-panel {
            background: var(--bg-muted);
            border: 1px solid var(--border-color);
            padding: 20px;
            border-radius: var(--radius-md);
            margin-bottom: 24px;
        }
        .filter-note { font-size: 0.85rem; color: var(--text-sub); margin-top: 12px; display: block; }
        .filter-grid {
          display: grid;
          grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
          gap: 12px;
          margin-top: 12px;
        }
        .filter-toolbar {
          display: flex;
          flex-wrap: wrap;
          gap: 10px;
          align-items: center;
          margin: 14px 0;
        }

        /* --- Stage Progress Indicator --- */
        .stage-indicator {
            display: flex;
            align-items: center;
            gap: 8px;
            margin-bottom: 24px;
            padding: 14px 18px;
            background: var(--bg-muted);
            border-radius: var(--radius-md);
            border: 1px solid var(--border-color);
        }
        .stage-badge {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 30px;
            height: 30px;
            background: var(--primary);
            color: white;
            border-radius: 50%;
            font-weight: 700;
            font-size: 0.85rem;
        }
        .stage-title {
            font-size: 1.05rem;
            font-weight: 700;
            color: var(--text-main);
        }

        .made-by-badge { display: none !important; }

        .app-footer {
          margin-top: auto;
          padding-top: 16px;
          padding-bottom: 4px;
          border-top: 1px solid var(--border-color);
          text-align: center;
          color: #94a3b8;
          font-size: 0.9rem;
          letter-spacing: 0.01em;
        }

        /* --- Filter Buttons --- */
        .filter-select {
          width: 100%;
          padding: 10px 12px;
          border: 1px solid var(--border-color);
          border-radius: var(--radius-sm);
          background: #fff;
          font-family: inherit;
          font-size: 0.92rem;
          color: var(--text-main);
        }
        .filter-select:focus {
          outline: none;
          border-color: var(--primary);
          box-shadow: var(--focus-ring);
        }
        .filter-group {
          margin-top: 20px;
          padding-top: 16px;
          border-top: 1px solid var(--border-color);
        }
        .filter-group .form-group { margin-bottom: 0; }
        .filter-group-title { font-size: 0.78rem; font-weight: 700; color: #475569; margin-bottom: 10px; text-transform: uppercase; letter-spacing: 0.08em; }
        details.filter-group > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; margin-bottom: 0; }
        details.filter-group > summary::-webkit-details-marker { display: none; }
        details.filter-group > summary::before { content: '▸'; font-size: 0.9rem; transition: transform .15s; }
        details.filter-group[open] > summary::before { transform: rotate(90deg); }
        details.filter-group[open] > summary { margin-bottom: 10px; }
        .filter-count { background: var(--primary); color: #fff; border-radius: 999px; padding: 1px 8px; font-size: 0.72rem; letter-spacing: 0; text-transform: none; }
        /* Variant chips on grouped catalogue cards */
        .variant-row { margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border-color); cursor: default; }
        .variant-label { display: block; font-size: 0.75rem; color: #64748b; margin-bottom: 6px; }
        .variant-chips { display: flex; flex-wrap: wrap; gap: 6px; }
        .variant-chip { border: 1px solid var(--border-color); background: #fff; color: var(--text-main); border-radius: 999px; padding: 4px 10px; font: 600 0.75rem/1.3 inherit; font-family: inherit; cursor: pointer; text-align: left; }
        .variant-chip:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); }
        .filter-buttons { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
        .filter-btn {
            padding: 8px 14px;
            border: 1px solid var(--border-color);
            background: white;
            border-radius: 999px;
            font-size: 0.85rem;
            cursor: pointer;
            transition: border-color 0.15s, background 0.15s, color 0.15s;
            color: #334155;
            font-weight: 500;
            font-family: inherit;
        }
        .filter-btn:hover {
            border-color: var(--primary);
            background: var(--primary-light);
            color: var(--primary);
        }
        .filter-btn.active {
            background: var(--primary);
            color: white;
            border-color: var(--primary);
        }

        /* --- Barrier Grid & Card Improvements --- */
        .barrier-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 18px;
            margin-top: 24px;
        }
        .barrier-card {
            background: white;
            border: 1px solid var(--border-color);
            border-radius: var(--radius-md);
            padding: 18px;
            cursor: pointer;
            transition: border-color 0.15s ease, box-shadow 0.15s ease;
            position: relative;
            display: flex;
            flex-direction: column;
            overflow: hidden;
        }
        .barrier-card::before {
            content: '';
            position: absolute;
            top: 0; left: 0; right: 0; height: 3px;
            background: transparent;
            transition: background 0.15s;
        }
        .barrier-card:hover {
            border-color: var(--primary);
            box-shadow: var(--shadow-md);
        }
        .barrier-card:hover::before { background: var(--primary); }

        .barrier-card.selected {
            border: 2px solid var(--primary);
            background-color: #f7fbfa;
            box-shadow: 0 0 0 3px rgba(31, 111, 191, 0.15);
        }

        .barrier-title {
            font-weight: 700;
            font-size: 1.08rem;
            line-height: 1.3;
            margin-bottom: 4px;
            color: var(--text-main);
        }
        .barrier-supplier { font-size: 0.88rem; color: var(--text-sub); margin-bottom: 14px; font-weight: 500; }

        .stat-group,
        .barrier-stats {
            background: var(--bg-muted);
            border-radius: var(--radius-sm);
            padding: 12px;
            margin-top: auto;
            border: 1px solid var(--border-color);
        }
        .barrier-header {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            gap: 8px;
            margin-bottom: 8px;
        }
        .stat-box { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 4px; align-items: center; }
        .stat-box:last-child { margin-bottom: 0; }
        .stat-label { color: var(--text-sub); font-weight: 500; }
        .stat-val { font-weight: 700; color: #334155; }

        /* Actions Overlay on Card */
        .card-actions {
            display: flex;
            justify-content: space-between;
            align-items: flex-start;
            margin-bottom: 12px;
        }
        .fav-btn {
            cursor: pointer; 
            font-size: 1.4rem; 
            line-height: 1; 
            color: #cbd5e1; 
            transition: all 0.2s;
            padding: 4px;
            border-radius: 50%;
        }
        .fav-btn:hover { background: #fff7ed; color: #fcc419; }
        .fav-btn.active { color: #f59e0b; text-shadow: 0 2px 4px rgba(245, 158, 11, 0.3); }

        .compare-checkbox {
            display: flex;
            align-items: center;
            gap: 6px;
            font-size: 0.8rem;
            color: var(--text-sub);
            font-weight: 600;
            padding: 4px 8px;
            border-radius: 20px;
            background: #f1f5f9;
            transition: all 0.2s;
        }
        .compare-checkbox:hover { background: #e2e8f0; }
        .compare-checkbox input { accent-color: var(--primary); width: 16px; height: 16px; cursor: pointer; }

        /* Quick picks */
        .quick-picks { background:#f8fafc; border:1px solid #e2e8f0; border-radius:10px; padding:10px 12px; margin-bottom:12px; display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
        .quick-heading { font-weight:700; color:#0f172a; font-size:0.9rem; margin-right:6px; }
        .chip { display:inline-flex; align-items:center; gap:6px; padding:6px 10px; border-radius:999px; border:1px solid #cbd5e1; background:white; cursor:pointer; font-size:0.9rem; color:#0f172a; }
        .chip:hover { border-color:#94a3b8; background:#e2e8f0; }
        .chip-fav { border-color:#f59e0b; color:#b45309; }
        .chip-recent { border-color:#0ea5e9; color:#0c4a6e; }
        .delta-good { background:#dcfce7; color:#166534; font-weight:600; border-radius:6px; padding:2px 6px; font-size:0.85rem; }
        .delta-bad { background:#fee2e2; color:#b91c1c; font-weight:600; border-radius:6px; padding:2px 6px; font-size:0.85rem; }

        /* Filter inputs */
        .filter-mini { display:flex; gap:8px; flex-wrap:wrap; align-items:flex-end; }
        .filter-mini .form-group { flex:1; min-width:140px; }

        /* --- Badges --- */
        .badge { 
            display: inline-flex; 
            align-items: center;
            padding: 4px 12px; 
            border-radius: 999px; 
            font-size: 0.75rem; 
            font-weight: 800; 
            text-transform: uppercase;
            letter-spacing: 0.05em;
            box-shadow: 0 1px 2px rgba(0,0,0,0.05);
        }
        .badge-tl2 { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }
        .badge-tl3 { background: #fff7ed; color: #c2410c; border: 1px solid #fed7aa; }
        .badge-tl4 { background: #dcfce7; color: #15803d; border: 1px solid #bbf7d0; }
        .badge-tl5 { background: #f3e8ff; color: #7e22ce; border: 1px solid #e9d5ff; }

        /* --- Tabs --- */
        .stage1-tabs, .tab-nav { display: flex; gap: 4px; margin-bottom: 24px; border-bottom: 1px solid var(--border-color); }
        .tab-btn { 
            background: transparent; 
            border: none; 
            padding: 12px 20px; 
            font-weight: 600; 
            color: var(--text-sub); 
            cursor: pointer; 
            border-bottom: 2px solid transparent; 
            font-size: 0.95rem;
            transition: color 0.2s;
        }
        .tab-btn:hover { color: var(--primary); }
        .tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

        /* --- Calculation Panel --- */
        .calc-container { display: none; grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); gap: 24px; align-items: start; }
        .calc-container.active { display: grid; }

        /* Stage 3 desktop balance: keep inputs visible while refining calculations */
        #stage3 #inputsPanel {
          position: sticky;
          top: 84px;
          max-height: calc(100vh - 120px);
          overflow: auto;
        }
        #stage3 #resultsPanel {
          min-width: 0;
        }
        
        .section-title { 
            font-weight: 700; 
            color: #334155; 
            margin: 24px 0 16px 0; 
            font-size: 0.8rem; 
            text-transform: uppercase; 
            letter-spacing: 0.05em; 
            border-bottom: 1px solid #e2e8f0; 
            padding-bottom: 8px; 
        }

        /* --- Results Card --- */
        .results-card {
            background: var(--navy);
            color: white;
            padding: 28px 32px;
            border-radius: var(--radius-md);
            margin-bottom: 32px;
            box-shadow: var(--shadow-md);
            border: 1px solid var(--navy-2);
        }
        .results-header { 
            display: flex; 
            justify-content: space-between; 
            align-items: center; 
          flex-wrap: wrap;
          gap: 10px;
            margin-bottom: 24px; 
            border-bottom: 1px solid rgba(255,255,255,0.1); 
            padding-bottom: 16px; 
        }
        .results-header h4 { margin: 0; color: #e2e8f0; font-weight: 600; font-size: 1.25rem; }
        
        .res-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 12px; font-size: 1.1rem; }
        .res-label { color: #c9d6e6; font-size: 0.95rem; font-weight: 500; }
        .res-val { font-weight: 700; font-family: var(--font-sans); font-variant-numeric: tabular-nums; font-size: 1.3rem; color: #ffffff; }
        .res-sub { font-size: 0.8rem; color: #9fb3c8; text-align: right; }

        .design-speed-input { 
            display: flex; 
            align-items: center; 
            gap: 12px; 
            padding: 8px 12px; 
            background: rgba(255,255,255,0.1); 
            border-radius: 6px; 
            border: 1px solid rgba(255,255,255,0.2); 
        }
        .design-speed-input input { 
            width: 80px; 
            padding: 6px; 
            border-radius: 4px; 
            border: none; 
            background: #fff; 
            color: #0f172a; 
            text-align: center; 
            font-weight: 700; 
        }
        .design-speed-input label { color: #e2e8f0; font-size: 0.9rem; font-weight: 500; }
        .results-controls {
          display: flex;
          align-items: flex-start;
          gap: 10px;
          flex-wrap: wrap;
          justify-content: flex-end;
        }
        .design-input-block {
          display: flex;
          flex-direction: column;
          gap: 6px;
        }
        .design-input-label-row {
          display: flex;
          align-items: center;
          gap: 8px;
          color: #e2e8f0;
          font-size: 0.9rem;
          font-weight: 500;
        }
        .design-input-label-row label {
          margin: 0;
          color: inherit;
          font-size: inherit;
          font-weight: inherit;
        }
        .curve-panel {
          margin: 0 0 18px;
          padding: 14px;
          border: 1px solid rgba(255,255,255,0.2);
          border-radius: 8px;
          background: rgba(255,255,255,0.06);
        }
        .curve-panel .section-title {
          color: #e2e8f0;
          border-bottom-color: rgba(255,255,255,0.15);
          margin-top: 0;
        }
        .curve-panel .form-group label,
        .curve-panel .formula-note { color: #e2e8f0; }
        .curve-panel .form-group { margin-bottom: 10px; }
        .curve-grid {
          display: grid;
          grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
          gap: 10px;
        }
        .inline-help {
          position: relative;
        }
        .inline-help summary {
          list-style: none;
          width: 18px;
          height: 18px;
          border-radius: 50%;
          border: 1px solid rgba(255,255,255,0.55);
          color: #e2e8f0;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          font-weight: 700;
          line-height: 1;
          user-select: none;
        }
        .inline-help summary::-webkit-details-marker { display: none; }
        .inline-help-note {
          position: absolute;
          top: calc(100% + 6px);
          right: 0;
          min-width: 220px;
          max-width: 280px;
          background: #ffffff;
          color: #0f172a;
          border: 1px solid #cbd5e1;
          border-radius: 8px;
          padding: 8px 10px;
          font-size: 0.8rem;
          font-weight: 600;
          box-shadow: var(--shadow-sm);
          z-index: 5;
        }
        .calc-field-legend {
          width: 100%;
          display: flex;
          justify-content: flex-end;
          flex-wrap: wrap;
          gap: 8px;
          margin-top: 4px;
        }
        .calc-legend-chip {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          padding: 4px 8px;
          border-radius: 999px;
          font-size: 0.75rem;
          font-weight: 700;
          border: 1px solid transparent;
          white-space: nowrap;
        }
        .calc-legend-chip.red {
          background: #fffbeb;
          border-color: #fcd34d;
          color: #92400e;
        }
        .calc-legend-chip.green {
          background: #f0fdf4;
          border-color: #86efac;
          color: #166534;
        }
        .calc-legend-chip.blue {
          background: #eff6ff;
          border-color: #93c5fd;
          color: #1d4ed8;
        }
        /* Fields the user must confirm: amber, so red is reserved for real problems. */
        .state-required {
          background: #fffbeb !important;
          border-color: #fcd34d !important;
          box-shadow: inset 3px 0 0 #f59e0b;
          color: #1f2937 !important;
          font-weight: 700;
        }
        .state-required:invalid,
        .state-required.is-invalid {
          background: #fff1f2 !important;
          border-color: #f87171 !important;
          box-shadow: inset 3px 0 0 #dc2626;
          color: #9f1239 !important;
        }
        .state-auto-fixed {
          background: #f0fdf4 !important;
          border-color: #86efac !important;
          color: #166534 !important;
          font-weight: 700;
        }
        .state-auto-editable {
          background: #eff6ff !important;
          border-color: #93c5fd !important;
          color: #1d4ed8 !important;
          font-weight: 700;
        }

        /* --- Matrix Tables --- */
        .matrix-table { width: 100%; table-layout: fixed; border-collapse: separate; border-spacing: 0; font-size: 0.85rem; margin-bottom: 24px; border: 1px solid var(--border-color); border-radius: var(--radius-sm); overflow: hidden; }
        .matrix-table th { 
            text-align: left; 
            padding: 10px 8px; 
            background: #f1f5f9; 
            border-bottom: 1px solid var(--border-color); 
            color: #475569; 
            font-weight: 600;
            white-space: normal;
            word-break: break-word;
        }
        .matrix-table td { 
            padding: 8px; 
            border-bottom: 1px solid var(--border-color); 
            color: #334155;
            white-space: normal;
            word-break: break-word;
        }
        .matrix-table .matrix-formula-row th {
          padding: 6px 8px;
          background: #f8fafc;
          color: #64748b;
          font-size: 0.72rem;
          font-weight: 500;
          border-bottom: 1px solid #e2e8f0;
          line-height: 1.3;
          white-space: normal;
          word-break: break-word;
        }
        .matrix-table .matrix-formula-row th:first-child {
          color: #475569;
          font-weight: 600;
        }
        .matrix-table tr:last-child td { border-bottom: none; }
        .row-highlight { background-color: #eff6ff !important; font-weight: 700; color: #1e40af !important; box-shadow: inset 3px 0 0 var(--primary); }
        .val-pass { color: var(--success-color); }
        .val-fail { color: var(--danger-color); font-weight: 700; }
        .row-fail { background: #fff1f2; }
        .matrix-grid-wrapper {
          width: 100%;
          overflow-x: hidden;
        }
        .matrix-scroll-wrap {
          width: 100%;
          overflow: hidden;
          padding-bottom: 0;
        }

        .calc-method {
          margin: 10px 24px 18px 24px;
          padding: 14px 16px;
          border: 1px solid #dbeafe;
          border-radius: 10px;
          background: #f8fbff;
          color: #334155;
        }
        .calc-method h4 {
          margin: 0 0 10px 0;
          color: #1e3a8a;
          font-size: 1rem;
          font-weight: 700;
        }
        .calc-method-steps {
          display: grid;
          gap: 8px;
          font-size: 0.9rem;
          line-height: 1.5;
        }
        .calc-method-formula {
          margin-top: 4px;
          font-family: 'Cambria Math', 'Times New Roman', serif;
          color: #0f172a;
          font-size: 0.92rem;
        }
        
        .angle-block { margin-bottom: 32px; background: white; border-radius: var(--radius-md); }
        .angle-header { 
            background: #e2e8f0; 
            padding: 10px 16px; 
            font-weight: 700; 
            border-radius: var(--radius-sm) var(--radius-sm) 0 0; 
            color: #334155;
            font-size: 0.95rem;
        }

        /* --- Login Overlay --- */
        body.app-locked {
          overflow: hidden;
        }
        /* CTMP hand-off is only meaningful once signed in. */
        body.app-locked #ctmpSendBtn,
        body.app-locked .ctmp-context-bar {
          display: none !important;
        }
        #loginContainer {
          display: flex;
          align-items: center;
          justify-content: center;
          min-height: 100vh;
          position: fixed;
          inset: 0;
          z-index: 9999;
          padding: 24px;
          background:
            repeating-linear-gradient(115deg, transparent 0 46px, rgba(255, 255, 255, 0.035) 46px 48px),
            linear-gradient(160deg, #16294a 0%, #0f1e33 60%);
          box-sizing: border-box;
        }
        .login-shell {
          width: min(430px, 95vw);
          background: #ffffff;
          border-radius: 20px;
          box-shadow: 0 32px 64px -12px rgba(0, 0, 0, 0.28);
          padding: 36px 32px 32px;
        }
        .login-logo {
          width: min(220px, 60vw);
          display: block;
          margin: 0 auto 20px;
          object-fit: contain;
        }
        .login-title {
          font-size: 1.35rem;
          font-weight: 700;
          color: var(--text-main);
          margin: 0 0 10px;
          text-align: center;
          padding-bottom: 12px;
          border-bottom: 2px solid var(--primary);
        }
        .login-note {
          margin: 12px 0 20px;
          text-align: center;
          color: #475569;
          font-size: 0.92rem;
          line-height: 1.5;
        }
        .login-field-label {
          display: block;
          font-size: 0.72rem;
          font-weight: 700;
          letter-spacing: 0.1em;
          text-transform: uppercase;
          color: #374151;
          margin-bottom: 6px;
        }
        .login-field {
          margin-bottom: 14px;
        }
        .login-input {
          width: 100%;
          padding: 11px 14px;
          border: 1.5px solid #e2e8f0;
          border-radius: 8px;
          font-size: 0.97rem;
          transition: border-color 0.2s ease, box-shadow 0.2s ease;
          background: #f1f5f9;
          box-sizing: border-box;
          color: #0f172a;
        }
        .login-input:focus {
          outline: none;
          border-color: var(--primary);
          background: #ffffff;
          box-shadow: var(--focus-ring);
        }
        .login-btn {
          width: 100%;
          padding: 13px;
          background: var(--primary);
          color: #ffffff;
          border: none;
          border-radius: 8px;
          font-size: 1rem;
          font-weight: 600;
          cursor: pointer;
          margin-top: 4px;
          transition: background 0.2s ease;
          letter-spacing: 0.01em;
          font-family: inherit;
        }
        .login-btn:hover {
          background: var(--primary-hover);
        }
        .login-error {
          margin-top: 10px;
          color: #b91c1c;
          font-size: 0.88rem;
          min-height: 1.2em;
          text-align: center;
        }
        .login-success {
          margin-top: 10px;
          color: var(--primary);
          font-size: 0.88rem;
          min-height: 1.2em;
          text-align: center;
        }
        .login-tabs {
          display: grid;
          grid-template-columns: 1fr 1fr;
          gap: 6px;
          margin: 0 0 18px;
          padding: 4px;
          background: #f1f5f9;
          border-radius: 10px;
        }
        .login-tab {
          border: none;
          background: transparent;
          color: #475569;
          font-size: 0.92rem;
          font-weight: 600;
          padding: 10px 8px;
          border-radius: 8px;
          cursor: pointer;
        }
        .login-tab.is-active {
          background: #ffffff;
          color: var(--primary);
          box-shadow: 0 1px 3px rgba(15, 23, 42, 0.12);
        }
        .login-btn:disabled {
          opacity: 0.65;
          cursor: wait;
        }
        .login-switch {
          margin-top: 14px;
          text-align: center;
          color: #64748b;
          font-size: 0.88rem;
        }
        .login-switch button {
          border: none;
          background: none;
          color: var(--primary);
          font-weight: 700;
          cursor: pointer;
          padding: 0;
          text-decoration: underline;
          text-underline-offset: 2px;
          font-family: inherit;
        }
        .login-confirm-field[hidden] {
          display: none !important;
        }

        /* --- Misc / Utilities --- */
        .image-preview { 
            display: flex; 
            flex-direction: column; 
            align-items: center; 
            padding: 24px; 
            background: #f8fafc; 
            border: 2px dashed #cbd5e1; 
            border-radius: var(--radius-md); 
            text-decoration: none; 
            color: inherit; 
            margin-bottom: 24px; 
            transition: all 0.2s; 
        }
        .image-preview:hover { border-color: var(--primary); background: #eff6ff; }
        .image-icon { font-size: 32px; margin-bottom: 8px; }
        .thumb-placeholder {
          width: 72px;
          height: 72px;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          border-radius: 6px;
          background: linear-gradient(135deg, #e2e8f0, #f8fafc);
          color: #64748b;
          font-weight: 700;
          font-size: 0.75rem;
          border: 1px dashed #cbd5e1;
          text-transform: uppercase;
          letter-spacing: 0.05em;
          flex-shrink: 0;
        }
        .info-banner {
          background: #f8fafc;
          border: 1px solid #e2e8f0;
          border-radius: 12px;
          padding: 12px 14px;
          margin: 8px 0 16px 0;
          display: flex;
          flex-direction: column;
          gap: 8px;
        }
        .legend-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
        .status-pill {
          display: inline-flex;
          align-items: center;
          gap: 6px;
          padding: 6px 10px;
          border-radius: 999px;
          font-size: 0.85rem;
          border: 1px solid #cbd5e1;
          background: white;
          color: #0f172a;
          font-weight: 600;
        }
        .status-pill.ok { border-color: #bbf7d0; background: #ecfdf3; color: #166534; }
        .status-pill.warn { border-color: #fecdd3; background: #fff1f2; color: #b91c1c; }
        .status-pill.note { border-color: #e2e8f0; background: #f8fafc; color: #334155; }
        .status-pill.highlight { border-color: #bfdbfe; background: #eff6ff; color: #1d4ed8; }
        .link-health { margin-top: 8px; color: #b91c1c; font-size: 0.9rem; display:none; }
        .link-health.ok { color: #18865a; }

        /* Width visualizer */
        .width-visual { margin-top:20px; padding:14px; border:1px solid #e2e8f0; border-radius:12px; background:#f8fafc; box-shadow:var(--shadow-xs); }
        .width-row { display:flex; align-items:center; gap:12px; margin-bottom:10px; flex-wrap:wrap; }
        .width-label { min-width:150px; font-weight:700; color:#0f172a; }
        .width-bar-shell { flex:1; min-width:180px; height:16px; background:#e2e8f0; border-radius:999px; overflow:hidden; position:relative; }
        .width-bar { height:100%; border-radius:999px; background: linear-gradient(90deg, #2563eb, #60a5fa); }
        .width-val { font-weight:700; color:#334155; min-width:80px; text-align:right; }
        .width-legend { display:flex; gap:10px; flex-wrap:wrap; font-size:0.9rem; color:#475569; margin-top:8px; }
        .width-pill { padding:6px 10px; border-radius:999px; border:1px solid #cbd5e1; background:white; font-weight:600; }
        .width-pill.ok { border-color:#bbf7d0; background:#ecfdf3; color:#166534; }
        .width-pill.warn { border-color:#fecdd3; background:#fff1f2; color:#b91c1c; }
        .width-dim-row { display:flex; align-items:center; gap:12px; margin-bottom:14px; flex-wrap:wrap; }
        .width-dim-track { position:relative; flex:1; min-width:220px; height:32px; }
        .width-dim-base { position:absolute; left:0; right:0; top:50%; height:6px; background:#e2e8f0; border-radius:999px; transform:translateY(-50%); }
        .width-dim-bar { position:absolute; left:0; top:50%; height:20px; transform:translateY(-50%); border-radius:999px; display:flex; align-items:center; justify-content:center; color:#0f172a; font-weight:700; font-size:0.85rem; padding:0 10px; overflow:hidden; box-shadow:0 2px 6px rgba(15,23,42,0.08); min-width:56px; }
        .width-dim-placeholder { background:#e2e8f0 !important; color:#94a3b8; border:1px dashed #cbd5e1; opacity:0.85; }
        .width-dim-mark { position:absolute; width:2px; height:18px; background:rgba(15,23,42,0.65); top:50%; transform:translateY(-50%); }
        .width-dim-mark.left { left:6px; }
        .width-dim-mark.right { right:6px; }
        .width-dim-text { position:relative; z-index:1; color:#0b1220; text-shadow:0 1px 2px rgba(255,255,255,0.7); white-space:nowrap; }
        .width-dim-text.muted { color:#94a3b8; text-shadow:none; }
        .width-dim-arrow { position:absolute; top:50%; width:0; height:0; border-top:8px solid transparent; border-bottom:8px solid transparent; transform:translateY(-50%); }
        .width-dim-arrow.start { left:-4px; border-right:10px solid #94a3b8; }
        .width-dim-arrow.end { right:-4px; border-left:10px solid #94a3b8; }
        .width-sketch { margin-top:16px; padding:14px; border:1px solid #e2e8f0; border-radius:12px; background:#fff; box-shadow:var(--shadow-xs); }
        .width-sketch-header { display:flex; justify-content:space-between; align-items:center; gap:12px; margin-bottom:8px; }
        .width-sketch-title { font-weight:700; color:#0f172a; }
        .width-sketch svg { width:100%; height:auto; display:block; }
        .width-sketch-note { color:#475569; font-size:0.9rem; margin-top:6px; }

        /* Tech sheet preview */
        .tech-preview { border:1px solid var(--border-color); border-radius:12px; background:#fff; box-shadow:var(--shadow-sm); margin-bottom:20px; overflow:hidden; }
        .tech-preview-header { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 14px; background:#f8fafc; border-bottom:1px solid var(--border-color); }
        .tech-preview-title { font-weight:700; color:#0f172a; }
        .tech-preview-note { font-size:0.9rem; color:#475569; margin:0; }
        .tech-preview-frame { width:100%; height:360px; border:0; background:#0f172a10; }
        .tech-preview-empty { padding:14px; color:#475569; font-size:0.95rem; }
        
        .scenario-toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; padding: 16px; background: #f1f5f9; border-radius: var(--radius-md); }
        .scenario-card { background: white; border: 1px solid var(--border-color); border-radius: var(--radius-md); padding: 16px; margin-bottom: 16px; box-shadow: var(--shadow-sm); }
        
        /* --- Signatures --- */
        .signature-section { border-top: 1px solid var(--border-color); padding-top: 32px; margin-top: 32px; }
        .sig-row { display: grid; grid-template-columns: 1fr 1fr; gap: 40px; margin-bottom: 24px; }
        .sig-label { display: block; font-weight: 600; color: #64748b; font-size: 0.85rem; margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.05em; }
        .sig-input { font-family: 'Mrs Saint Delafield', cursive, sans-serif; font-size: 1.5rem; border-bottom: 1px solid #94a3b8; padding: 4px 0; color: #000; min-height: 40px; }

        /* --- Page Navigation --- */
        .page-nav {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 10px;
          margin: 12px 0 20px 0;
          padding: 10px 12px;
          border: 1px solid var(--border-color);
          border-radius: var(--radius-md);
          background: var(--bg-muted);
        }
        .page-nav.bottom {
          margin-top: 24px;
          margin-bottom: 8px;
        }
        .page-nav-title {
          font-size: 0.9rem;
          font-weight: 600;
          color: #334155;
          text-align: center;
          flex: 1;
          min-width: 0;
        }
        .page-nav-btn {
          padding: 9px 14px;
          font-size: 0.88rem;
          font-weight: 600;
          border-radius: var(--radius-sm);
          border: 1px solid var(--border-color);
          background: white;
          color: var(--text-main);
          cursor: pointer;
          font-family: inherit;
          white-space: nowrap;
        }
        .page-nav-btn:not(:disabled):hover {
          border-color: var(--primary);
          color: var(--primary);
          background: var(--primary-light);
        }
        .page-nav-btn:disabled {
          opacity: 0.4;
          cursor: not-allowed;
        }
        .page-nav-btn.is-hidden {
          visibility: hidden;
          pointer-events: none;
        }

        /* --- Step bar (top navigation) --- */
        .sr-only {
          position: absolute !important;
          width: 1px; height: 1px; padding: 0; margin: -1px;
          overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
        }
        .step-bar {
          list-style: none;
          display: flex;
          flex: 1;
          min-width: 0;
          margin: 0;
          padding: 0;
          gap: 4px;
          justify-content: center;
        }
        .step-bar li { flex: 1 1 0; min-width: 0; max-width: 220px; }
        .step-bar button {
          display: flex;
          align-items: center;
          gap: 8px;
          width: 100%;
          padding: 6px 10px;
          border: 1px solid transparent;
          border-radius: var(--radius-sm);
          background: transparent;
          font: 600 0.85rem/1.2 inherit;
          font-family: inherit;
          color: #475569;
          cursor: pointer;
          text-align: left;
        }
        .step-bar button:not(:disabled):hover { background: white; border-color: var(--border-color); }
        .step-bar button:disabled { cursor: not-allowed; color: #94a3b8; }
        .step-bar .step-num {
          flex: 0 0 auto;
          display: inline-flex;
          align-items: center;
          justify-content: center;
          width: 24px; height: 24px;
          border-radius: 999px;
          border: 1.5px solid #cbd5e1;
          background: white;
          font-size: 0.78rem;
          font-weight: 700;
        }
        .step-bar .step-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
        .step-bar li.is-done .step-num { background: var(--primary); border-color: var(--primary); color: white; }
        .step-bar li.is-current button { background: white; border-color: var(--primary); color: var(--primary); }
        .step-bar li.is-current .step-num { border-color: var(--primary); color: var(--primary); }
        @media (max-width: 760px) {
          #pageNavTop { flex-wrap: wrap; }
          #pageNavTop .step-bar { order: -1; flex: 1 1 100%; }
          #pageNavTop .page-nav-btn { flex: 1 1 0; }
          .step-bar .step-text { display: none; }
          .step-bar li.is-current .step-text { display: inline; }
          .step-bar li { flex: 0 0 auto; max-width: none; }
          .step-bar li.is-current { flex: 1 1 auto; }
          #resultsSummaryBar.results-summary-bar {
            position: static;
            display: grid;
            grid-template-columns: 1fr 1fr;
          }
          #resultsSummaryBar[hidden] { display: none; }
          #resultsSummaryBar .rsb-product, #resultsSummaryBar .rsb-status { grid-column: 1 / -1; }
          #resultsSummaryBar .rsb-status { margin-left: 0; }
        }
        body.is-external .step-bar { visibility: hidden; }

        /* --- Fold-out panels --- */
        .panel-fold { margin: 0 0 12px; }
        .panel-fold > summary {
          cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px;
          padding: 10px 14px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
          background: var(--bg-muted); font-weight: 600; color: var(--text-main);
        }
        .panel-fold > summary::-webkit-details-marker { display: none; }
        .panel-fold > summary::before { content: '▸'; color: var(--primary); transition: transform .15s; }
        .panel-fold[open] > summary::before { transform: rotate(90deg); }
        .panel-fold[open] > summary { margin-bottom: 12px; background: #fff; }
        .panel-fold > summary:hover { border-color: var(--border-hover); }
        .panel-fold > summary small { display: block; font-weight: 400; font-size: 0.8rem; color: var(--text-sub); }
        .panel-fold-lg { margin: 0 24px 16px; }
        .panel-fold-lg > summary { padding: 14px 16px; font-size: 1.02rem; }
        details.calc-method { padding: 0; border: 0; background: none; }
        details.calc-method .calc-method-steps { padding: 14px 16px; border: 1px solid #dbeafe; border-radius: 10px; background: #f8fbff; color: #334155; }
        .scenario-toolbar { margin-left: 24px; margin-right: 24px; }

        /* --- Toasts --- */
        .toast-host {
          position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
          z-index: 100000; display: flex; flex-direction: column; gap: 8px;
          width: min(460px, calc(100vw - 32px)); pointer-events: none;
        }
        .toast {
          pointer-events: auto; cursor: pointer; white-space: pre-line;
          padding: 12px 16px 12px 14px; border-radius: 8px; font-size: 0.9rem; line-height: 1.4;
          background: #0f1e33; color: #fff; box-shadow: 0 10px 28px rgba(15, 30, 51, 0.28);
          border-left: 4px solid #f59e0b; animation: toast-in .18s ease-out;
        }
        .toast-success { border-left-color: #18865a; }
        .toast-error { border-left-color: #dc2626; }
        .toast.is-leaving { opacity: 0; transform: translateY(6px); transition: opacity .2s, transform .2s; }
        @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

        /* --- Sticky results summary --- */
        .results-summary-bar {
          position: sticky;
          top: 0;
          z-index: 40;
          display: flex;
          flex-wrap: wrap;
          align-items: center;
          gap: 8px 22px;
          margin: -8px 0 18px;
          padding: 10px 16px;
          background: #0f1e33;
          color: #fff;
          border-radius: var(--radius-md);
          box-shadow: 0 6px 18px rgba(15, 30, 51, 0.18);
        }
        .results-summary-bar[hidden] { display: none; }
        .rsb-item { display: flex; flex-direction: column; min-width: 0; }
        .rsb-product { flex: 1 1 220px; }
        .rsb-label { font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: #9fb3c8; font-weight: 600; }
        .rsb-value { font-weight: 700; font-size: 0.98rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-variant-numeric: tabular-nums; }
        .rsb-value input {
          width: 72px; padding: 2px 6px; border-radius: 4px; border: 1px solid #3f8edb;
          background: #16294a; color: #fff; font: inherit; font-weight: 700;
        }
        .rsb-status { flex-direction: row; align-items: center; gap: 10px; margin-left: auto; }
        .rsb-pill { padding: 4px 12px; border-radius: 999px; font-size: 0.78rem; font-weight: 800; letter-spacing: 0.06em; text-transform: uppercase; background: #334155; color: #e2e8f0; }
        .rsb-pill.is-pass { background: #18865a; color: #fff; }
        .rsb-pill.is-fail { background: #b42335; color: #fff; }
        .rsb-pill.is-warn { background: #f59e0b; color: #1f2937; }
        .rsb-note { font-size: 0.8rem; color: #c9d6e6; }

        .role-mode-banner {
          display: none;
          margin: 0 0 16px 0;
          padding: 10px 14px;
          border-radius: var(--radius-sm);
          border: 1px solid #b6d4ce;
          background: var(--primary-light);
          color: var(--primary);
          font-weight: 600;
          font-size: 0.9rem;
        }

        .legacy-nav { display: none !important; }

        .tmr-banner {
          margin: 0 0 16px;
          padding: 12px 14px;
          border: 1px solid var(--border-color);
          border-radius: var(--radius-sm);
          background: #fff;
          font-size: 0.9rem;
          color: var(--text-sub);
        }
        .tmr-banner a {
          color: var(--primary);
          font-weight: 600;
        }
        .jurisdiction-bar {
          display: flex;
          flex-wrap: wrap;
          gap: 10px;
          align-items: flex-end;
          margin: 0 0 12px;
          padding: 12px;
          border: 1px solid #c9d7e5;
          background: linear-gradient(180deg, #f7fafc 0%, #eef3f8 100%);
        }
        .jurisdiction-bar .form-group {
          margin: 0;
          min-width: 220px;
          flex: 1;
        }
        .jurisdiction-bar label {
          display: block;
          font-size: 11px;
          letter-spacing: 0.08em;
          text-transform: uppercase;
          color: #5b6f84;
          font-weight: 700;
          margin-bottom: 6px;
        }
        .jurisdiction-check {
          display: flex;
          align-items: center;
          gap: 8px;
          font-size: 0.9rem;
          color: #334155;
          padding-bottom: 8px;
        }
        .jurisdiction-check input {
          width: 16px;
          height: 16px;
        }
        .jurisdiction-badges {
          display: flex;
          flex-wrap: wrap;
          gap: 4px;
          margin-top: 8px;
        }
        .jurisdiction-badge {
          display: inline-flex;
          align-items: center;
          padding: 2px 7px;
          font-size: 10px;
          font-weight: 800;
          letter-spacing: 0.06em;
          text-transform: uppercase;
          border: 1px solid #9db2c5;
          color: #123549;
          background: #fff;
        }
        .jurisdiction-badge.tcu {
          border-color: #d4a017;
          color: #7a4f00;
          background: #fff8eb;
        }

        /* --- Editable Report Modal --- */
        .report-modal {
          display: none;
          position: fixed;
          inset: 0;
          z-index: 11000;
          background: rgba(15, 23, 42, 0.55);
          backdrop-filter: blur(2px);
          padding: 18px;
        }
        .report-modal.show {
          display: flex;
          align-items: center;
          justify-content: center;
        }
        .report-modal-panel {
          width: min(1080px, 98vw);
          max-height: 94vh;
          background: #ffffff;
          border-radius: 12px;
          border: 1px solid #cbd5e1;
          box-shadow: var(--shadow-xl);
          display: flex;
          flex-direction: column;
          overflow: hidden;
        }
        .report-modal-toolbar {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 10px;
          padding: 12px 14px;
          border-bottom: 1px solid #e2e8f0;
          background: #f8fafc;
        }
        .report-modal-title {
          font-weight: 800;
          color: #0f172a;
        }
        .report-modal-actions {
          display: flex;
          flex-wrap: wrap;
          gap: 8px;
        }
        .report-edit-surface {
          padding: 14px;
          overflow: auto;
          max-height: calc(94vh - 72px);
          background: #f1f5f9;
        }
        .report-edit-content {
          background: #ffffff;
          border: 1px solid #c9d7e5;
          border-radius: 4px;
          padding: 18px 22px;
          min-height: 260px;
        }
        .report-edit-content:focus {
          outline: 3px solid rgba(31, 78, 111, 0.18);
          border-color: #2f6f97;
        }
        .report-edit-content .eng-report {
          max-width: 920px;
          margin: 0 auto;
        }

        @media print {
          .report-modal {
            display: none !important;
          }
        }

        /* --- Admin --- */
        .admin-only { display: none !important; }
        body.is-admin .admin-only { display: block !important; }
        body.is-admin .admin-only.btn { display: inline-flex !important; }

        #adminPortal {
          display: none;
          position: fixed;
          inset: 0;
          z-index: 10000;
          background: rgba(15, 23, 42, 0.55);
          backdrop-filter: blur(4px);
          padding: 24px;
          box-sizing: border-box;
          overflow: auto;
        }
        #adminPortal.is-open { display: flex; align-items: flex-start; justify-content: center; }
        .admin-shell {
          width: min(920px, 100%);
          margin: 24px auto;
          background: #fff;
          border-radius: 16px;
          box-shadow: 0 28px 60px -16px rgba(0,0,0,0.3);
          overflow: hidden;
        }
        .admin-header {
          display: flex;
          align-items: center;
          justify-content: space-between;
          gap: 12px;
          padding: 18px 22px;
          background: var(--primary);
          color: #fff;
        }
        .admin-header h2 {
          margin: 0;
          font-size: 1.2rem;
          font-weight: 700;
        }
        .admin-header p {
          margin: 4px 0 0;
          font-size: 0.85rem;
          opacity: 0.85;
        }
        .admin-close {
          border: 1px solid rgba(255,255,255,0.35);
          background: transparent;
          color: #fff;
          border-radius: 8px;
          padding: 8px 12px;
          cursor: pointer;
          font-weight: 600;
        }
        .admin-body { padding: 20px 22px 24px; }
        .admin-section { margin-bottom: 28px; }
        .admin-section h3 {
          margin: 0 0 6px;
          font-size: 1rem;
          color: #0f172a;
        }
        .admin-section > p {
          margin: 0 0 14px;
          color: #64748b;
          font-size: 0.9rem;
        }
        .admin-invite-form {
          display: grid;
          grid-template-columns: 1.4fr 0.8fr auto;
          gap: 10px;
          margin-bottom: 14px;
        }
        .admin-invite-form input,
        .admin-invite-form select,
        .admin-table select {
          width: 100%;
          padding: 10px 12px;
          border: 1.5px solid #e2e8f0;
          border-radius: 8px;
          background: #f8fafc;
          color: #0f172a;
          font-size: 0.92rem;
          box-sizing: border-box;
        }
        .admin-invite-form button,
        .admin-refresh-btn {
          border: none;
          background: var(--primary);
          color: #fff;
          border-radius: 8px;
          padding: 10px 14px;
          font-weight: 600;
          cursor: pointer;
          font-family: inherit;
        }
        .admin-refresh-btn {
          background: #e2e8f0;
          color: #0f172a;
          margin-bottom: 12px;
        }
        .admin-table-wrap { overflow-x: auto; border: 1px solid #e2e8f0; border-radius: 10px; }
        .admin-table {
          width: 100%;
          border-collapse: collapse;
          font-size: 0.9rem;
        }
        .admin-table th,
        .admin-table td {
          text-align: left;
          padding: 10px 12px;
          border-bottom: 1px solid #e2e8f0;
          vertical-align: middle;
        }
        .admin-table th {
          background: #f1f5f9;
          color: #334155;
          font-size: 0.75rem;
          letter-spacing: 0.06em;
          text-transform: uppercase;
        }
        .admin-table tr:last-child td { border-bottom: none; }
        .admin-badge {
          display: inline-block;
          padding: 3px 8px;
          border-radius: 999px;
          font-size: 0.75rem;
          font-weight: 700;
          background: #e2e8f0;
          color: #334155;
        }
        .admin-badge.is-admin { background: #dcfce7; color: #166534; }
        .admin-badge.is-external { background: #e0e7ff; color: #3730a3; }
        .admin-badge.is-disabled { background: #fee2e2; color: #991b1b; }
        .admin-actions { display: flex; gap: 8px; flex-wrap: wrap; }
        .admin-actions button {
          border: 1px solid #cbd5e1;
          background: #fff;
          border-radius: 6px;
          padding: 6px 10px;
          font-size: 0.8rem;
          cursor: pointer;
          font-weight: 600;
          color: #0f172a;
        }
        .admin-actions button.danger { color: #b91c1c; border-color: #fecaca; }
        .admin-status {
          min-height: 1.2em;
          margin-top: 8px;
          font-size: 0.88rem;
          color: var(--primary);
        }
        .admin-status.is-error { color: #b91c1c; }
        .admin-empty {
          padding: 16px;
          color: #64748b;
          text-align: center;
        }
        @media (max-width: 720px) {
          .admin-invite-form { grid-template-columns: 1fr; }
        }
        
        /* --- Planner User --- */
        body.is-planner .admin-only { display: none !important; }
        body.is-planner .planner-no-print { display: none !important; }
        
        /* --- External User (view only) --- */
        .internal-only { display: inline-flex; }
        body.is-external .internal-only { display: none !important; }
        body.is-external .app-project { visibility: hidden; }
        body.is-external #stage1,
        body.is-external #stage3,
        body.is-external #stage4,
        body.is-external #stage5,
        body.is-external #stage7 { display: none !important; }
        
        /* --- Print Styles --- */
        .print-only { display: none; }
        @media print {
            @page { size: A4; margin: 0; }
            body { background: white; padding: 0; print-color-adjust: exact; -webkit-print-color-adjust: exact; }
            .container { box-shadow: none; border: none; width: 100%; max-width: none; padding: 0; margin: 0; }
            .no-print, .header button, .filter-panel, .tab-nav, .scenario-toolbar { display: none !important; }
            
            .print-page { 
                padding: 15mm; 
                width: 210mm; 
                min-height: 297mm; 
                position: relative; 
                display: flex; 
                flex-direction: column; 
            }
            .page-break { page-break-before: always; }
            
            #printReportOutput { display: block !important; }
            #mainApp { display: none !important; }
            
            .results-card { 
                background: #ffffff !important; 
                color: #000000 !important; 
                border: 2px solid #000; 
                box-shadow: none; 
                break-inside: avoid; 
            }
            .results-card h4, 
            .results-card .res-label, 
            .results-card .res-val, 
            .results-card .res-sub,
            .results-card label {
                color: #000000 !important;
            }
            
            .res-label { font-weight: 600 !important; }
            .design-speed-input { background: transparent !important; border: 1px solid #000 !important; }
            .design-speed-input input { border: none !important; color: #000 !important; }
            
            a[href].er-btn:after { content: none !important; }
            a[href]:after { content: none; }
            .eng-report .er-cover,
            .eng-report .er-section,
            .eng-report .er-doc,
            .eng-report .er-product,
            .eng-report .er-kpi,
            .eng-report .er-sign-box {
              break-inside: avoid;
            }
            .eng-report .er-page-break { page-break-before: always; }
        }
        
        /* --- Loading Spinner --- */
        .spinner {
            display: inline-block;
            width: 20px;
            height: 20px;
            border: 3px solid rgba(255,255,255,0.3);
            border-radius: 50%;
            border-top-color: white;
            animation: spin 1s linear infinite;
        }
        @keyframes spin {
            to { transform: rotate(360deg); }
        }

        /* --- Stage Transitions --- */
        #stage1, #stage2, #stage3, #stagePinning, #stage4, #stage5, #stage7 {
            animation: fadeInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1);
        }
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(20px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }

        /* --- Responsiveness --- */
        @media (max-width: 1200px) {
            .calc-container { grid-template-columns: 1fr; gap: 20px; }
            #stage3 #inputsPanel {
              position: static;
              top: auto;
              max-height: none;
              overflow: visible;
            }
            .results-controls,
            .calc-field-legend {
              justify-content: flex-start;
            }
        }

        @media (max-width: 900px) {
            .form-row-3,
            .input-grid.two-col {
              grid-template-columns: 1fr;
            }
        }

        @media (max-width: 768px) {
            body { padding: 10px; }
            .container { padding: 18px 16px; border-radius: 10px; min-height: calc(100vh - 20px); }
            .calc-container { grid-template-columns: 1fr; }
            .header { flex-direction: column; gap: 16px; }
            .header h1 { font-size: 1.4rem; max-width: none; }
            .header-actions { max-width: none; width: 100%; justify-content: flex-start; }
            .header-actions .btn { flex: 1 1 auto; }
            .login-shell { padding: 24px 18px; }
            .sig-row { grid-template-columns: 1fr; gap: 20px; }
            .barrier-grid { grid-template-columns: 1fr; gap: 14px; }
            .page-nav { flex-wrap: wrap; }
            .page-nav-title { flex: 1 1 100%; order: -1; margin-bottom: 4px; }
            .page-nav-btn { flex: 1 1 auto; }
            .filter-toolbar { flex-direction: column; align-items: stretch; }
            .admin-invite-form { grid-template-columns: 1fr; }
        }

        @media (prefers-reduced-motion: reduce) {
          *, *::before, *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
          }
        }

/* --- Cloud projects --- */
.app-save-btn {
  align-self: flex-end; padding: 7px 14px; border-radius: 6px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font: 700 0.86rem/1.2 var(--font-sans);
}
.app-save-btn:hover { background: #5aa0e3; }
.app-save-btn:disabled { opacity: 0.6; cursor: progress; }
body.is-external .app-save-btn { display: none; }
.projects-modal {
  position: fixed; inset: 0; z-index: 2500; background: rgba(15, 30, 51, 0.55);
  display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px;
}
.projects-modal[hidden] { display: none; }
.projects-panel {
  width: min(760px, 100%); max-height: 86vh; overflow: auto; background: #fff;
  border-radius: 12px; box-shadow: var(--shadow-xl); padding: 20px 22px;
}
.projects-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 14px; }
.projects-head h2 { margin: 0 0 4px; font-size: 1.25rem; }
.projects-head p { margin: 0; font-size: 0.88rem; }
.projects-list { display: flex; flex-direction: column; gap: 8px; }
.projects-empty { padding: 18px; text-align: center; background: var(--bg-muted); border-radius: 8px; margin: 0; }
.project-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 14px; align-items: center;
  padding: 12px 14px; border: 1px solid var(--border-color); border-radius: 8px;
}
.project-row.is-current { border-color: var(--primary); background: var(--primary-light); }
.project-main { display: flex; flex-direction: column; min-width: 0; }
.project-main strong { color: var(--text-main); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-main span { font-size: 0.82rem; color: var(--text-sub); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.project-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-size: 0.78rem; color: var(--text-sub); }
.project-meta .rsb-pill { font-size: 0.68rem; padding: 2px 8px; }
.project-actions { display: flex; gap: 6px; }
@media (max-width: 640px) {
  .project-row { grid-template-columns: 1fr; }
  .project-meta { flex-direction: row; align-items: center; gap: 10px; }
  .app-save-btn { align-self: stretch; }
}
