/* ============================================================
   HailHydro — engineering-tool styling.
   Light, readable theme. No external fonts / assets.
   ============================================================ */

:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --border: #d7dce3;
  --border-strong: #b9c1cc;
  --ink: #1f2733;
  --ink-soft: #5b6573;
  --ink-faint: #8a94a3;
  --accent: #2563eb;
  --accent-soft: #e8f0fe;
  --warn-bg: #fff4e5;
  --warn-ink: #9a5b00;
  --danger: #dc2626;
  --ok: #16915b;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08), 0 1px 2px rgba(20, 30, 50, 0.06);
  --radius: 6px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", "Consolas", monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  min-height: 480px; /* below this the page scrolls rather than collapsing the schematic */
  overflow: auto;
}

/* ---------------- Toolbar ---------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-right: 8px;
  margin-right: 2px;
}
.brand-mark {
  font-size: 20px;
  color: var(--accent);
  line-height: 1;
}
.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.tb-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-faint);
  margin-right: 2px;
}

.tb-sep {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 4px;
}

.tb-btn {
  font: inherit;
  font-size: 12px;
  padding: 6px 11px;
  border: 1px solid var(--border-strong);
  background: #fbfcfe;
  color: var(--ink);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
  white-space: nowrap;
}
.tb-btn:hover { background: #eef2f8; }
.tb-btn:active { background: #e3e9f2; }

.tb-btn.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.mode-delete.is-active {
  background: var(--danger);
  border-color: var(--danger);
}

/* Disabled toolbar buttons (e.g. Undo/Redo when nothing to do). */
.tb-btn:disabled,
.tb-btn[disabled] {
  opacity: 0.4;
  cursor: default;
  background: #fbfcfe;
}
.tb-btn:disabled:hover,
.tb-btn[disabled]:hover {
  background: #fbfcfe;
}

/* The Grid toggle reuses .is-active for its on-state (handled above). */
#btn-grid.is-active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* Toolbar buttons carrying a standard component symbol. */
.tb-btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.tb-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  color: inherit; /* icons stroke with currentColor, so they flip on is-active */
}

/* Block-type buttons group: keep the nine glyph buttons compact. */
.tb-blocks { flex-wrap: wrap; gap: 4px; }
.block-btn { padding: 5px 8px; }

/* Block-type buttons are draggable: drop on empty canvas to place, or
   drop a 2-port block on a pipe to splice it into the run. */
.tb-draggable { cursor: grab; }
.tb-draggable:active { cursor: grabbing; }
.tb-draggable.is-dragging { opacity: 0.5; }

.tb-select {
  font: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  background: #fff;
  border-radius: var(--radius);
  color: var(--ink);
  cursor: pointer;
}

/* ---------------- Workspace ---------------- */

.workspace {
  flex: 1 1 auto;
  display: flex;
  min-height: 240px;
}

/* Left column of the workspace row: schematic on top + pump chart below, both
   the width of the main viewport. The right inspector/help run full height. */
.main-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.schematic-area {
  flex: 1 1 auto;
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  /* The snap grid is invisible; blocks just align to it. Plain canvas. */
  background-color: #fbfcfe;
}

.schematic {
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  user-select: none;
}

.status-bar {
  flex: 0 0 auto;
  padding: 5px 12px;
  font-size: 11.5px;
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.9);
  border-top: 1px solid var(--border);
  min-height: 26px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.status-bar .st-ok { color: var(--ok); font-weight: 600; }
.status-bar .st-warn { color: var(--warn-ink); }
.status-bar .st-err { color: var(--danger); font-weight: 600; }

/* ---------------- Inspector ---------------- */

/* Target the stable #inspector id (NOT just the .inspector-panel class):
   HY.Inspector.render() rewrites the element's className, which would otherwise
   drop these styles and let the panel shrink/grow to fit its content — which in
   turn resized the schematic and broke selection/zoom. The id always matches. */
#inspector,
.inspector-panel {
  /* FIXED width driven by a CSS variable (the drag-resizer adjusts it). The
     panel must NOT grow or shrink to its content — that is the whole point. */
  flex: 0 0 var(--insp-w, 400px);
  width: var(--insp-w, 400px);
  min-width: var(--insp-w, 400px);
  max-width: var(--insp-w, 400px);
  box-sizing: border-box;
  background: var(--panel);
  border-left: 1px solid var(--border);
  /* The panel is now a column: a fixed tab bar on top + a scrolling body. */
  display: flex;
  flex-direction: column;
  overflow: hidden;          /* children scroll, not the panel itself */
}

