/* ---------------------------------------------------------------------------
   SFMD Collab — industrial-precision dark UI
   Canvas colours in canvas-renderer.js mirror these tokens.
   Tile geometry (.node, .node-head, .node-config, .node-pins, .pin-row) is
   mirrored in solver.js; change both together.
   ------------------------------------------------------------------------- */
:root {
  --bg: #0b0d10;
  --s1: #14171c;            /* islands, tiles */
  --s2: #1a1e25;            /* hover */
  --s3: #232831;            /* pressed, active */
  --inset: #0d0f13;         /* fields */
  --line: #232830;          /* hairline inside a surface */
  --line-2: #2c323c;        /* surface outline */
  --line-3: #3c4450;        /* hover outline */
  --text: #e7eaee;
  --text-2: #a4acb8;
  --text-3: #6b7482;
  --accent: #fa9549;
  --accent-ink: #1a0f05;
  --accent-soft: rgba(250, 149, 73, 0.14);
  --accent-line: rgba(250, 149, 73, 0.5);
  --ok: #3ecf8e;
  --warn: #f2c94c;
  --danger: #f2555a;
  --info: #5ab0f5;
  --sans: Inter, "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", "Cascadia Mono", ui-monospace, "SF Mono", Consolas, monospace;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45), 0 2px 6px rgba(0, 0, 0, 0.3);
  --edge: 12px;             /* island distance from the window edge */
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 13.5px;
  line-height: 1.38;
  overflow: hidden;
  user-select: none;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
input, textarea { user-select: text; }
.hidden { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* Icons */
.ic {
  width: 16px; height: 16px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-sm { width: 12px; height: 12px; stroke-width: 2; }

kbd {
  display: inline-block; min-width: 18px; height: 18px; padding: 0 5px;
  border: 1px solid var(--line-2); border-bottom-width: 2px; border-radius: 4px;
  background: var(--s2); color: var(--text-2);
  font: 500 10.5px/15px var(--mono); text-align: center; white-space: nowrap;
}

.workspace { position: fixed; inset: 0; overflow: hidden; }

/* ---------------------------------------------------------------- Canvas */
.viewport { position: absolute; inset: 0; overflow: hidden; cursor: default; touch-action: none; }
.viewport.tool-pan { cursor: grab; }
.viewport.tool-pen, .viewport.tool-note, .viewport.tool-zone { cursor: crosshair; }
.viewport.tool-erase { cursor: cell; }
.viewport.edge-hover { cursor: pointer; }
.viewport.panning, .viewport.panning * { cursor: grabbing !important; }

.bg-canvas { position: absolute; inset: 0; display: block; pointer-events: none; }
.world {
  position: absolute; top: 0; left: 0; transform-origin: 0 0;
  will-change: transform; pointer-events: none;
}
.layer { position: absolute; top: 0; left: 0; overflow: visible; pointer-events: none; }

.empty-hint {
  position: absolute; left: 50%; top: 46%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text-3); pointer-events: none; text-align: center;
}
.empty-hint .ic { width: 28px; height: 28px; stroke-width: 1.3; color: var(--line-3); margin-bottom: 6px; }
.empty-hint strong { font-size: 14px; font-weight: 600; color: var(--text-2); }
.empty-hint code { font-family: var(--mono); font-size: 11.5px; color: var(--text-2); }

/* --------------------------------------------------------- Machine tiles */
.node {
  position: absolute; top: 0; left: 0; width: 360px;
  background: var(--s1); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), 0 6px 18px rgba(0, 0, 0, 0.4);
  pointer-events: auto; will-change: transform; contain: layout style;
}
.node:hover { border-color: var(--line-3); }
.node.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px var(--accent), 0 0 0 5px var(--accent-soft), 0 10px 26px rgba(0, 0, 0, 0.5);
}
.viewport.tool-erase .node:hover { border-color: var(--danger); box-shadow: 0 0 0 1px var(--danger), 0 0 0 5px rgba(242, 85, 90, 0.14); }

