/* =============================================================================
   IMCHEMSIM — Engineering Workbench Theme (v2)
   Loaded after app.css. Flat, dense, square-cornered desktop-engineering look:
   IBM Plex Sans/Mono, neutral graphite chrome, one accent blue, monochrome
   line-art PFD symbols, no decorative shadows or pills.
   ============================================================================= */
:root {
  --font-ui: "IBM Plex Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-num: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;

  --bg: #ecebe7;
  --canvas-bg: #ffffff;
  --surface: #ffffff;
  --surface-alt: #f5f4f1;
  --chrome: #e4e3df;
  --border: #cfcdc7;
  --border-strong: #2b2b28;
  --text: #1c1c1a;
  --text-secondary: #4a4a45;
  --text-muted: #77766f;
  --ink: #2b2b28;
  --wire: #3d3d39;
  --grid: #f0efeb;
  --accent: #1f5f99;
  --accent-bg: #e6eef6;
  --ok: #2e7d32;
  --warn: #9a5b00;
  --danger: #b3261e;
  --action-dark: #1c1c1a;
  --feed-main: #1f5f99;
  --feed-bg: #e6eef6;
  --radius: 3px;
}
body.theme-dark {
  --bg: #1a1a19;
  --canvas-bg: #222220;
  --surface: #262624;
  --surface-alt: #2d2d2a;
  --chrome: #20201e;
  --border: #45443f;
  --border-strong: #d8d6cf;
  --text: #ecebe6;
  --text-secondary: #c4c2ba;
  --text-muted: #9a988f;
  --ink: #e2e0d9;
  --wire: #cfcdc5;
  --grid: #2a2a27;
  --accent: #7fb0e0;
  --accent-bg: #1f2c3a;
  --action-dark: #ecebe6;
  --feed-main: #7fb0e0;
  --feed-bg: #1f2c3a;
}

body { font-family: var(--font-ui); font-size: 13px; background: var(--bg); -webkit-font-smoothing: auto; }
button, input, select, textarea { font-family: inherit; }
table td, .kpi-card .val, .pfd-caption, .num, input[type="number"], .status-chip { font-family: var(--font-num); font-feature-settings: "tnum"; }
table td:first-child { font-family: var(--font-ui); }