/* Tab bar: switch between the Components list and the single-item Inspector. */
.panel-tabs {
  flex: 0 0 auto;
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.panel-tab {
  flex: 1 1 0;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-soft);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 11px 8px;
  cursor: pointer;
}
.panel-tab:hover { background: #f6f8fb; }
.panel-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }

/* The scrolling content region that ListView / Inspector render into. The
   active-tab mode class controls padding: the single-item inspector keeps its
   generous text buffer; the list view manages its own tighter spacing. */
.panel-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-gutter: stable;
}
.panel-body.panel-mode-inspector { padding: 20px 22px 40px; }
.panel-body.panel-mode-list { padding: 0; }

/* Drag handle between the schematic and the inspector. */
.inspector-resizer {
  flex: 0 0 6px;
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 4;
  transition: background 0.12s;
}
.inspector-resizer:hover,
.inspector-resizer.is-dragging {
  background: var(--accent);
}
/* A subtle grip in the middle of the handle. */
.inspector-resizer::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 2px;
  height: 26px;
  transform: translate(-50%, -50%);
  border-left: 1px dotted rgba(255, 255, 255, 0.7);
  border-right: 1px dotted rgba(255, 255, 255, 0.7);
}
body.resizing-inspector { cursor: col-resize; user-select: none; }

.insp-empty { color: var(--ink-soft); }

.insp-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 8px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.insp-kind {
  font-weight: 700;
  font-size: 14px;
}
.insp-id {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-faint);
}

.insp-section {
  margin: 12px 0;
  padding-top: 4px;
}
.insp-section-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--ink-faint);
  font-weight: 700;
  margin-bottom: 7px;
}

.insp-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 6px 0;
}
.insp-label {
  flex: 0 0 40%;
  font-size: 12px;
  color: var(--ink-soft);
}
.insp-control {
  flex: 1 1 auto;
  min-width: 0;
}

.insp-input,
.insp-select,
.insp-textarea {
  font: inherit;
  font-size: 12px;
  width: 100%;
  padding: 5px 7px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.insp-input:focus,
.insp-select:focus,
.insp-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}
.insp-textarea {
  font-family: var(--mono);
  font-size: 11px;
  resize: vertical;
}
.insp-disabled { opacity: 0.5; }

.insp-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}
.insp-unit {
  font-size: 11px;
  color: var(--ink-faint);
}

.insp-slider {
  flex: 1 1 auto;
  cursor: pointer;
}
.insp-slider-val {
  flex: 0 0 auto;
  font-family: var(--mono);
  font-size: 11px;
  min-width: 38px;
  text-align: right;
  color: var(--ink-soft);
}

.insp-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  cursor: pointer;
}

.insp-btn {
  font: inherit;
  font-size: 12px;
  padding: 5px 14px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius);
  cursor: pointer;
}
.insp-btn:hover { background: #1d4ed8; }

.insp-btn-danger {
  background: var(--danger);
  border-color: var(--danger);
}
.insp-btn-danger:hover { background: #b91c1c; }

.insp-derived,
.insp-fit-status {
  margin-top: 6px;
}

.insp-note {
  font-size: 11.5px;
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 3px 0;
}

.insp-warning {
  font-size: 11.5px;
  color: var(--warn-ink);
  background: var(--warn-bg);
  border: 1px solid #f0d8ad;
  border-radius: var(--radius);
  padding: 5px 8px;
  margin: 5px 0;
  line-height: 1.4;
}

.insp-fit { margin-top: 4px; }

/* ---------------- Multi-select (bulk) panel ---------------- */

/* Grouped bulk actions: a small caption over a wrapping row of buttons. */
.insp-bulk-group {
  margin: 8px 0;
}
.insp-bulk-label {
  font-size: 11px;
  color: var(--ink-faint);
  margin-bottom: 5px;
}
.insp-bulk-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* Bulk-action buttons: lighter than the primary inspector button so a grid of
   them doesn't overwhelm the panel. */
.insp-bulk-btn {
  flex: 0 0 auto;
  padding: 5px 10px;
  background: #fbfcfe;
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
.insp-bulk-btn:hover {
  background: #eef2f8;
}
/* A danger bulk button (Delete selected) keeps the red treatment. */
.insp-bulk-btn.insp-btn-danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #fff;
}
.insp-bulk-btn.insp-btn-danger:hover {
  background: #b91c1c;
}

/* ---------------- Charts ---------------- */

.charts-area {
  flex: 0 0 auto;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding: 8px 14px 12px;
  box-shadow: 0 -1px 3px rgba(20, 30, 50, 0.05);
}
.charts-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 4px;
}
.charts-title {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-soft);
}
.charts-sub {
  font-size: 11.5px;
  color: var(--ink-faint);
}
.chart-canvas {
  display: block;
  width: 100%;
  height: 220px;
  max-width: 760px;
}