/* Head: 44px. Clean single-row recipe title with category color chip (click to switch). */
.node-head { position: relative; height: 44px; display: flex; align-items: center; padding: 0 12px 0 14px; }
.node:hover .node-head, .node.selected .node-head, .node:focus-within .node-head { padding-right: 104px; }
.node-title {
  display: flex; align-items: center; gap: 7px; max-width: 100%; min-width: 0; height: 30px;
  margin: 0 0 0 -6px; padding: 0 6px; border: 0; border-radius: 6px; background: transparent;
  font-weight: 700; font-size: 16.5px; line-height: 22px; letter-spacing: -0.01em; color: var(--text);
  cursor: pointer;
}
.node-title:hover { background: var(--s3); }
.node-title-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.node-title .ic { color: var(--text-3); margin-left: -1px; }
.node-title:hover .ic { color: var(--text); }
.node-alt, .tag {
  flex: none; height: 18px; padding: 0 5px; border-radius: 4px;
  border: 1px solid rgba(242, 201, 76, 0.45); color: var(--warn);
  font: 700 10px/16px var(--mono); letter-spacing: 0.06em;
}
.node-chip { width: 8px; height: 8px; border-radius: 2.5px; flex: none; }

/* Quick actions: shown on hover and while selected. */
.node-actions {
  position: absolute; top: 50%; transform: translateY(-50%); right: 8px; display: flex; gap: 2px; padding-left: 6px;
  background: var(--s1); box-shadow: -12px 0 12px 2px var(--s1); border-radius: 6px;
  opacity: 0; pointer-events: none;
}
.node:hover .node-actions, .node.selected .node-actions, .node:focus-within .node-actions { opacity: 1; pointer-events: auto; }
.node-act {
  width: 28px; height: 28px; display: grid; place-items: center;
  border: 0; border-radius: 6px; background: transparent; color: var(--text-2);
}
.node-act .ic { width: 15px; height: 15px; }
.node-act:hover { background: var(--s3); color: var(--text); }
.node-act[data-act="balance"]:hover { color: var(--accent); }
.node-act[data-act="del"]:hover { background: rgba(242, 85, 90, 0.16); color: var(--danger); }

/* Config: 42px. Machines stepper, clock %, power. */
.node-config {
  height: 42px; border-top: 1px solid var(--line);
  display: flex; align-items: center; gap: 6px; padding: 0 10px 0 12px;
}
.num {
  height: 100%; min-width: 0; border: 0; background: transparent; outline: none; padding: 0;
  font: 600 15px/26px var(--mono); font-variant-numeric: tabular-nums; color: var(--text);
}
.field {
  display: flex; align-items: center; height: 28px; flex: none;
  background: var(--inset); border: 1px solid var(--line-2); border-radius: 6px;
}
.field:hover { border-color: var(--line-3); }
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.field-unit { padding: 0 6px 0 2px; font: 600 11.5px/26px var(--mono); color: var(--text-3); }
.stepper .num { min-width: 44px; width: 4.5ch; text-align: center; padding: 0 2px; }
.step-btn {
  width: 24px; height: 100%; display: grid; place-items: center;
  border: 0; background: transparent; color: var(--text-3);
}
.step-btn:first-child { border-radius: 5px 0 0 5px; border-right: 1px solid var(--line); }
.step-btn:last-child { border-radius: 0 5px 5px 0; border-left: 1px solid var(--line); }
.step-btn .ic { width: 11px; height: 11px; stroke-width: 2.4; }
.step-btn:hover { background: var(--s3); color: var(--accent); }
.config-x { color: var(--text-3); font: 600 13px var(--mono); margin: 0 -2px; }
.clock { display: flex; align-items: center; gap: 4px; color: var(--text-3); }
.clock .ic { width: 14px; height: 14px; }
.clock .num { width: 56px; text-align: right; padding-left: 3px; }
.clock.boosted .ic { color: var(--accent); }
.clock.slowed .ic { color: var(--info); }
.node-power {
  margin-left: auto; display: flex; align-items: center; gap: 4px; min-width: 0;
  font: 600 13px var(--mono); font-variant-numeric: tabular-nums; color: var(--text-2); white-space: nowrap;
}
.node-power .ic { width: 13px; height: 13px; color: var(--text-3); }
.node-power.gen { color: var(--ok); }
.node-power.gen .ic { color: var(--ok); }