/* ---------- icons (CSS mask, inherit currentColor) ---------- */
.ic { width: 15px; height: 15px; display: inline-block; vertical-align: -3px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
[data-icon]::before {
  content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 6px; vertical-align: -2px;
  background: currentColor; -webkit-mask: var(--ic) no-repeat center / contain; mask: var(--ic) no-repeat center / contain;
}

/* ---------- menubar + toolbar ---------- */
header {
  display: block; min-height: 0; padding: 0; background: var(--chrome);
  border-bottom: 1px solid var(--border); flex-wrap: nowrap;
}
.menubar {
  display: flex; align-items: stretch; height: 30px; padding: 0 8px; gap: 2px;
  border-bottom: 1px solid var(--border); background: var(--chrome); position: relative; z-index: 60;
}
.menubar .brand { gap: 7px; margin-right: 10px; }
.logo-mark { width: 20px; height: 20px; border-radius: 2px; font-size: 9.5px; font-weight: 600; letter-spacing: 0.3px; background: var(--ink); color: var(--chrome); }
.brand h1 { font-size: 12.5px; font-weight: 600; letter-spacing: 0.4px; }
.brand small { display: none; }
.menu { position: relative; display: flex; }
.menu > button {
  border: none; background: transparent; color: var(--text); font-size: 12.5px; padding: 0 9px; cursor: default;
}
.menu > button:hover, .menu.open > button { background: var(--surface); }
.menu-pop {
  display: none; position: absolute; top: 100%; left: 0; min-width: 236px; padding: 4px 0;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 0;
  box-shadow: 2px 3px 0 rgba(0,0,0,0.12); z-index: 80;
}
.menu.open .menu-pop { display: block; }
.menu-pop button {
  display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 16px;
  border: none; background: transparent; text-align: left; padding: 5px 14px; font-size: 12.5px; color: var(--text); cursor: default;
}
.menu-pop button:hover { background: var(--accent); color: #fff; }
.menu-pop button kbd { font-family: var(--font-num); font-size: 11px; color: var(--text-muted); }
.menu-pop button:hover kbd { color: #e6eef6; }
.menu-pop hr { border: none; border-top: 1px solid var(--border); margin: 4px 0; }
.menu-pop .menu-hdr { padding: 6px 14px 2px; font-size: 10.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; }
.menubar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

.toolbar-center { padding: 5px 8px; gap: 4px; flex-wrap: wrap; }
.thermo-bar { border-radius: var(--radius); border-color: var(--border); background: var(--surface); padding: 2px 8px; font-size: 12px; display: inline-flex; align-items: center; gap: 6px; }
.thermo-bar span { font-weight: 500; }
.thermo-bar select { color: var(--accent); font-weight: 600; font-size: 12px; }
.thermo-rec-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600;
  border: 1px solid #d97706; background: #fffbeb; color: #b45309;
  cursor: pointer; white-space: nowrap;
}
.thermo-rec-pill:hover { background: #fef3c7; border-color: #b45309; }
body.theme-dark .thermo-rec-pill { background: #451a03; border-color: #f59e0b; color: #fcd34d; }
body.theme-dark .thermo-rec-pill:hover { background: #78350f; }
.btn-account {
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  color: var(--text); font-weight: 600; font-size: 11.5px; padding: 3px 9px;
  cursor: pointer; white-space: nowrap;
}
.btn-account:hover { border-color: var(--ink); }
.btn-account.signed-in { border-color: var(--accent); color: var(--accent); }
body.theme-dark .btn-account { background: var(--surface); border-color: var(--border); color: var(--text); }
body.theme-dark .btn-account.signed-in { border-color: var(--accent); color: var(--accent); }
.acc-err { padding: 7px 10px; border-radius: var(--radius); background: #fef2f2; border: 1px solid #ef4444; color: #b91c1c; font-size: 12px; margin-bottom: 10px; }
body.theme-dark .acc-err { background: #450a0a; border-color: #f87171; color: #fecaca; }
.acc-profile-bar { display: flex; justify-content: space-between; align-items: center; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt); }
.acc-role-badge { display: inline-block; margin-left: 6px; padding: 1px 6px; border-radius: 999px; font-size: 10px; font-weight: 600; background: var(--surface); border: 1px solid var(--border); text-transform: uppercase; }
.acc-save-box { padding: 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-alt); margin-bottom: 10px; }
.acc-proj-list { display: flex; flex-direction: column; gap: 7px; max-height: 290px; overflow-y: auto; }
.acc-proj-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.acc-proj-meta { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; }
.acc-proj-actions { display: flex; gap: 5px; flex-shrink: 0; flex-wrap: wrap; }
.btn-tool {
  border-radius: var(--radius); border: 1px solid var(--border); background: var(--surface);
  font-weight: 500; font-size: 12px; padding: 5px 9px; display: inline-block; transition: none;
}
.btn-tool:hover { border-color: var(--ink); background: var(--surface); }
.btn-solve {
  background: var(--accent); border: 1px solid var(--accent); border-radius: var(--radius);
  font-weight: 600; font-size: 12px; padding: 5px 13px; box-shadow: none; display: inline-block; margin-left: 4px;
}
.btn-solve:hover { background: #174a78; }
.header-right-stack { flex-direction: row; align-items: center; gap: 8px; }
.lang-toggle { border-radius: var(--radius); border-color: var(--border); background: var(--surface); }
.lang-toggle button { border-radius: 2px; font-weight: 600; padding: 2px 8px; }
.lang-toggle button.active { background: var(--ink); color: var(--surface); }
.theme-switch { height: 20px; width: 44px; border-radius: var(--radius); border-color: var(--border); background: var(--surface); padding: 0 5px; }
.theme-switch .theme-thumb { width: 18px; height: 14px; border-radius: 2px; box-shadow: none; background: var(--ink); }
.theme-switch .theme-thumb::after, body.theme-dark .theme-switch .theme-thumb::after { content: ""; }
.theme-switch .ts-ico { display: inline-flex; color: var(--text-muted) !important; }
.theme-switch .ts-ico .ic { width: 11px; height: 11px; }
body.theme-dark .theme-switch { background: var(--surface); border-color: var(--border); }
body.theme-dark .theme-switch .theme-thumb { left: calc(100% - 20px); background: var(--ink); box-shadow: none; }
body.theme-dark header, body.theme-dark .menubar { background: var(--chrome); border-color: var(--border); }
body.theme-dark .btn-tool, body.theme-dark .thermo-bar, body.theme-dark .lang-toggle { background: var(--surface); border-color: var(--border); color: var(--text); }
body.theme-dark .btn-tool:hover { background: var(--surface-alt); border-color: var(--ink); }
body.theme-dark .thermo-bar select { color: var(--accent); }
body.theme-dark .lang-toggle button.active { background: var(--ink); color: var(--surface); }
body.theme-dark .logo-mark { background: var(--ink); color: var(--chrome); }

/* ---------- palette ---------- */
.workbench { grid-template-columns: 228px 1fr; }
.palette { background: var(--surface-alt); padding: 8px 8px 14px; gap: 6px; }
.pal-sec-hdr { font-size: 10.5px; font-weight: 600; letter-spacing: 0.8px; color: var(--text-muted); margin: 6px 2px 4px; }
.pal-unit {
  border-radius: var(--radius); border: 1px solid transparent; background: transparent;
  padding: 4px 6px; margin-bottom: 1px; gap: 8px; transition: none;
}
.pal-unit:hover { border-color: var(--border); background: var(--surface); box-shadow: none; transform: none; }
.pal-badge {
  width: 38px; height: 22px; border-radius: 2px; font-family: var(--font-num); font-size: 9.5px; font-weight: 500;
  background: var(--surface) !important; color: var(--ink) !important; border: 1px solid var(--ink) !important;
}
.pal-txt strong { font-size: 12px; font-weight: 500; }
.pal-txt small { font-size: 10.5px; }
body.theme-dark .palette { background: var(--surface-alt); border-right-color: var(--border); }
body.theme-dark .pal-unit { background: transparent; border-color: transparent; }
body.theme-dark .pal-unit:hover { background: var(--surface); border-color: var(--border); box-shadow: none; }

/* ---------- flowsheet tabs + canvas ---------- */
.flowsheet-tabs-bar { background: var(--chrome); height: 32px; padding: 4px 8px 0; gap: 2px; }
.fs-tab { border-radius: 0; background: transparent; border-color: transparent; font-weight: 500; font-size: 12px; padding: 4px 10px; }
.fs-tab:hover { background: var(--surface-alt); }
.fs-tab.active { background: var(--canvas-bg); border-color: var(--border); }
.fs-tab-add { border-radius: var(--radius); background: transparent; color: var(--accent); border: 1px solid transparent; font-weight: 500; }
.fs-tab-add:hover { background: var(--surface); border-color: var(--border); }
body.theme-dark .flowsheet-tabs-bar { background: var(--chrome); border-color: var(--border); }
body.theme-dark .fs-tab { background: transparent; border-color: transparent; color: var(--text-secondary); }
body.theme-dark .fs-tab.active { background: var(--canvas-bg); border-color: var(--border); color: var(--text); }
body.theme-dark .fs-tab-add { background: transparent; color: var(--accent); border-color: transparent; }
.canvas-area, .canvas-viewport { background-color: var(--surface-alt); }
#canvas-stage {
  background-color: var(--canvas-bg);
  background-image: radial-gradient(circle, var(--border) 0.8px, transparent 0.9px);
  background-size: 20px 20px;
}
body.theme-dark .canvas-area, body.theme-dark .canvas-viewport { background-color: var(--bg); }
body.theme-dark #canvas-stage { background-color: var(--canvas-bg); background-image: radial-gradient(circle, #3a3a36 0.8px, transparent 0.9px); }
.canvas-top-strip { top: 40px; left: 10px; right: 10px; }
.status-chip {
  border-radius: var(--radius); box-shadow: none; border-color: var(--border); background: var(--surface);
  font-size: 11.5px; font-weight: 500; padding: 4px 10px;
}
.status-chip .solve-dur { color: var(--text-muted); font-weight: 600; font-variant-numeric: tabular-nums; }
.canvas-toolbar { border-radius: var(--radius); box-shadow: none; border-color: var(--border); background: var(--surface); padding: 2px 4px; gap: 1px; }
.ct-btn { border-radius: 2px; font-weight: 500; font-size: 12px; padding: 3px 7px; }
.ct-btn:hover:not(:disabled) { background: var(--surface-alt); border-color: var(--border); }
.ct-btn.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.ct-btn.danger:not(:disabled) { background: transparent; color: var(--danger); border-color: transparent; }
.ct-btn.danger:hover:not(:disabled) { background: #f8e5e3; border-color: var(--danger); }
.ct-sep { background: var(--border); }
body.theme-dark .status-chip, body.theme-dark .canvas-toolbar { background: var(--surface); border-color: var(--border); box-shadow: none; }
body.theme-dark .ct-btn.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
body.theme-dark .ct-btn.danger:hover:not(:disabled) { background: #3a1d1a; }

/* ---------- PFD symbols: monochrome line art ---------- */
.pfd-node { filter: none; }
.pfd-node.dragging { filter: none; opacity: 0.85; }
.pfd-node.selected, .recycle-stream-pill.selected { outline: 1.5px dashed var(--accent); outline-offset: 5px; border-radius: 0; }
body.theme-dark .pfd-node svg { filter: invert(0.9) hue-rotate(180deg); }
.pfd-tag-pill {
  background: transparent !important; border: none !important; color: var(--ink) !important;
  font-family: var(--font-num); font-size: 11px; font-weight: 500; padding: 0 2px; border-radius: 0; letter-spacing: 0.2px;
}
.node-del-btn { background: transparent; color: var(--text-muted); border-radius: 2px; width: 14px; height: 14px; font-weight: 500; }
.node-del-btn:hover { background: var(--danger); color: #fff; }
.pfd-caption {
  border-radius: 0; border: none; border-top: 1px solid var(--border); background: transparent;
  font-size: 10.5px; color: var(--text-secondary); padding: 3px 4px 0;
}
.pfd-caption strong { font-weight: 500; }
body.theme-dark .pfd-caption { background: transparent; border-color: var(--border); color: var(--text-secondary); }
.pfd-wire { stroke: var(--wire); stroke-width: 1.6; }
.pfd-wire.recycle { stroke-dasharray: 6 4; }
#arr-ink path { fill: var(--wire); }
.recycle-stream-pill {
  border-radius: var(--radius); background: var(--surface); color: var(--ink); border: 1px solid var(--ink);
  font-weight: 500; font-size: 11px; box-shadow: none; font-family: var(--font-num);
}
.recycle-stream-pill:hover { background: var(--surface-alt); border-color: var(--accent); }
body.theme-dark .recycle-stream-pill { background: var(--surface); color: var(--ink); border-color: var(--ink); }
.node-resize-handle { border-radius: 0; border-color: var(--accent); box-shadow: none; }
.marquee-box { border-radius: 0; border: 1px dashed var(--accent); background: rgba(31, 95, 153, 0.08); }
.empty-canvas-guide { border-radius: var(--radius); border: 1px dashed var(--border); background: var(--surface); }

/* ---------- bottom panel (replaces floating advisor + report dock) ---------- */
.canvas-area { display: flex; flex-direction: column; }
.bottom-panel {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 16;
  background: var(--surface); border-top: 1px solid var(--border-strong);
  display: flex; flex-direction: column; height: 200px; max-height: 60%;
}
.bottom-panel.collapsed { height: 31px; }
.bp-bar { display: flex; align-items: stretch; height: 30px; overflow-x: auto; overflow-y: hidden; scrollbar-width: thin; white-space: nowrap; border-bottom: 1px solid var(--border); background: var(--chrome); flex-shrink: 0; }
.bp-tabs { display: flex; align-items: stretch; flex-shrink: 0; }
.bp-tab {
  border: none; border-right: 1px solid var(--border); background: transparent; color: var(--text-secondary);
  font-size: 12px; padding: 0 12px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; flex-shrink: 0;
}
.bp-tab.active { background: var(--surface); color: var(--text); box-shadow: inset 0 2px 0 var(--accent); }
.bp-tab .bp-count { font-family: var(--font-num); font-size: 10.5px; color: var(--text-muted); }
.bp-actions { margin-left: auto; display: flex; align-items: center; gap: 2px; padding: 0 6px; flex-shrink: 0; }
#bp-collapse { position: sticky; right: 0; background: var(--chrome); z-index: 2; }
.bp-actions button, .report-dock .dock-pill {
  border: 1px solid transparent; background: transparent; color: var(--text); font-size: 12px; padding: 3px 8px;
  border-radius: 2px; cursor: pointer; display: inline-block; white-space: nowrap;
}
.bp-actions button:hover, .report-dock .dock-pill:hover { border-color: var(--border); background: var(--surface); }
.bp-body { flex: 1; overflow: auto; padding: 8px 12px; font-size: 12px; }
.bottom-panel.collapsed .bp-body { display: none; }
.bp-pane { display: none; }
.bp-pane.active { display: block; }
.report-dock { position: static; box-shadow: none; border: none; border-radius: 0; background: transparent; padding: 0; max-width: none; gap: 0; }
body.theme-dark .report-dock { background: transparent; box-shadow: none; }
body.theme-dark .dock-pill { background: transparent; border-color: transparent; }
.advisor-widget {
  position: static; width: auto; border: none; border-left: none; box-shadow: none; border-radius: 0; padding: 0; background: transparent;
}
.advisor-widget .advisor-widget-hdr { display: none; }
.advisor-widget-body { max-height: none; font-size: 12px; color: var(--text); line-height: 1.5; }
body.theme-dark .advisor-widget { background: transparent; box-shadow: none; }
.msg-log { font-family: var(--font-num); font-size: 11.5px; line-height: 1.55; }
.msg-log .msg { display: grid; grid-template-columns: 64px 18px 1fr; gap: 6px; border-bottom: 1px solid var(--grid); padding: 2px 0; }
.msg-log .msg .t { color: var(--text-muted); }
.msg-log .msg.err { color: var(--danger); }
.msg-log .msg.warn { color: var(--warn); }
.msg-log .msg.ok { color: var(--ok); }
.msg-log .msg .hint { grid-column: 3; color: var(--text-secondary); font-family: var(--font-ui); }
.stream-table th, .stream-table td { padding: 3px 9px; font-size: 11.5px; }
.stream-table th { position: sticky; top: 0; }
.stream-table td.lbl { font-family: var(--font-ui); color: var(--text-secondary); }
.bp-empty { color: var(--text-muted); padding: 8px 0; }
.bp-resize { height: 4px; cursor: ns-resize; margin-top: -2px; position: absolute; left: 0; right: 0; top: 0; z-index: 2; }
.bottom-panel.collapsed .bp-resize { display: none; }

/* ---------- modals ---------- */
.modal-bg { background: rgba(20, 20, 18, 0.38); backdrop-filter: none; }
.modal-card { border-radius: var(--radius); border-color: var(--border-strong); box-shadow: 4px 6px 0 rgba(0,0,0,0.14); }
.modal-hdr { padding: 9px 14px; background: var(--chrome); }
.modal-hdr h2 { font-size: 13.5px; font-weight: 600; }
.modal-body { padding: 14px 18px; }
.modal-ftr { padding: 8px 14px; background: var(--chrome); }
.x-btn { width: 24px; height: 24px; border-radius: 2px; border-color: var(--border); font-weight: 500; font-size: 15px; background: var(--surface); color: var(--text); }
body.theme-dark .modal-card { background: var(--surface); border-color: var(--border); box-shadow: 4px 6px 0 rgba(0,0,0,0.4); }
body.theme-dark .modal-hdr, body.theme-dark .modal-ftr { background: var(--chrome); border-color: var(--border); }
body.theme-dark .x-btn { background: var(--surface); color: var(--text); border-color: var(--border); }
label { font-size: 11.5px; font-weight: 500; }
input, select, textarea { border-radius: 2px; padding: 5px 8px; font-size: 12.5px; border-color: var(--border); margin-bottom: 9px; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
body.theme-dark input, body.theme-dark select, body.theme-dark textarea { background: var(--surface-alt); color: var(--text); border-color: var(--border); }
input.invalid, select.invalid { border-color: var(--danger) !important; box-shadow: 0 0 0 1px var(--danger) !important; background: #fdf3f2; }
body.theme-dark input.invalid { background: #3a1d1a; }
.field-err { display: block; color: var(--danger); font-size: 11px; margin: -6px 0 8px; }
.sub-tabs { gap: 0; padding-bottom: 0; margin-bottom: 14px; }
.sub-tab { border-radius: 0; border: none; border-bottom: 2px solid transparent; background: transparent; font-weight: 500; font-size: 12.5px; padding: 6px 12px; }
.sub-tab:hover { color: var(--text); }
.sub-tab.active { background: transparent; color: var(--text); border-bottom-color: var(--accent); }
body.theme-dark .sub-tab { background: transparent; border-color: transparent; }
body.theme-dark .sub-tab.active { background: transparent; color: var(--text); border-bottom-color: var(--accent); }
.kpi-strip { gap: 0; border: 1px solid var(--border); margin-bottom: 14px; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.kpi-card { border-radius: 0; border: none; border-right: 1px solid var(--border); background: var(--surface); padding: 8px 12px; }
.kpi-card:last-child { border-right: none; }
.kpi-card .lbl { font-weight: 500; }
.kpi-card .val { font-size: 16px; font-weight: 500; }
body.theme-dark .kpi-card { background: var(--surface); border-color: var(--border); }
.tbl-wrap, .plot-box, .step-card, .comp-list-scroll, .comp-preview-card, .tex-wrap { border-radius: var(--radius); }
.plot-box { border-radius: var(--radius); }
th { font-weight: 600; background: var(--surface-alt); }
th, td { padding: 5px 10px; }
.info-callout { border-radius: 0; border-left-width: 3px; background: var(--accent-bg); border-left-color: var(--accent); }
body.theme-dark .info-callout { background: var(--accent-bg); color: var(--text); border-left-color: var(--accent); }
.comp-chip { border-radius: 2px; background: var(--surface); color: var(--ink); border-color: var(--border); font-weight: 500; }
.comp-chip button { color: var(--text-muted); }
body.theme-dark .comp-chip { background: var(--surface-alt); color: var(--ink); border-color: var(--border); }
.comp-cat-pill { border-radius: 2px; font-weight: 500; }
.comp-cat-pill.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }
body.theme-dark .comp-cat-pill.active { background: var(--ink); color: var(--surface); border-color: var(--ink); }
.prod-item { border-radius: var(--radius); }
.prod-item.active { border: 1px solid var(--accent); box-shadow: inset 0 0 0 1px var(--accent); background: var(--accent-bg); }
.latex-copy-btn { border-radius: 2px; font-weight: 500; }

/* ---------- onboarding tour ---------- */
.tour-mask { position: fixed; inset: 0; z-index: 200; pointer-events: none; }
.tour-hole { position: fixed; border: 2px solid var(--accent); box-shadow: 0 0 0 9999px rgba(20,20,18,0.45); border-radius: 2px; transition: all 0.18s ease; pointer-events: none; z-index: 201; }
.tour-card {
  position: fixed; z-index: 202; width: 320px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); box-shadow: 4px 6px 0 rgba(0,0,0,0.18); padding: 12px 14px; pointer-events: auto;
}
.tour-card h3 { margin: 0 0 6px; font-size: 13.5px; font-weight: 600; }
.tour-card p { margin: 0 0 10px; font-size: 12.5px; line-height: 1.5; color: var(--text-secondary); }
.tour-card .tour-nav { display: flex; justify-content: space-between; align-items: center; }
.tour-card .tour-step { font-family: var(--font-num); font-size: 11px; color: var(--text-muted); }
.tour-card .tour-nav button { margin-left: 6px; }

/* ---------- examples gallery ---------- */
.ex-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; }
.ex-course { margin: 12px 0 6px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.7px; color: var(--text-muted); }
.ex-item { border: 1px solid var(--border); border-radius: var(--radius); padding: 9px 11px; cursor: pointer; background: var(--surface); }
.ex-item:hover { border-color: var(--accent); }
.ex-item strong { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 3px; }
.ex-item span { display: block; font-size: 11.5px; color: var(--text-secondary); line-height: 1.45; }
.ex-item code { font-family: var(--font-num); font-size: 10.5px; color: var(--accent); }

/* ---------- small screens ---------- */
.palette-toggle { display: none; }
.small-screen-note { display: none; }
@media (max-width: 1100px) {
  .workbench { grid-template-columns: 196px 1fr; }
  .pal-txt small { display: none; }
  .brand h1 { display: none; }
  .bp-actions button, .report-dock .dock-pill { padding: 3px 5px; font-size: 11px; }
  .bp-tab { padding: 0 8px; font-size: 11.5px; }
}
@media (max-width: 860px) {
  .workbench { grid-template-columns: 1fr; position: relative; }
  .palette {
    position: absolute; top: 0; bottom: 0; left: 0; width: 240px; z-index: 50;
    transform: translateX(-100%); transition: transform 0.18s ease; box-shadow: 4px 0 0 rgba(0,0,0,0.12);
  }
  body.palette-open .palette { transform: none; }
  .palette-toggle { display: inline-flex; }
  .menu.hide-sm { display: none; }
  .toolbar-center .btn-tool span.lbl-long { display: none; }
  .canvas-toolbar .ct-btn span { display: none; }
  .status-chip { display: none; }
  .bottom-panel { height: 160px; }
}
@media (max-width: 640px) {
  .small-screen-note {
    display: block; position: fixed; left: 8px; right: 8px; bottom: 8px; z-index: 120;
    background: var(--surface); border: 1px solid var(--border-strong); padding: 10px 12px; font-size: 12.5px;
    box-shadow: 3px 4px 0 rgba(0,0,0,0.15);
  }
  body.note-dismissed .small-screen-note { display: none; }
  .small-screen-note button { margin-top: 8px; }
  .toolbar-center .thermo-bar span { display: none; }
}

@media print {
  .menubar, .bottom-panel, .tour-mask, .tour-card, .tour-hole, .small-screen-note { display: none !important; }
}
body.theme-dark .btn-solve { color: #0f1a24; }
body.theme-dark .btn-solve:hover { background: #a3c7ea; }
.menu > button:focus { outline: none; }
.menu > button:focus-visible { outline: 1px solid var(--accent); outline-offset: -2px; }
@media (max-width: 640px) {
  html, body { max-width: 100vw; overflow-x: hidden; }
  .menubar { flex-wrap: wrap; height: auto; padding: 0 4px; }
  .menubar .brand { display: none; }
  .menu > button { padding: 6px 7px; font-size: 12px; }
  .menu[data-menu="report"], .menu[data-menu="help"] { display: none; }
  .menubar-right { margin-left: auto; }
  .menu-pop { position: fixed; left: 8px !important; right: 8px; top: auto; min-width: 0; }
}

/* ---------- connected flowsheet: ports, numbered streams, product flags ---------- */
.port-dot {
  position: absolute; width: 10px; height: 10px; border-radius: 50%; z-index: 6;
  box-sizing: border-box; border: 1.5px solid var(--wire, #3d3d39); background: var(--surface, #fff);
  opacity: 0.55; transition: opacity .12s, transform .12s;
}
.port-dot.out { cursor: crosshair; }
.port-dot.in { border-style: dashed; pointer-events: auto; }
.port-dot.used { background: var(--wire, #3d3d39); opacity: 0.8; }
.port-dot:hover, body.conn-dragging .port-dot.in { opacity: 1; transform: scale(1.35); border-color: var(--accent); }
body.conn-dragging .port-dot.in { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.pfd-node.conn-target { outline: 2px dashed var(--accent); outline-offset: 4px; border-radius: 4px; }
#pfd-wires .wire-hit { fill: none; stroke: transparent; stroke-width: 12; pointer-events: stroke; cursor: pointer; }
#pfd-wires .conn-stream rect, #pfd-wires .conn-stream text { pointer-events: all; cursor: pointer; }
.pfd-wire.conn { stroke-linejoin: miter; }
.conn-stream.sel .pfd-wire { stroke: var(--accent); stroke-width: 2.4; }
.conn-stream.sel .stream-num-box { stroke: var(--accent); }
.stream-num-box { fill: var(--surface, #fff); stroke: var(--wire, #3d3d39); stroke-width: 1; }
.stream-num-txt { font-family: var(--font-num); font-size: 9.5px; fill: var(--ink, #1f1f1c); }
.conn-drag { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-dasharray: 5 4; }
.conn-mode-badge {
  position: absolute; left: 18px; top: 92px; z-index: 5; pointer-events: auto;
  font-size: 11px; color: var(--text-secondary); background: var(--surface, #fff);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 3px 8px;
}
body.theme-dark .stream-num-box { fill: #1c1c1a; stroke: #b8b8b0; }
body.theme-dark .stream-num-txt { fill: #e8e8e2; }
body.theme-dark .port-dot { background: #1c1c1a; border-color: #b8b8b0; }
body.theme-dark .port-dot.used { background: #b8b8b0; }

/* Inline text-style action button (status chip) */
.btn-link { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); text-decoration: underline; cursor: pointer; }
.btn-link:hover { color: var(--text); }

/* ===================== Faz 29: theme selector, colour theme, live view ===================== */
.theme-seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.theme-seg button { flex: 1; border: 0; background: transparent; color: var(--text-muted); padding: 2px 7px; cursor: pointer; line-height: 1; }
.theme-seg button + button { border-left: 1px solid var(--border); }
.theme-seg button .ic { width: 12px; height: 12px; vertical-align: -2px; }
.theme-seg button:hover { color: var(--text); background: var(--surface-alt); }
.theme-seg button.active { background: var(--accent-bg); color: var(--accent); }
.theme-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* Colour theme: light chrome, equipment coloured by type (fill = light tint, line = strong tone). */
body.theme-color:not(.theme-dark) { --accent: #1f5f99; }
.color-eq-toggle { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-muted); padding: 2px 7px; cursor: pointer; line-height: 1; }
.color-eq-toggle .ic { width: 12px; height: 12px; vertical-align: -2px; }
.color-eq-toggle:hover { color: var(--text); background: var(--surface-alt); }
.color-eq-toggle.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.color-eq-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
body.theme-color .pfd-node { --eq: #2b2b28; --eq-bg: #ffffff; }
body.theme-color .pfd-node[data-utype="REACTOR"] { --eq: #c2410c; --eq-bg: #ffedd5; }
body.theme-color .pfd-node[data-utype="HEX"]     { --eq: #1d4ed8; --eq-bg: #dbeafe; }
body.theme-color .pfd-node[data-utype="PUMP"]    { --eq: #0f766e; --eq-bg: #ccfbf1; }
body.theme-color .pfd-node[data-utype="COMP"]    { --eq: #6d28d9; --eq-bg: #ede9fe; }
body.theme-color .pfd-node[data-utype="VALV"]    { --eq: #475569; --eq-bg: #e2e8f0; }
body.theme-color .pfd-node[data-utype="MIXER"]   { --eq: #0e7490; --eq-bg: #cffafe; }
body.theme-color .pfd-node[data-utype="SPLIT"]   { --eq: #4338ca; --eq-bg: #e0e7ff; }
body.theme-color .pfd-node[data-utype="FLASH"]   { --eq: #15803d; --eq-bg: #dcfce7; }
body.theme-color .pfd-node[data-utype="TOWER"],
body.theme-color .pfd-node[data-utype="SCDS"]    { --eq: #a16207; --eq-bg: #fef9c3; }
body.theme-color .pfd-node[data-utype="EVAP"]    { --eq: #be123c; --eq-bg: #ffe4e6; }
body.theme-color .pfd-node[data-utype="FEED"]    { --eq: #15803d; --eq-bg: #f0fdf4; }
body.theme-color .pfd-node[data-utype="PRODUCT"] { --eq: #b91c1c; --eq-bg: #fef2f2; }
body.theme-color .pfd-node svg [fill="#ffffff"] { fill: var(--eq-bg); }
body.theme-color .pfd-node svg [stroke="#2b2b28"] { stroke: var(--eq); }
body.theme-color .pfd-node svg :not(text)[fill="#2b2b28"] { fill: var(--eq); }
body.theme-color .pfd-node svg text { fill: #1c1c1a; }

/* Equipment problem markers */
.pfd-node.has-issue-err > div:nth-child(2) { outline: 2px solid var(--danger); outline-offset: 4px; border-radius: 6px; animation: issue-pulse 1.1s ease-in-out 3; }
.pfd-node.has-issue-warn > div:nth-child(2) { outline: 2px dashed var(--warn); outline-offset: 4px; border-radius: 6px; }
@keyframes issue-pulse { 50% { outline-color: transparent; } }
.unit-issue-badge {
  position: absolute; top: 18px; right: -6px; width: 18px; height: 18px; border-radius: 50%;
  display: grid; place-items: center; font: 700 12px/1 var(--font-ui); color: #fff; cursor: pointer; z-index: 5;
  box-shadow: 0 0 0 2px var(--canvas-bg);
}
.unit-issue-badge.err { background: var(--danger); }
.unit-issue-badge.warn { background: #d97706; }
body.theme-dark .unit-issue-badge.err { background: #ef5350; }

/* Live flow animation */
#pfd-wires .flow-dots { fill: none; stroke-linecap: round; pointer-events: none; animation-name: flow-dash; animation-timing-function: linear; animation-iteration-count: infinite; animation-duration: 1.6s; }
#pfd-wires .flow-dots.liq { stroke-width: 3.2; stroke-dasharray: 7 9; }
#pfd-wires .flow-dots.vap { stroke-width: 2.2; stroke-dasharray: 1.5 6.5; }
#pfd-wires .flow-dots.nodata { stroke: var(--text-muted); opacity: 0.6; }
@keyframes flow-dash { to { stroke-dashoffset: -32; } }
@media (prefers-reduced-motion: reduce) { #pfd-wires .flow-dots { animation: none; } }
#btn-live-view.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
#live-legend {
  position: absolute; right: 12px; bottom: 12px; z-index: 20; width: 210px; padding: 7px 9px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 11px; color: var(--text-secondary); pointer-events: none;
}
#live-legend .ll-title { font-weight: 600; color: var(--text); margin-bottom: 4px; }
#live-legend .ll-bar { height: 7px; border-radius: 2px; background: linear-gradient(to right, hsl(215,78%,46%), hsl(161,78%,46%), hsl(108,78%,46%), hsl(54,78%,46%), hsl(0,78%,46%)); }
#live-legend .ll-scale { display: flex; justify-content: space-between; font-family: var(--font-num); font-size: 10px; margin: 2px 0 5px; }
#live-legend .ll-row { display: flex; align-items: center; gap: 5px; }
#live-legend .ll-row svg line { stroke: var(--text-secondary); stroke-linecap: round; }
#live-legend .ll-liq { stroke-width: 3.2; stroke-dasharray: 7 9; }
#live-legend .ll-vap { stroke-width: 2.2; stroke-dasharray: 1.5 6.5; }
#live-legend .ll-note { margin-top: 3px; color: var(--text-muted); }

/* Stream probes */
#probe-layer { position: absolute; top: 0; left: 0; width: 0; height: 0; z-index: 8; }
.probe-card {
  position: absolute; min-width: 150px; padding: 4px 7px 5px; background: var(--surface);
  border: 1px solid var(--accent); border-radius: var(--radius); font-size: 11px; color: var(--text);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.probe-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; color: var(--accent); margin-bottom: 2px; }
.probe-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 14px; line-height: 1; padding: 0 0 0 6px; }
.probe-x:hover { color: var(--danger); }
.probe-card table { border-collapse: collapse; width: 100%; }
.probe-card td { padding: 0 2px; font-family: var(--font-num); font-size: 10.5px; }
.probe-card td:first-child { font-family: var(--font-ui); color: var(--text-secondary); padding-right: 8px; }
.probe-card td:last-child { text-align: right; }
.probe-empty { color: var(--text-muted); }
#pfd-wires .probe-pin { fill: var(--accent); stroke: var(--canvas-bg); stroke-width: 1.5; }

/* ===== Faz 31: Live tuner (slider panel + traced result curve) ===== */
#tuner-panel {
  position: absolute; right: 12px; top: 52px; z-index: 22; width: 292px; max-height: calc(100% - 70px); overflow-y: auto;
  padding: 8px 10px 9px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  font-size: 12px; color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}
#tuner-panel .tn-head { display: flex; justify-content: space-between; align-items: center; font-weight: 600; margin-bottom: 6px; }
#tuner-panel .tn-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 16px; line-height: 1; }
#tuner-panel .tn-x:hover { color: var(--danger); }
#tuner-panel .tn-field { display: block; color: var(--text-secondary); font-size: 11px; margin-bottom: 4px; }
#tuner-panel .tn-field select { display: block; width: 100%; margin-top: 2px; font-size: 12px; }
#tuner-panel .tn-hint { color: var(--text-muted); font-size: 10.5px; margin-bottom: 6px; }
#tuner-panel .tn-row { margin: 6px 0 4px; }
#tuner-panel .tn-lbl { display: flex; justify-content: space-between; gap: 8px; color: var(--text-secondary); }
#tuner-panel .tn-val { font-family: var(--font-num); color: var(--text); white-space: nowrap; }
#tuner-panel .tn-range { width: 100%; margin: 3px 0 0; accent-color: var(--accent); }
#tuner-panel .tn-ends { display: flex; justify-content: space-between; font-family: var(--font-num); font-size: 9.5px; color: var(--text-muted); }
#tuner-panel .tn-empty { color: var(--text-muted); font-size: 11px; padding: 4px 0; }
#tuner-panel .tn-sep { border-top: 1px solid var(--border); margin: 8px 0 6px; }
#tuner-panel .tn-kpi-val { font-family: var(--font-num); font-size: 18px; color: var(--accent); margin: 2px 0 4px; }
#tuner-panel .tn-plot svg { display: block; background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius); }
#tuner-panel .tn-axis { stroke: var(--text-muted); stroke-width: 1; }
#tuner-panel .tn-ax { fill: var(--text-muted); font-family: var(--font-num); font-size: 9px; }
#tuner-panel .tn-line { fill: none; stroke: var(--accent); stroke-width: 1.8; }
#tuner-panel .tn-dot { fill: var(--accent); }
#tuner-panel .tn-status { margin-top: 5px; font-size: 11px; color: var(--text-secondary); min-height: 14px; }
#tuner-panel .tn-err { color: var(--danger); }
#tuner-panel .tn-actions { display: flex; flex-wrap: wrap; gap: 4px 10px; margin-top: 6px; }
#btn-live-tuner.active, #btn-live-view.active { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
body.tuner-open #live-legend { right: 316px; }

/* ===== Faz 32: user-written rate law in the reaction cards ===== */
.rx-expr { margin-top: 8px; border-top: 1px solid var(--border); padding-top: 6px; font-size: 12px; }
.rx-expr summary { cursor: pointer; color: var(--accent); font-weight: 600; }
.rx-expr-on { font-weight: 400; font-size: 11px; color: var(--ok); margin-left: 6px; }
.rx-expr label { display: block; margin: 6px 0 2px; font-size: 11px; color: var(--text-secondary); }
.rx-expr-inp { width: 100%; font-family: var(--font-num); font-size: 12px; margin: 0; }
.rx-expr-help { margin-top: 4px; font-size: 10.5px; color: var(--text-muted); line-height: 1.4; }
.rx-expr-btns { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.rx-expr-msg { margin-top: 4px; font-size: 11px; color: var(--text-secondary); min-height: 14px; }
.rx-expr-msg.err { color: var(--danger); }
.rx-expr-msg.ok { color: var(--ok); }
.rx-expr-tex { overflow-x: auto; }

/* ===== Faz 33: custom names ===== */
.pfd-node-name {
  max-width: 190px; margin: 1px auto 2px; padding: 0 4px; text-align: center; font-size: 11px; font-weight: 600;
  color: var(--accent); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.modal-name-row { display: inline-flex; align-items: center; gap: 8px; margin-left: auto; margin-right: 10px; font-size: 12px; min-width: 0; }
.modal-name-row .mn-name { color: var(--accent); font-weight: 600; max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#rename-pop {
  position: fixed; z-index: 3000; width: 270px; padding: 9px 10px; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,0.18); font-size: 12px;
}
#rename-pop .rn-title { font-weight: 600; margin-bottom: 6px; }
#rename-pop input { width: 100%; margin: 0; font-size: 13px; }
#rename-pop .rn-msg { margin-top: 4px; font-size: 11px; color: var(--text-muted); }
#rename-pop .rn-msg.err { color: var(--danger); }
#rename-pop .rn-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 8px; }

/* ===================== Faz 36: convergence settings ===================== */
.conv-grid { display: grid; grid-template-columns: minmax(180px, auto) 1fr; gap: 10px 14px; align-items: center; max-width: 520px; }
.conv-grid select, .conv-grid input { margin: 0; }
.conv-err { color: var(--danger); min-height: 1.2em; margin: 8px 0 0; font-size: 13px; }
.conv-last { margin: 6px 0; font-size: 13px; color: var(--text); }
.conv-note { margin: 6px 0 14px; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
.conv-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
@media (max-width: 560px) { .conv-grid { grid-template-columns: 1fr; } }

/* Faz 36: feed flash result */
.feed-flash-out:empty { display: none; }
.feed-flash-out { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 12px; font-size: 13px; }
.feed-flash-out .ff-hdr { font-weight: 600; margin-bottom: 6px; color: var(--text); }
.feed-flash-out table { width: 100%; border-collapse: collapse; }
.feed-flash-out .ff-tab th { text-align: left; font-weight: 500; color: var(--text-muted); padding: 3px 10px 3px 0; width: 42%; }
.feed-flash-out .ff-tab td { padding: 3px 0; font-variant-numeric: tabular-nums; color: var(--text); }
.feed-flash-out .ff-split { margin-top: 10px; }
.feed-flash-out .ff-split th, .feed-flash-out .ff-split td { padding: 3px 6px; border-bottom: 1px solid var(--border); text-align: right; font-variant-numeric: tabular-nums; }
.feed-flash-out .ff-split th:first-child, .feed-flash-out .ff-split td:first-child { text-align: left; }
.feed-flash-out .ff-note { margin: 8px 0 0; font-size: 12px; color: var(--text-muted); line-height: 1.45; }
.feed-flash-out .ff-err { color: var(--danger); margin: 0; }
.feed-flash-out .ff-busy { color: var(--text-muted); margin: 0; }
.modal-ftr .feed-flash-btn { margin-right: auto; }
.feed-flash-out .ff-tab th, .feed-flash-out .ff-tab td { background: transparent; border: 0; border-bottom: 1px solid var(--border); text-align: left; font-family: var(--font-ui); }
.feed-flash-out .ff-split th { background: transparent; }

/* ===================== Faz 38: colour palettes (Volt, Mercan, Orman) ===================== */
/* Each palette is three colours: dark, light and one accent. It works with both base themes: the light
   theme uses the light colour as paper and the dark colour as ink; the dark theme swaps them. The accent
   is kept as a fill (buttons, highlights) with a readable ink on top; where it is used as text on a light
   background a deeper shade of the same hue is used (lime, coral and violet are too light for text there). */
body.pal-volt  { --p-dark: #0B0B0C; --p-light: #FAFAF7; --p-acc: #C6F432; --p-acc-ink: #4C6600; --p-acc-night: #C6F432; --p-on-acc: #0B0B0C; }
body.pal-coral { --p-dark: #14213D; --p-light: #F4EDE0; --p-acc: #FF6B5B; --p-acc-ink: #B83A2B; --p-acc-night: #FF8173; --p-on-acc: #14213D; }
body.pal-grove { --p-dark: #1F3D2B; --p-light: #E8DCC4; --p-acc: #8B5CF6; --p-acc-ink: #6638D6; --p-acc-night: #CBB8FD; --p-on-acc: #FFFFFF; }

body:is(.pal-volt, .pal-coral, .pal-grove) {
  --bg: color-mix(in srgb, var(--p-light) 92%, var(--p-dark));
  --chrome: color-mix(in srgb, var(--p-light) 86%, var(--p-dark));
  --canvas-bg: color-mix(in srgb, var(--p-light) 40%, #ffffff);
  --surface: color-mix(in srgb, var(--p-light) 50%, #ffffff);
  --surface-alt: var(--p-light);
  --border: color-mix(in srgb, var(--p-light) 74%, var(--p-dark));
  --border-strong: var(--p-dark);
  --text: var(--p-dark);
  --text-secondary: color-mix(in srgb, var(--p-dark) 80%, var(--p-light));
  --text-muted: color-mix(in srgb, var(--p-dark) 74%, var(--p-light));
  --ink: var(--p-dark);
  --wire: color-mix(in srgb, var(--p-dark) 88%, var(--p-light));
  --grid: color-mix(in srgb, var(--p-light) 88%, var(--p-dark) 4%);
  --accent: var(--p-acc-ink);
  --accent-bg: color-mix(in srgb, var(--p-acc) 24%, #ffffff);
  --accent-fill: var(--p-acc);
  --on-accent: var(--p-on-acc);
  --action-dark: var(--p-dark);
  --feed-main: var(--p-acc-ink);
  --feed-bg: color-mix(in srgb, var(--p-acc) 24%, #ffffff);
}
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark {
  --bg: var(--p-dark);
  --chrome: color-mix(in srgb, var(--p-dark) 82%, #000000);
  --canvas-bg: color-mix(in srgb, var(--p-dark) 93%, var(--p-light));
  --surface: color-mix(in srgb, var(--p-dark) 89%, var(--p-light));
  --surface-alt: color-mix(in srgb, var(--p-dark) 83%, var(--p-light));
  --border: color-mix(in srgb, var(--p-dark) 68%, var(--p-light));
  --border-strong: var(--p-light);
  --text: var(--p-light);
  --text-secondary: color-mix(in srgb, var(--p-light) 82%, var(--p-dark));
  --text-muted: color-mix(in srgb, var(--p-light) 76%, var(--p-dark));
  --ink: var(--p-light);
  --wire: color-mix(in srgb, var(--p-light) 86%, var(--p-dark));
  --grid: color-mix(in srgb, var(--p-dark) 88%, var(--p-light));
  --accent: var(--p-acc-night);
  --accent-bg: color-mix(in srgb, var(--p-acc) 20%, var(--p-dark));
  --action-dark: var(--p-light);
  --feed-main: var(--p-acc-night);
  --feed-bg: color-mix(in srgb, var(--p-acc) 20%, var(--p-dark));
}
body.pal-grove:not(.theme-dark) { --text-muted: color-mix(in srgb, var(--p-dark) 84%, var(--p-light)); }   /* sand page: keep muted text ≥ 4.5:1 */
/* Accent fills carry the palette's own ink (black on lime, navy on coral, white on violet). */
body:is(.pal-volt, .pal-coral, .pal-grove) .btn-solve,
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .btn-solve { background: var(--accent-fill); border-color: var(--accent-fill); color: var(--on-accent); }
body:is(.pal-volt, .pal-coral, .pal-grove) .btn-solve:hover,
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .btn-solve:hover { background: color-mix(in srgb, var(--accent-fill) 86%, var(--p-dark)); }
body:is(.pal-volt, .pal-coral, .pal-grove) .menu-pop button:hover { background: var(--accent-fill); color: var(--on-accent); }
body:is(.pal-volt, .pal-coral, .pal-grove) .logo-mark { background: var(--accent-fill); color: var(--on-accent); }
body:is(.pal-volt, .pal-coral, .pal-grove) .marquee-box { background: color-mix(in srgb, var(--accent-fill) 12%, transparent); }
/* Monochrome PFD in the palette's ink; the dark theme no longer needs the invert filter for it. */
body:is(.pal-volt, .pal-coral, .pal-grove):not(.theme-color) .pfd-node svg [stroke="#2b2b28"] { stroke: var(--ink); }
body:is(.pal-volt, .pal-coral, .pal-grove):not(.theme-color) .pfd-node svg :not(text)[fill="#2b2b28"] { fill: var(--ink); }
body:is(.pal-volt, .pal-coral, .pal-grove):not(.theme-color) .pfd-node svg text[fill="#2b2b28"] { fill: var(--ink); }
body:is(.pal-volt, .pal-coral, .pal-grove):not(.theme-color) .pfd-node svg [fill="#ffffff"] { fill: var(--canvas-bg); }
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark:not(.theme-color) .pfd-node svg { filter: none; }
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .stream-num-box { fill: var(--canvas-bg); stroke: var(--wire); }
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .stream-num-txt { fill: var(--text); }
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .port-dot { background: var(--canvas-bg); border-color: var(--wire); }
body:is(.pal-volt, .pal-coral, .pal-grove).theme-dark .port-dot.used { background: var(--wire); }

/* Palette picker: three swatch buttons next to the colour-equipment toggle. */
.palette-seg { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--surface); }
.palette-seg button { border: 0; background: transparent; padding: 3px 6px; cursor: pointer; line-height: 0; display: flex; gap: 0; align-items: center; }
.palette-seg button + button { border-left: 1px solid var(--border); }
.palette-seg button:hover { background: var(--surface-alt); }
.palette-seg button.active { background: var(--accent-bg); box-shadow: inset 0 -2px 0 var(--accent); }
.palette-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.palette-seg .sw { width: 9px; height: 12px; display: inline-block; border: 1px solid rgba(0, 0, 0, 0.18); }
.palette-seg .sw + .sw { border-left: 0; }
.palette-seg .sw:first-child { border-radius: 2px 0 0 2px; }
.palette-seg .sw:last-child { border-radius: 0 2px 2px 0; }
body.theme-dark .palette-seg .sw { border-color: rgba(255, 255, 255, 0.22); }

/* ===================== Faz 39: collapsible equipment panel ===================== */
.pal-collapse {
  display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;
  border: 1px solid transparent; border-radius: var(--radius); background: transparent; color: var(--text-muted);
  font-size: 10.5px; font-weight: 600; letter-spacing: 0.8px; text-transform: uppercase; padding: 3px 4px 3px 2px; cursor: pointer;
  position: sticky; top: -8px; z-index: 2; background: var(--surface-alt); margin: -2px 0 2px;
}
.pal-collapse:hover { color: var(--text); border-color: var(--border); background: var(--surface); }
.pal-collapse:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.pal-collapse .ic { width: 14px; height: 14px; flex-shrink: 0; }
@media (min-width: 861px) {
  body.palette-collapsed .workbench { grid-template-columns: 58px 1fr; }
  body.palette-collapsed .palette { padding: 8px 6px 14px; overflow-x: hidden; scrollbar-width: none; }
  body.palette-collapsed .palette::-webkit-scrollbar { display: none; }
  body.palette-collapsed .pal-collapse { justify-content: center; padding: 4px 0; }
  body.palette-collapsed .pal-collapse .pc-lbl { display: none; }
  body.palette-collapsed .pal-collapse .pc-chev { transform: scaleX(-1); }
  body.palette-collapsed .pal-txt { display: none; }
  body.palette-collapsed .pal-sec-hdr { font-size: 0; height: 0; margin: 6px 4px 5px; border-top: 1px solid var(--border); }
  body.palette-collapsed .pal-unit { justify-content: center; padding: 3px 0; gap: 0; }
}
@media (max-width: 860px) { .pal-collapse { display: none; } }

/* ===================== Faz 40: target adjustment (controller) ===================== */
/* Canvas tag on the adjusted unit/feed: monochrome dashed box (ink colour), like a CONT symbol. */
.ctrl-badge {
  position: absolute; left: -10px; top: -8px; z-index: 3; min-width: 18px; padding: 0 3px; height: 15px; line-height: 13px;
  font-family: var(--font-num); font-size: 9.5px; font-weight: 600; text-align: center; cursor: pointer;
  color: var(--ink); background: var(--canvas-bg); border: 1px dashed var(--ink); border-radius: 2px;
}
.ctrl-badge:hover { border-style: solid; }
.ctrl-badge.off { opacity: 0.45; }
.ctrl-badge.fail { color: var(--danger); border-color: var(--danger); }
.ctrl-intro { margin: 0 0 12px; font-size: 12.5px; color: var(--text-secondary); line-height: 1.5; max-width: 760px; }
.ctrl-empty { color: var(--text-muted); font-size: 12.5px; margin: 6px 0 14px; }
.ctrl-table { width: 100%; border-collapse: collapse; margin-bottom: 14px; font-size: 12.5px; }
.ctrl-table th, .ctrl-table td { background: transparent; text-align: left; vertical-align: top; padding: 6px 8px; border-bottom: 1px solid var(--border); font-family: var(--font-ui); }
.ctrl-table th { color: var(--text-muted); font-weight: 600; font-size: 11.5px; }
.ctrl-table .ctrl-id { font-family: var(--font-num); font-weight: 600; white-space: nowrap; }
.ctrl-table .ctrl-sub { color: var(--text-muted); font-size: 11.5px; margin-top: 2px; font-family: var(--font-num); }
.ctrl-table .ctrl-state { white-space: nowrap; color: var(--text-secondary); }
.ctrl-table .ctrl-act { white-space: nowrap; text-align: right; }
.ctrl-table .ctrl-act .btn-tool { padding: 3px 7px; font-size: 11.5px; }
.ctrl-table tr.ctrl-off td { color: var(--text-muted); }
.ctrl-form fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 14px 14px; margin: 0 0 12px; }
.ctrl-form legend { font-size: 11.5px; font-weight: 600; color: var(--text-muted); padding: 0 4px; }
.ctrl-form .ctrl-cur { font-family: var(--font-num); font-size: 12.5px; }

/* ===================== Faz 41: stream data card ===================== */
.stream-card {
  position: absolute; right: 12px; top: 52px; z-index: 23; width: 400px; max-width: calc(100% - 24px); max-height: calc(100% - 70px);
  overflow-y: auto; padding: 8px 10px 10px; background: var(--surface); color: var(--text); font-size: 12px;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}
.stream-card[hidden] { display: none; }
body.tuner-open .stream-card { right: 316px; }
.stream-card.two-phase { width: 540px; }
.stream-card .sc-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 6px; }
.stream-card .sc-title { font-weight: 600; font-size: 13px; color: var(--accent); }
.stream-card .sc-name { font-weight: 500; color: var(--text-secondary); }
.stream-card .sc-route { color: var(--text-muted); font-size: 11.5px; margin-top: 1px; }
.stream-card .sc-x { border: 0; background: transparent; color: var(--text-muted); cursor: pointer; font-size: 18px; line-height: 1; padding: 0 2px; }
.stream-card .sc-x:hover { color: var(--text); }
.stream-card table { width: 100%; border-collapse: collapse; }
.stream-card th, .stream-card td { background: transparent; border: 0; border-bottom: 1px solid var(--border); padding: 3px 4px; text-align: left; font-size: 11.5px; }
.stream-card td.num { text-align: right; font-family: var(--font-num); font-feature-settings: "tnum"; white-space: nowrap; }
.stream-card .sc-props td:first-child { color: var(--text-secondary); font-family: var(--font-ui); }
.stream-card .sc-props { table-layout: fixed; }
.stream-card .sc-props td:first-child { width: 52%; }
.stream-card .sc-props td.sc-text { text-align: right; color: var(--text); white-space: normal; font-family: var(--font-ui); }
.stream-card .sc-props td.num { width: 34%; }
.stream-card .sc-props .sc-u { color: var(--text-muted); width: 14%; white-space: nowrap; font-family: var(--font-ui); }
.stream-card .sc-comp th { font-weight: 600; color: var(--text-muted); font-size: 10.5px; text-align: right; white-space: nowrap; }
.stream-card .sc-comp th:first-child { text-align: left; }
.stream-card .sc-comp td:first-child { font-family: var(--font-ui); white-space: nowrap; }
.stream-card .sc-tbl-wrap { overflow-x: auto; }
.stream-card .sc-sub { font-size: 10.5px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase; color: var(--text-muted); margin: 10px 0 2px; }
.stream-card .sc-empty { color: var(--text-muted); margin: 4px 0 8px; }
.stream-card .sc-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 9px; }
@media (max-width: 860px) { .stream-card, body.tuner-open .stream-card { right: 8px; left: 8px; width: auto; } }

/* ===== Faz 43: azeotrope note — information by default, a warning only when a product has reached it ===== */
.info-callout.azeo-callout { font-weight: 400; line-height: 1.5; }
.info-callout.azeo-callout.limits { border-left-color: var(--warn); background: color-mix(in srgb, var(--warn) 9%, var(--surface)); }
body.theme-dark .info-callout.azeo-callout.limits { border-left-color: #f0b35a; background: color-mix(in srgb, #f0b35a 12%, transparent); color: var(--text); }

/* ===== Faz 44: heat exchanger utility flow line in the Design tab ===== */
.hx-util-result { grid-column: 1 / -1; border: 1px solid var(--border); border-left: 3px solid var(--accent); background: var(--accent-bg); padding: 8px 11px; font-size: 12.5px; line-height: 1.5; color: var(--text); }
.hx-util-result.has-warn { border-left-color: var(--warn); }
.hx-util-result .hx-ur-main { display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.hx-util-result .hx-ur-main strong { font-family: 'IBM Plex Mono', monospace; font-size: 14px; }
.hx-util-result .hx-ur-sub { color: var(--text-secondary); font-size: 11.5px; }
.hx-util-result .hx-ur-warn { margin-top: 5px; color: var(--warn); }
body.theme-dark .hx-util-result .hx-ur-warn { color: #f0b35a; }

/* ===== Faz 46b: binary interaction parameters (k_ij) ===== */
.kij-wrap { max-height: 46vh; overflow: auto; border: 1px solid var(--border); border-radius: 4px; margin: 4px 0 8px; }
.kij-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.kij-table th, .kij-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); text-align: left; }
.kij-table th:last-child, .kij-table td:last-child { padding-right: 12px; }
.kij-table th { position: sticky; top: 0; background: var(--surface); font-weight: 500; }
.kij-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.kij-table input.kij-in { width: 88px; box-sizing: border-box; margin: 0; }
.menu-sub { color: var(--text-muted); font-size: 12px; }