/* ------------------------------------------------------------------
   SVG schematic element styling (rendered by HY.Render).

   The schematic is the blocks + lines model: BLOCKS are component
   glyphs, LINES are plain orthogonal pipe wires, PORTS are the small
   connection nubs. There are NO text labels on the canvas — every
   name/value/pressure/flow lives only in the inspector.

   All hit-testing happens in HY.Canvas against the model geometry
   (block bboxes, port proximity, pipe polyline distance), so the SVG
   itself should not intercept pointer events per-shape; we let clicks
   land on the <svg> surface and resolve them in model space.
   ------------------------------------------------------------------ */
.schematic * { pointer-events: none; }

/* Selection accents (the renderer also draws its own halo geometry). */
.hy-block.is-selected,
.hy-line.is-selected { /* visual emphasis handled in HY.Render */ }

/* Port nubs: rendered states (free/hover/from) are coloured by HY.Render
   and HY.Symbols; keep them crisp. */
.hy-port { stroke-linejoin: round; }

/* A pipe (or block) highlighted as a drag-and-drop splice target.
   HY.Render tags lines with data-line-id / blocks with data-block-id. */
.hy-line.drop-target polyline,
[data-line-id].drop-target polyline,
[data-id].drop-target polyline {
  stroke: var(--accent) !important;
  stroke-width: 5;
  stroke-dasharray: 6 4;
}

/* Cursors per edit mode (set on the <svg> by mode class is optional;
   default keeps the crosshair feel of a schematic editor). */
.schematic { cursor: default; }

/* ------------------------------------------------------------------
   Editor-suite overlays (all GEOMETRY, no text). HY.Render draws these
   into dedicated layers; the palette is also baked into the renderer so
   these rules are mostly documentary / for any CSS-only theming.
   ------------------------------------------------------------------ */

/* Faint snap grid (bottom layer, opt-in via the Grid toggle). */
.hy-grid line {
  stroke: #e2e8f0;
  stroke-width: 1;
}

/* Box-select marquee: thin blue dashed rectangle with a light fill. */
.hy-marquee {
  stroke: var(--accent);
  fill: var(--accent);
  fill-opacity: 0.08;
  stroke-dasharray: 4 3;
}

/* Alignment guide lines while dragging blocks: thin magenta dashed. */
.hy-guide {
  stroke: #d946ef;
  stroke-width: 1;
  stroke-dasharray: 5 3;
}

/* ============================================================================
   Component Library — modal manager, picker, save dialog (R1).
   Reuses .insp-* controls; adds an overlay + modal shell and a 2-pane layout.
   ============================================================================ */

/* Overlay + modal shell */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 28, 42, 0.42);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.lib-modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 24px 48px rgba(15, 23, 42, 0.28);
  width: 560px;
  max-width: 100%;
  max-height: 88vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.lib-modal-wide { width: 920px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; font-size: 15px; color: var(--ink); }
.modal-close {
  border: none;
  background: none;
  font-size: 24px;
  line-height: 1;
  color: var(--ink-faint);
  cursor: pointer;
  padding: 0 4px;
}
.modal-close:hover { color: var(--ink); }
.modal-body { padding: 16px 18px; overflow-y: auto; }