/* Pins: hairline + 6px, then 34px rows, then 8px. */
.node-pins { border-top: 1px solid var(--line); padding: 6px 0 8px; }
.pin-row {
  position: relative; height: 34px; display: flex; align-items: center; gap: 7px;
  padding: 0 13px 0 15px; font-size: 14px; font-weight: 500;
}
.pin-row.out { padding: 0 15px 0 13px; }
.pin-row.none { color: var(--text-3); font-size: 12.5px; padding-left: 14px; }
.item-dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.pin-item { flex: 1; min-width: 0; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pin-row.out .pin-item { color: var(--text); }
.pin-rate { flex: none; font: 600 15px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.pin-rate i, .edge-flow i { font-style: normal; font-size: 12.5px; font-weight: 500; color: var(--text-2); margin-left: 2px; }
.pin-rate.short { color: #ff8c90; }
.pin-surplus { flex: none; font: 600 12px var(--mono); color: var(--info); white-space: nowrap; }
.pin-target .num { min-width: 58px; width: 6.2ch; text-align: right; padding-left: 4px; }
.pin-target .field-unit { font-size: 12.5px; color: var(--text-2); }

/* Pin dots sit exactly on the tile's outer edge: 14px dot, centre on the border. */
.pin-dot {
  position: absolute; top: 10px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--text-3); cursor: crosshair;
}
.pin-dot::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; }
.pin-dot.in { left: -8px; }
.pin-dot.out { right: -8px; border-color: var(--accent); }
.pin-dot.in.ok { border-color: var(--ok); background: #123226; }
.pin-dot.in.short { border-color: var(--danger); background: #3a1719; }
.pin-dot.out.used { background: #3d2616; }
.pin-dot:hover { transform: scale(1.3); }
.pin-dot.compat {
  transform: scale(1.35); border-color: var(--ok) !important;
  box-shadow: 0 0 0 4px rgba(62, 207, 142, 0.28);
}

/* ---------------------------------------------------------- Outpost zones */
.zone {
  position: absolute; top: 0; left: 0;
  border: 1px dashed rgba(164, 172, 184, 0.34); background: rgba(164, 172, 184, 0.035);
  border-radius: 10px; pointer-events: none; will-change: transform;
}
.zone-label {
  position: absolute; top: -14px; left: 12px; height: 28px; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 5px; padding: 0 5px 0 10px;
  background: var(--s1); border: 1px solid var(--line-2); border-radius: 7px;
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-2);
  cursor: move; pointer-events: auto; white-space: nowrap;
}
.zone-label:hover { border-color: var(--line-3); color: var(--text); }
.zone-name { overflow: hidden; text-overflow: ellipsis; }
.zone-name-input {
  width: 180px; height: 18px; border: 0; outline: none; background: transparent; padding: 0;
  font: inherit; letter-spacing: inherit; text-transform: none; color: var(--text);
}
.zone-del {
  width: 16px; height: 16px; display: grid; place-items: center; flex: none;
  border: 0; border-radius: 4px; background: transparent; color: var(--text-3);
}
.zone-del { opacity: 0.45; }
.zone-label:hover .zone-del { opacity: 1; }
.zone-del .ic { width: 11px; height: 11px; stroke-width: 2.2; }
.zone-del:hover { background: rgba(242, 85, 90, 0.16); color: var(--danger); }
.zone-resize {
  position: absolute; right: -1px; bottom: -1px; width: 16px; height: 16px;
  border-right: 2px solid var(--text-3); border-bottom: 2px solid var(--text-3);
  border-radius: 0 0 10px 0; cursor: nwse-resize; pointer-events: auto;
}
.zone-resize:hover { border-color: var(--accent); }

/* ------------------------------------------------------------ Sticky notes */
.note {
  position: absolute; top: 0; left: 0; width: 230px; border-radius: 7px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.4), inset 0 -1px 0 rgba(0, 0, 0, 0.12);
  color: #1c1917; display: flex; flex-direction: column;
  pointer-events: auto; will-change: transform;
}
.note-handle {
  height: 24px; display: flex; align-items: center; justify-content: space-between;
  padding: 0 4px 0 9px; cursor: move; border-bottom: 1px solid rgba(0, 0, 0, 0.09);
}
.note-grip { width: 14px; height: 6px; background: radial-gradient(circle, rgba(0, 0, 0, 0.32) 1px, transparent 1.4px) 0 0 / 5px 3px; }
.note-del {
  width: 20px; height: 20px; display: grid; place-items: center;
  border: 0; border-radius: 4px; background: transparent; color: rgba(28, 25, 23, 0.5);
}
.note-del .ic { width: 13px; height: 13px; stroke-width: 2.2; }
.note-del:hover { background: rgba(0, 0, 0, 0.1); color: #1c1917; }
.note textarea {
  width: 100%; min-height: 78px; border: 0; background: transparent; resize: none; overflow: hidden;
  padding: 8px 10px 10px; font-size: 14px; line-height: 1.45; color: #1c1917; outline: none;
}
.note textarea::placeholder { color: rgba(28, 25, 23, 0.42); }

/* ---------------------------------------------------------- Remote cursors */
.remote-cursor { position: absolute; top: 0; left: 0; pointer-events: none; will-change: transform; }
.cursor-tag {
  margin: 1px 0 0 11px; padding: 1px 6px; border-radius: 4px;
  font-size: 10px; font-weight: 600; color: #111; white-space: nowrap;
}

/* ----------------------------------------------------------------- Islands */
.island {
  position: absolute; z-index: 20; display: flex; align-items: center; gap: 2px;
  height: 44px; padding: 0 5px;
  background: rgba(20, 23, 28, 0.94); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04), var(--shadow);
  backdrop-filter: blur(14px) saturate(1.3);
}
.island-tl { top: var(--edge); left: var(--edge); }
.island-tr { top: var(--edge); right: var(--edge); gap: 8px; padding: 0 4px 0 10px; }
.island-tc { top: var(--edge); left: 50%; transform: translateX(-50%); }
.island-bl { bottom: var(--edge); left: var(--edge); }
.island-bc { bottom: var(--edge); left: 50%; transform: translateX(-50%); }
.island-sep { width: 1px; height: 18px; background: var(--line-2); margin: 0 4px; flex: none; }

.ib {
  height: 32px; min-width: 32px; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 7px; background: transparent; color: var(--text-2);
}
.ib:hover { background: var(--s3); color: var(--text); }
.ib:active { background: #2a303a; }
.ib:focus-visible, .btn-accent:focus-visible, .menu-item:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 1px; }
.ib.active, .ib[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.ib:disabled { opacity: 0.35; pointer-events: none; }
.ib-text { padding: 0 10px; font-size: 13px; font-weight: 500; }
.ib-sm { height: 26px; min-width: 26px; border-radius: 5px; }
.ib-sm .ic { width: 15px; height: 15px; }
.ib-danger:hover { background: rgba(242, 85, 90, 0.16); color: var(--danger); }

.btn-accent {
  height: 32px; display: inline-flex; align-items: center; gap: 6px; padding: 0 12px 0 10px;
  border: 0; border-radius: 7px; background: var(--accent); color: var(--accent-ink);
  font-size: 13px; font-weight: 600;
}
.btn-accent:hover { background: #ffa762; }
.btn-accent:active { background: #ea8840; }
.btn-accent .ic { stroke-width: 2; }

.brand { display: flex; align-items: center; gap: 7px; padding: 0 6px 0 6px; }
.brand-mark { width: 20px; height: 20px; flex: none; }
.brand-name { font-weight: 700; font-size: 13px; letter-spacing: 0.09em; }
.room {
  display: flex; align-items: center; gap: 5px; height: 30px; padding: 0 8px 0 7px;
  border: 1px solid transparent; border-radius: 6px; color: var(--text-3); cursor: text;
}
.room:hover { background: var(--s2); }
.room:focus-within { background: var(--inset); border-color: var(--accent); }
.room .ic { width: 14px; height: 14px; }
.room input {
  width: 8ch; max-width: 24ch; border: 0; outline: none; background: transparent; padding: 0;
  font: 600 13px var(--mono); color: var(--text);
}

.status { display: flex; align-items: center; gap: 7px; font-size: 12.5px; color: var(--text-2); white-space: nowrap; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-3); }
[data-level="ok"] > .status-dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(62, 207, 142, 0.16); }
[data-level="warn"] > .status-dot { background: var(--warn); box-shadow: 0 0 0 3px rgba(242, 201, 76, 0.14); }
[data-level="bad"] > .status-dot { background: var(--danger); box-shadow: 0 0 0 3px rgba(242, 85, 90, 0.16); }
.peers { display: flex; align-items: center; padding-left: 4px; }
.peer-chip {
  width: 26px; height: 26px; margin-left: -5px; border-radius: 50%;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; color: #111;
  border: 2px solid var(--s1);
}
.peer-chip.self { box-shadow: 0 0 0 1px var(--text-3); }
.name-input {
  width: 112px; height: 30px; padding: 0 8px; border: 1px solid transparent; border-radius: 6px;
  background: transparent; outline: none; font-size: 13px; font-weight: 500; color: var(--text); text-overflow: ellipsis;
}
.name-input:hover { background: var(--s2); }
.name-input:focus { background: var(--inset); border-color: var(--accent); }

.sel-count { padding: 0 6px 0 8px; font-size: 13px; font-weight: 600; white-space: nowrap; }

/* Factory summary */
.stats { gap: 0; padding: 0 14px 0 12px; color: var(--text-2); font-size: 13px; }
.stats .island-sep { margin: 0 12px; }
.stats:hover { border-color: var(--line-3); background: rgba(26, 30, 37, 0.96); }
.stat { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.stat .ic { width: 15px; height: 15px; color: var(--text-3); }
.stat b { font: 700 14px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); }
.stat i { font-style: normal; color: var(--text-3); }
.stat-status { gap: 7px; font-weight: 600; }
.stat-status[data-level="ok"] { color: var(--ok); }
.stat-status[data-level="bad"] { color: #ff8c90; }

/* Toolbar and pen options */
.pen-bar { bottom: calc(var(--edge) + 48px); left: 50%; transform: translateX(-50%); gap: 6px; padding: 0 4px 0 10px; }
.swatch {
  width: 18px; height: 18px; padding: 0; border-radius: 50%; border: 0; background: var(--c);
  box-shadow: 0 0 0 2px var(--s1), 0 0 0 3px transparent;
}
.swatch:hover { box-shadow: 0 0 0 2px var(--s1), 0 0 0 3px var(--line-3); }
.swatch.active { box-shadow: 0 0 0 2px var(--s1), 0 0 0 4px var(--c); }
.range { width: 92px; height: 18px; accent-color: var(--accent); cursor: pointer; }

/* Minimap and zoom */
.nav { position: absolute; z-index: 20; right: var(--edge); bottom: var(--edge); display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.nav .island { position: static; }
.minimap-wrap {
  width: 196px; height: 124px; overflow: hidden; cursor: crosshair;
  background: rgba(20, 23, 28, 0.94); border: 1px solid var(--line-2); border-radius: 10px;
  box-shadow: var(--shadow); backdrop-filter: blur(14px);
}
.minimap { width: 100%; height: 100%; display: block; }
.zoom-label { min-width: 54px; padding: 0 5px; font: 600 13px var(--mono); font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------ Popovers and menus */
.catch-layer { position: absolute; inset: 0; z-index: 60; }
.menu, .picker {
  position: absolute; z-index: 61;
  background: #171a20; border: 1px solid var(--line-3); border-radius: 10px;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.6), 0 2px 8px rgba(0, 0, 0, 0.4);
}
.menu { top: calc(var(--edge) + 46px); left: var(--edge); width: 216px; padding: 5px; }
.menu-item {
  width: 100%; height: 30px; display: flex; align-items: center; gap: 9px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; color: var(--text); font-size: 12.5px; text-align: left;
}
.menu-item .ic { color: var(--text-3); }
.menu-item:hover { background: var(--s3); }
.menu-item:hover .ic { color: var(--accent); }
.menu-sep { height: 1px; background: var(--line); margin: 5px -5px; }
.menu-label { padding: 4px 8px 3px; font-size: 9.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.menu-foot { display: flex; justify-content: space-between; padding: 3px 8px 2px; font-size: 11px; color: var(--text-3); }
.menu-foot span:last-child { font-family: var(--mono); font-size: 10.5px; }

.picker { width: 370px; max-height: 420px; display: flex; flex-direction: column; overflow: hidden; }
.picker.with-cats { width: min(570px, calc(100vw - 24px)); }
.picker-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px 2px; font-size: 13.5px; font-weight: 600;
}
#pickerTitle { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-count { flex: none; font: 600 11.5px var(--mono); color: var(--text-3); }
.picker-search {
  display: flex; align-items: center; gap: 7px; height: 34px; margin: 8px; padding: 0 10px;
  background: var(--inset); border: 1px solid var(--line-2); border-radius: 7px; color: var(--text-3); cursor: text;
}
.picker-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.picker-search .ic { width: 15px; height: 15px; }
.picker-search input { flex: 1; min-width: 0; border: 0; outline: none; background: transparent; padding: 0; font-size: 13.5px; color: var(--text); }
.picker-search input::placeholder { color: var(--text-3); }
.picker-body { flex: 1; min-height: 0; display: flex; border-top: 1px solid var(--line); }
.picker-cats {
  display: none; flex: none; width: 162px; padding: 5px; border-right: 1px solid var(--line);
  background: rgba(11, 13, 16, 0.45); overflow-y: auto; flex-direction: column; gap: 2px;
  scrollbar-width: thin; scrollbar-color: var(--line-3) transparent;
}
.picker.with-cats .picker-cats { display: flex; }
.picker-cat {
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  width: 100%; height: 30px; padding: 0 8px; border: 0; border-radius: 6px;
  background: transparent; color: var(--text-2); font-size: 12.5px; font-weight: 500;
  text-align: left; cursor: pointer;
}
.picker-cat:hover { background: var(--s2); color: var(--text); }
.picker-cat.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.picker-cat-left { display: flex; align-items: center; gap: 7px; min-width: 0; }
.picker-cat-left span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker-cat-dot { width: 7px; height: 7px; border-radius: 2px; flex: none; }
.picker-cat-cnt { font: 600 11px var(--mono); color: var(--text-3); flex: none; }
.picker-cat.active .picker-cat-cnt { color: var(--accent); opacity: 0.85; }
/* scroll-padding-bottom clears the 34px fade below, so keyboard focus scrolls rows out from under it. */
.picker-list {
  flex: 1; min-height: 0; overflow-y: auto; padding: 4px 5px 5px; scroll-padding: 4px 0 36px;
  scrollbar-width: thin; scrollbar-color: var(--line-3) transparent;
}
/* Fade at the bottom edge while more rows are below (toggled by syncPickerScrollCue in app.js). */
.picker-list-wrap { position: relative; flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.picker-list-wrap::after {
  content: ""; position: absolute; left: 0; right: 8px; bottom: 0; height: 34px; pointer-events: none;
  background: linear-gradient(to bottom, rgba(23, 26, 32, 0), #171a20 88%);
  opacity: 0;
}
.picker-list-wrap.more-below::after { opacity: 1; }
.picker-item {
  display: flex; align-items: center; gap: 9px; min-height: 46px; padding: 7px 9px; border-radius: 6px; cursor: pointer;
}
.picker-item.focused { background: var(--s3); }
.picker-item-main { flex: 1; min-width: 0; }
.picker-item-title { display: flex; align-items: center; gap: 6px; font-size: 13.5px; font-weight: 600; white-space: nowrap; }
.picker-item-title span:first-child { overflow: hidden; text-overflow: ellipsis; }
.picker-item-sub { font-size: 12px; line-height: 1.35; color: var(--text-3); white-space: normal; word-break: break-word; }
.picker-item-sub b { font-weight: 500; color: var(--text-2); }
.picker-item.focused .picker-item-sub { color: var(--text-2); }
.picker-item.focused .picker-item-sub b { color: var(--text); }
.picker-item .ic { color: var(--accent); }
.picker-group { padding: 8px 8px 3px; font-size: 10.5px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3); }
.picker-empty { padding: 18px 10px 20px; text-align: center; color: var(--text-3); }
.picker-foot {
  display: flex; gap: 14px; padding: 7px 12px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--text-3);
}
.picker-foot kbd { min-width: 17px; height: 17px; padding: 0 4px; font-size: 10px; line-height: 14px; margin-right: 2px; }

/* Belt popover */
.edge-pop {
  position: absolute; top: 0; left: 0; z-index: 18; height: 38px;
  display: flex; align-items: center; gap: 9px; padding: 0 6px 0 12px;
  background: #171a20; border: 1px solid var(--accent); border-radius: 9px;
  box-shadow: 0 0 0 4px var(--accent-soft), var(--shadow); white-space: nowrap; will-change: transform;
}
.edge-item { font-size: 13.5px; font-weight: 600; }
.edge-flow { font: 700 14.5px var(--mono); font-variant-numeric: tabular-nums; }
.edge-pop .tag { border-color: var(--line-3); color: var(--text-2); }
.edge-pop.over .tag { border-color: rgba(242, 85, 90, 0.55); color: #ff8c90; }
.edge-pop.short .edge-flow { color: #ff8c90; }

/* ----------------------------------------------------------------- Modals */
.modal {
  position: absolute; inset: 0; z-index: 70; display: grid; place-items: center;
  background: rgba(5, 6, 8, 0.62); backdrop-filter: blur(2px);
}
.modal-card {
  width: min(720px, 92vw); max-height: 82vh; display: flex; flex-direction: column; overflow: hidden;
  background: #171a20; border: 1px solid var(--line-3); border-radius: 12px;
  box-shadow: 0 28px 70px rgba(0, 0, 0, 0.65);
}
.modal-narrow { width: min(680px, 92vw); }
.modal-confirm { width: min(390px, 92vw); }
.confirm-body { padding: 16px; display: flex; flex-direction: column; gap: 16px; }
.confirm-body p { margin: 0; font-size: 12.5px; line-height: 1.5; color: var(--text-2); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-subtle, .btn-danger-solid {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px;
  border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.btn-subtle { background: var(--s2); border: 1px solid var(--line-2); color: var(--text-2); }
.btn-subtle:hover { background: var(--s3); color: var(--text); }
.btn-danger-solid { background: var(--danger); border: 1px solid var(--danger); color: #fff; }
.btn-danger-solid:hover { filter: brightness(1.08); }
.btn-danger-solid .ic { width: 14px; height: 14px; }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; height: 46px; padding: 0 10px 0 16px;
  border-bottom: 1px solid var(--line); font-size: 13px;
}
.totals-body, .help-body { padding: 16px; overflow-y: auto; display: grid; gap: 22px; }
.totals-body { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.3fr); }
#totalsModal .modal-card { width: min(800px, 92vw); }
.help-body { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.totals-col h4, .help-col h4 {
  margin: 0 0 7px; font-size: 11px; font-weight: 600; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-3);
}
.totals-col h4:not(:first-child) { margin-top: 18px; }
.totals-row, .help-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 32px;
  border-bottom: 1px solid var(--line); font-size: 13.5px; color: var(--text-2);
}
.totals-row span:first-child { display: flex; align-items: center; gap: 8px; min-width: 0; color: var(--text); }
.totals-row span:last-child { font: 600 14px var(--mono); font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap; }
.totals-row span:last-child i { font-style: normal; font-size: 11px; color: var(--text-3); margin-left: 2px; }
.totals-row .pos { color: var(--ok) !important; }
.totals-none { padding: 6px 0; color: var(--text-3); font-size: 12px; }
.help-row span:last-child { display: flex; gap: 4px; align-items: center; flex: none; color: var(--text-3); }

.drop-overlay {
  position: absolute; inset: 0; z-index: 80; background: rgba(8, 10, 13, 0.8);
  display: grid; place-items: center; pointer-events: none;
}
.drop-card {
  display: flex; align-items: center; gap: 12px; padding: 22px 30px;
  border: 1px dashed var(--accent); border-radius: 12px; background: var(--s1); font-size: 14px;
}
.drop-card .ic { width: 20px; height: 20px; color: var(--accent); }

.toasts {
  position: absolute; z-index: 90; left: 50%; top: calc(var(--edge) + 52px); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 8px; height: 32px; padding: 0 12px;
  background: #1c2027; border: 1px solid var(--line-3); border-radius: 8px; box-shadow: var(--shadow);
  font-size: 12px; white-space: nowrap;
}
.toast .status-dot { background: var(--ok); }
.toast[data-level="bad"] .status-dot { background: var(--danger); }
.toast[data-level="info"] .status-dot { background: var(--info); }

.tip {
  position: fixed; z-index: 100; top: 0; left: 0; pointer-events: none;
  display: flex; align-items: center; gap: 8px; height: 26px; padding: 0 5px 0 8px;
  background: #22262e; border: 1px solid var(--line-3); border-radius: 6px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5); font-size: 11.5px; color: var(--text); white-space: nowrap;
}
.tip span { padding-right: 3px; }
.tip kbd { background: var(--inset); height: 17px; line-height: 14px; }

@media (max-width: 1180px) {
  .stat i, .status span { display: none; }
  .name-input { width: 76px; }
}
@media (max-width: 920px) {
  .minimap-wrap, .name-input, #layoutBtn, #balanceAllBtn { display: none; }
}