/* Ghost button variant (used across library UI) */
.insp-btn-ghost {
  background: #fbfcfe;
  color: var(--ink);
  border: 1px solid var(--border-strong);
}
.insp-btn-ghost:hover { background: #eef2f8; }

/* Action bar */
.lib-actionbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.lib-spacer { flex: 1 1 auto; }

/* Manager 2-pane grid */
.lib-grid { display: flex; gap: 14px; align-items: flex-start; }
.lib-grid-left { flex: 0 0 320px; display: flex; flex-direction: column; gap: 10px; }
.lib-editor { flex: 1 1 auto; min-width: 0; }

/* Category tabs */
.lib-tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.lib-tab {
  font: inherit;
  font-size: 11.5px;
  padding: 5px 9px;
  border: 1px solid var(--border-strong);
  background: #fbfcfe;
  color: var(--ink-soft);
  border-radius: 999px;
  cursor: pointer;
}
.lib-tab:hover { background: #eef2f8; }
.lib-tab.is-active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Parts list */
.lib-list {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-y: auto;
  max-height: 52vh;
  background: #fff;
}
.lib-list-tall { max-height: 60vh; }
.lib-item {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  background: none;
  padding: 9px 12px;
  cursor: pointer;
  position: relative;
}
.lib-item:hover { background: var(--accent-soft); }
.lib-item.is-active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.lib-item-name { font-size: 12.5px; font-weight: 600; color: var(--ink); }
.lib-item-sub { font-size: 11px; color: var(--ink-faint); margin-top: 1px; }
.lib-item-notes { font-size: 11px; color: var(--ink-soft); margin-top: 4px; line-height: 1.35; }
.lib-badge {
  position: absolute; top: 9px; right: 10px;
  font-size: 9.5px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--ink-faint); border: 1px solid var(--border-strong);
  border-radius: 4px; padding: 1px 5px; background: #f6f8fb;
}
.lib-empty { padding: 18px 14px; font-size: 12px; color: var(--ink-faint); line-height: 1.5; }

/* Editor form */
.lib-form { display: flex; flex-direction: column; gap: 12px; }
.lib-field { display: flex; flex-direction: column; gap: 4px; }
.lib-field-label { flex: none; font-size: 11px; color: var(--ink-soft); }
.lib-row2 { display: flex; gap: 10px; }
.lib-row2 > .lib-field { flex: 1 1 0; min-width: 0; }
.lib-hint { font-size: 10.5px; color: var(--ink-faint); line-height: 1.4; }
.lib-points, .lib-params { font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; font-size: 11.5px; }
.lib-fitrow { display: flex; align-items: center; gap: 10px; }
.lib-fitmsg { font-size: 11px; color: var(--ink-faint); }
.lib-fitmsg.is-ok { color: var(--ok); }
.lib-fitmsg.is-warn { color: var(--danger); }
.lib-btnrow { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

/* Inspector "Library" inline buttons */
.insp-lib-row { display: flex; gap: 8px; }
.insp-lib-row .insp-btn { flex: 1 1 0; }

/* ============================================================================
   Component list view (HY.ListView) — sortable / filterable table in the
   right panel's "Components" tab.
   ============================================================================ */
.lv-filterbar {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  position: sticky;
  top: 0;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 2;
}
.lv-search {
  flex: 1 1 auto;
  min-width: 0;
  font: inherit;
  font-size: 12px;
  padding: 5px 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}
.lv-search:focus { border-color: var(--accent); outline: none; }
.lv-select {
  flex: 0 0 auto;
  font: inherit;
  font-size: 11.5px;
  padding: 5px 4px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: #fff;
}

.lv-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
}
.lv-th {
  position: sticky;
  top: 41px; /* below the sticky filter bar */
  background: #f6f8fb;
  color: var(--ink-soft);
  font-weight: 700;
  text-align: left;
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  white-space: nowrap;
  user-select: none;
}
.lv-th:hover { background: #eef2f8; }
.lv-th.is-sorted { color: var(--accent); }
.lv-th.lv-num { text-align: right; }

.lv-row { cursor: pointer; border-bottom: 1px solid #eef1f5; }
.lv-row:hover { background: var(--accent-soft); }
.lv-row.is-selected { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.lv-td {
  padding: 6px 8px;
  color: var(--ink);
  vertical-align: top;
}
.lv-td.lv-num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.lv-td.lv-detail {
  color: var(--ink-faint);
  max-width: 0;            /* let ellipsis kick in within the table layout */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.lv-empty { padding: 18px 12px; color: var(--ink-faint); text-align: center; }
.lv-count {
  padding: 8px 12px 14px;
  color: var(--ink-faint);
  font-size: 11px;
}

/* ============================================================================
   Feedback modal + version stamp.
   ============================================================================ */
.fb-intro { margin: 0 0 14px; font-size: 12.5px; line-height: 1.5; color: var(--ink-soft); }
.fb-text { font-size: 12.5px; }
.fb-check { display: flex; align-items: center; gap: 7px; font-size: 12px; color: var(--ink); cursor: pointer; }
.fb-status { min-height: 16px; font-size: 11.5px; color: var(--ink-faint); }
.fb-status.is-ok { color: var(--ok); }
.fb-status.is-warn { color: var(--danger); }
.fb-foot { margin-top: 6px; font-size: 11px; color: var(--ink-faint); }

/* Right-aligned version stamp in the status bar. */
.status-bar .st-version { margin-left: auto; color: var(--ink-faint); font-variant-numeric: tabular-nums; }

/* Live library-file bar inside the Library manager. */
.lib-filebar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 8px 11px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f8fafc;
  font-size: 11.5px;
}
.lib-file-status { color: var(--ink-soft); }
.lib-file-status.is-live { color: var(--ok); font-weight: 600; }
.lib-file-note { color: var(--ink-faint); }
.lib-file-err { color: var(--danger); }

/* Current-file indicator in the status bar (file-first persistence state). */
.status-bar .st-file { font-weight: 600; }
.status-bar .st-file.st-saved { color: var(--ok); }
.status-bar .st-file.st-dirty { color: var(--warn-ink); }
.status-bar .st-file.st-unbound { color: var(--ink-faint); font-weight: 500; }
.status-bar .st-file.st-fallback { color: var(--ink-faint); font-weight: 500; }

/* Offline / Update modal. */
.upd-dl { text-decoration: none; font-size: 13px; padding: 8px 16px; }
.upd-ver { font-size: 11.5px; color: var(--ink-faint); margin: 8px 0 16px; }
.upd-section-title { font-weight: 700; font-size: 12.5px; color: var(--ink); margin: 4px 0 6px; }
.upd-steps { margin: 0 0 14px; padding-left: 20px; }
.upd-steps li { font-size: 12.5px; line-height: 1.5; margin-bottom: 6px; color: var(--ink); }
.upd-note { font-size: 11.5px; color: var(--ink-soft); line-height: 1.5; margin: 8px 0 0; }
.upd-note a { color: var(--accent); }

/* ============================================================================
   Help & Manual drawer (right slide-out; pin to dock or float over the canvas).
   ============================================================================ */
/* Anchor the absolute help drawer AND clip it when closed: the drawer parks
   off the right edge (translateX(100%)); without clipping that overflow makes
   the page scroll sideways. overflow:hidden keeps it fully hidden, no scroll. */
.workspace { position: relative; overflow: hidden; }

.help-drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: var(--help-w, 420px);
  max-width: 92vw;
  background: var(--panel);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 26px rgba(20, 30, 50, 0.14);
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
  z-index: 30;
}
.workspace.help-open .help-drawer { transform: translateX(0); }
/* Pinned: reserve space so the drawer docks beside (not over) the workspace. */
.workspace.help-open.help-pinned { padding-right: var(--help-w, 420px); }
.workspace.help-pinned .help-drawer { box-shadow: none; }

.help-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 11px 12px 11px 16px;
  border-bottom: 1px solid var(--border);
}
.help-title { font-weight: 700; font-size: 14px; color: var(--ink); }
.help-grow { flex: 1 1 auto; }
.help-icon-btn {
  border: none; background: none; cursor: pointer;
  font-size: 14px; line-height: 1; padding: 5px 7px;
  border-radius: 6px; color: var(--ink-soft);
}
.help-icon-btn:hover { background: #eef2f8; }
.help-icon-btn.is-on { color: var(--accent); }

.help-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 14px 16px 48px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--ink);
}
.help-toc {
  background: #f6f8fb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.help-toc-title { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--ink-faint); margin-bottom: 6px; }
.help-toc ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 14px; }
.help-toc li { margin: 3px 0; break-inside: avoid; }
.help-toc a { color: var(--accent); text-decoration: none; font-size: 12px; }
.help-toc a:hover { text-decoration: underline; }

.help-section { margin-bottom: 18px; scroll-margin-top: 8px; }
.help-h { font-size: 13px; margin: 0 0 7px; color: var(--ink); border-bottom: 1px solid var(--border); padding-bottom: 4px; }
.help-prose p { margin: 0 0 8px; }
.help-prose ul { margin: 0 0 8px; padding-left: 18px; }
.help-prose li { margin: 3px 0; }
.help-prose a { color: var(--accent); cursor: pointer; text-decoration: none; }
.help-prose a:hover { text-decoration: underline; }
.help-prose code, .help-prose kbd {
  font-family: var(--mono); font-size: 11px;
  background: #eef2f7; border: 1px solid var(--border); border-radius: 4px; padding: 0 4px;
}
.help-keys { width: 100%; border-collapse: collapse; margin: 2px 0 4px; }
.help-keys td { padding: 4px 6px; border-bottom: 1px solid #eef1f5; vertical-align: top; }
.help-keys td:first-child { white-space: nowrap; width: 44%; }
.help-changelog .help-cl-entry { margin-bottom: 12px; }
.help-cl-ver { font-weight: 700; font-size: 12.5px; color: var(--ink); }
.help-cl-date { font-weight: 400; color: var(--ink-faint); font-size: 11px; }
.help-changelog ul { margin: 4px 0 0; padding-left: 18px; }

/* "What's new" dot on the Help button when the version changed since last seen. */
#btn-help { position: relative; }
#btn-help.has-update::after {
  content: "";
  position: absolute; top: 3px; right: 4px;
  width: 7px; height: 7px; border-radius: 50%;
  background: #ef4444; box-shadow: 0 0 0 2px var(--panel);
}

.upd-hosted { font-size: 12px; color: var(--ink-soft); margin: 0 0 12px; }
.upd-hosted a { color: var(--accent); }

/* Square +/- zoom buttons (equal width, bold glyph). */
.tb-btn-sq { min-width: 30px; text-align: center; font-weight: 700; padding: 6px 9px; }

/* "Keep your work safe" block in the Offline/Update modal. */
.upd-safety { background: #f0f7f1; border: 1px solid #cfe6d4; border-radius: 8px; padding: 11px 13px; margin-bottom: 14px; }
.upd-safety-title { margin: 0 0 4px; font-weight: 700; font-size: 12.5px; color: var(--ok); }

/* Quick rotate-90 button next to the rotation dropdown. */
.insp-btn-rot { padding: 4px 9px; font-size: 14px; line-height: 1; }

/* ============================================================================
   Flow color legend — a blue→red gradient with min/mid/max labels, overlaid in
   the schematic's bottom-left corner. Toggled by the Legend toolbar button.
   ============================================================================ */
/* Container anchored bottom-left, ABOVE the status bar. Collapsed = just the
   icon; clicking expands the card above it. */
.flow-legend {
  position: absolute;
  left: 12px;
  bottom: 38px;            /* clear the ~26px status bar */
  z-index: 6;
  display: flex;
  flex-direction: column;  /* card stacks above the toggle (toggle is last) */
  align-items: flex-start;
  gap: 6px;
  pointer-events: none;    /* only the toggle is interactive */
}
.flow-legend-toggle {
  pointer-events: auto;
  width: 30px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--border);
  border-radius: 7px;
  box-shadow: var(--shadow);
  cursor: pointer;
  padding: 0;
}
.flow-legend-toggle:hover { background: #eef2f8; }
.flow-legend.is-open .flow-legend-toggle { border-color: var(--accent); }

/* The expandable card (hidden until open). */
.flow-legend-card {
  display: none;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 7px 9px 6px;
  width: 168px;
}
.flow-legend.is-open .flow-legend-card { display: block; }
.flow-legend-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--ink-faint);
  margin-bottom: 4px;
}
.flow-legend-bar {
  height: 9px;
  border-radius: 3px;
  /* Matches flowColor(): blue (low) -> red (high). */
  background: linear-gradient(to right, #3b82f6, #ef4444);
}
.flow-legend-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 3px;
  font-size: 10.5px;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}
.flow-legend-labels span:nth-child(2) { transform: translateX(-50%); margin-left: 50%; }
