/* 66_select.css - KP Equipment editor release: the looks of what is picked. F6 (the action bar) is below;
 * F5 (handles, outlines, marquee) is a later run and goes in as its own block. Nothing here styles the svg. */

/* ==== F6 (Fable, 15/11/2026): the action bar for what is picked ====
 * The bar 66_select.js draws: #sel-bar.sel-bar[role=toolbar] > .sel-bar-count, .sel-bar-btn (+ .sel-bar-<action>),
 * and the simple type list .sel-type-list inside it.
 *
 * WHERE THE BAR SITS
 * 1. PC (a mouse): floating above the selection. 66_select.js gives the place through two custom properties ON THE
 *    BAR, set with bar.style.setProperty (the CSP allows that; it only forbids style attributes in the markup):
 *      --sel-bar-x = the horizontal CENTRE of the selection, --sel-bar-y = its TOP edge, both in screen px.
 *    The bar is centred on x and hangs --sel-bar-gap (40 px, room for the rotate handle) above y. It is held on
 *    screen: never left of 8 px, never past the right edge (or the open record), never above the hint line under the edit bar, never
 *    below the plan. The script may give the plan's real edges as --sel-bar-min-y / --sel-bar-max-y /
 *    --sel-bar-max-x (screen px); without them the top is the house bar (60 px) + --editbar-h, the bottom is 48 px
 *    above the screen's foot, the right is the screen edge (less the record when it is open).
 * 2. .is-at-pointer (right-click): the same buttons as a short menu, its top-left corner at x / y, held on screen
 *    the same way.
 * 3. No x / y (a touch tablet, or the script did not place it): docked in the top-left corner of the plan, under
 *    the hint line. It is inside the stage there, so it cannot reach the edit bar, the footer or the record.
 * 4. Phone (the same breakpoint as the phone edit bar): docked across the screen right above the edit bar, whose
 *    real height is --editbar-h (measured by 65_editor.js). x / y are not used. While the record sheet is open
 *    the bar steps aside, so the two never stack.
 * The type list opens INSIDE the bar - above the buttons when the bar hangs from its bottom edge (1 and 4), under
 * them when it hangs from its top (2 and 3) - so it can never leave the screen or cover the edit bar.
 * A disabled button (.is-disabled / aria-disabled) can still be pressed - it then says why - so it looks "held back"
 * (dashed edge, grey fill, blue dot), the same look as a refused Undo. */
.sel-bar { position: absolute; left: var(--sp-3); top: calc(var(--sp-3) + 44px); z-index: 20; box-sizing: border-box; display: flex; flex-wrap: wrap; align-items: center; gap: 2px; width: max-content; max-width: calc(100% - 2 * var(--sp-3)); margin: 0; padding: 4px; border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); box-shadow: var(--shadow-lg); font-family: var(--font); font-size: 14px; line-height: 1.2; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
.sel-bar[hidden] { display: none !important; }
.sel-bar-count { display: inline-flex; align-items: center; align-self: stretch; margin-right: 2px; padding: 0 10px 0 8px; border-right: 1px solid var(--line); color: var(--ink-soft); font-size: 13px; font-weight: 600; white-space: nowrap; }
.sel-bar-btn { position: relative; box-sizing: border-box; display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 44px; min-height: 44px; margin: 0; padding: 0 10px; border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; font-weight: 500; line-height: 1.2; white-space: nowrap; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sel-bar-delete { margin-left: 7px; color: var(--danger-fg); }
.sel-bar-delete::before { content: ""; position: absolute; left: -6px; top: 7px; bottom: 7px; width: 1px; background: var(--line); }
.sel-bar-count + .sel-bar-delete { margin-left: 0; }
.sel-bar-count + .sel-bar-delete::before { display: none; }
@media (hover: hover) {
  .sel-bar-btn:hover { background: var(--surface-alt); border-color: var(--line); }
  .sel-bar-delete:hover { background: var(--danger-bg); border-color: transparent; }
  .sel-type-item:hover { background: var(--surface-alt); }
}
.sel-bar-btn:active { background: var(--brand-soft); }
.sel-bar:has(> .sel-type-list) > .sel-bar-type, .sel-bar-btn[aria-expanded="true"] { background: var(--brand-soft); border-color: var(--brand); }
.sel-bar-btn.is-disabled, .sel-bar-btn[aria-disabled="true"] { border: 1px dashed var(--ink-muted); background: var(--surface-alt); color: var(--ink-soft); cursor: help; }
.sel-bar-btn.is-disabled::after, .sel-bar-btn[aria-disabled="true"]::after { content: ""; position: absolute; top: 4px; right: 4px; width: 8px; height: 8px; border-radius: 50%; background: var(--info); }
.sel-bar-btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }

/* the simple type list (PT-PICK replaces it later, so only what it needs to be usable): a full-width row of the bar.
 * width 0 + min-width 100% keeps it from widening the bar. */
.sel-type-list { order: 1; box-sizing: border-box; flex: 0 0 auto; width: 0; min-width: 100%; max-height: min(264px, 40vh); overflow-y: auto; overscroll-behavior: contain; margin: 4px 0 0; padding: 4px 0 0; border-top: 1px solid var(--line); }
.sel-type-group { padding: 8px 10px 4px; color: var(--ink-soft); font-size: 12px; font-weight: 600; line-height: 1.3; }
.sel-type-item { box-sizing: border-box; display: flex; align-items: center; width: 100%; min-height: 44px; margin: 0; padding: 4px 10px; border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; line-height: 1.2; text-align: left; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.sel-type-item.is-current { background: var(--brand-soft); box-shadow: inset 3px 0 0 var(--brand); font-weight: 600; }
.sel-type-item:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }

/* PC and tablet: the place from 66_select.js (1) and the right-click menu (2) */
@media screen and (min-width: 700.02px) and (min-height: 500.02px), screen and (min-width: 960.02px) {
  .sel-bar[style*="--sel-bar-x"][style*="--sel-bar-y"] { --f6-min-y: calc(var(--sel-bar-min-y, calc(60px + var(--editbar-h, 65px))) + 56px); --f6-max-y: calc(var(--sel-bar-max-y, calc(100vh - 48px)) - 8px); --f6-max-x: calc(var(--sel-bar-max-x, 100vw) - 8px); position: fixed; left: 0; top: 0; max-width: calc(100vw - 16px); max-height: calc(var(--f6-max-y) - var(--f6-min-y)); overflow-y: auto; transform: translate(calc(var(--sel-bar-x) - 50%), calc(var(--sel-bar-y) - 100% - var(--sel-bar-gap, 40px))); }
  body:not(.drawer-tucked) .stage:has(~ .drawer:not([hidden])) > .sel-bar { --sel-bar-max-x: calc(100vw - var(--drawer-w, 360px)); }
  .sel-bar[style*="--sel-bar-x"][style*="--sel-bar-y"]:not(.is-at-pointer) > .sel-type-list { order: -1; margin: 0 0 4px; padding: 0 0 4px; border-top: 0; border-bottom: 1px solid var(--line); }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"][style*="--sel-bar-y"] { transform: translate(var(--sel-bar-x), var(--sel-bar-y)); flex-direction: column; flex-wrap: nowrap; align-items: stretch; gap: 1px; min-width: 208px; }
  @supports (transform: translate(clamp(1px, calc(10px - 50%), calc(100vw - 100% - 8px)), 0px)) {
    .sel-bar[style*="--sel-bar-x"][style*="--sel-bar-y"] { transform: translate(clamp(8px, calc(var(--sel-bar-x) - 50%), calc(var(--f6-max-x) - 100%)), clamp(var(--f6-min-y), calc(var(--sel-bar-y) - 100% - var(--sel-bar-gap, 40px)), calc(var(--f6-max-y) - 100%))); }
    .sel-bar.is-at-pointer[style*="--sel-bar-x"][style*="--sel-bar-y"] { transform: translate(clamp(8px, var(--sel-bar-x), calc(var(--f6-max-x) - 100%)), clamp(var(--f6-min-y), var(--sel-bar-y), calc(var(--f6-max-y) - 100%))); }
  }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-bar-count { align-self: auto; min-height: 32px; margin: 0 0 3px; padding: 0 9px; border-right: 0; border-bottom: 1px solid var(--line); }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-bar-btn { justify-content: flex-start; }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-bar-delete { margin: 7px 0 0; }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-bar-delete::before { left: 4px; right: 4px; top: -5px; bottom: auto; width: auto; height: 1px; }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-bar-count + .sel-bar-delete { margin: 0; }
  .sel-bar.is-at-pointer[style*="--sel-bar-x"] > .sel-type-list { flex: 0 1 auto; min-height: 92px; }
}

/* Phone (4): docked above the edit bar. Equal columns, so a button keeps its size whatever is picked. */
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .sel-bar { position: fixed; left: 0; right: 0; top: auto; bottom: var(--editbar-h, calc(72px + env(safe-area-inset-bottom, 0px))); display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); align-items: stretch; gap: 4px; width: auto; max-width: none; padding: 6px; border-width: 1px 0 0; border-radius: 0; box-shadow: 0 -6px 16px rgba(15,23,42,.10); }
  [data-theme="dark"] .sel-bar { box-shadow: 0 -6px 16px rgba(0,0,0,.40); }
  .sel-bar-count { grid-column: 1 / -1; align-self: auto; margin: 0; padding: 0 4px 1px; border: 0; line-height: 1.35; white-space: normal; }
  .sel-bar-btn { min-width: 0; min-height: 48px; padding: 4px 3px; border-color: var(--line); font-size: 13px; line-height: 1.15; white-space: normal; text-align: center; overflow-wrap: anywhere; }
  .sel-bar-delete { margin: 0; }
  .sel-bar-delete::before { display: none; }
  .sel-type-list { grid-column: 1 / -1; order: -1; width: auto; min-width: 0; max-height: min(320px, 44dvh); margin: 0 0 2px; padding: 0 0 4px; border-top: 0; border-bottom: 1px solid var(--line); }
  .stage:has(~ .drawer:not([hidden])) .sel-bar { display: none; }
}
/* N1-10 (D353): while a machine is being moved the move bar is the only control bar (50_plan sets body.is-moving with state.moving). */
body.is-moving .sel-bar { display: none !important; }
@media screen and (max-width: 560px) { .sel-bar { bottom: var(--editbar-h, calc(124px + env(safe-area-inset-bottom, 0px))); } }
@media screen and (max-height: 500px) and (min-width: 560.02px) and (max-width: 960px) { .sel-bar-count { grid-column: auto; align-self: center; } }
@media print { .sel-bar { display: none !important; } }

/* ==== F12d (Fable, 15/11/2026): the selection as it is drawn ON THE PLAN (the F5 look) ====
 * Until this block nothing styled what the scripts draw in the svg, so it painted with the svg defaults: a solid
 * black box over the picked item, black handles, black touch discs and a black selection box.
 * WHAT THE SCRIPTS REALLY SET (grep 15/11):
 *   66_select.js  g#sel-handles.sel-handles > rect.sel-frame, then for each handle a drawn shape and its press target:
 *                 .sel-handle + .sel-hit, both with .sel-resize.sel-ns|ew|nwse|nesw (8, square), .sel-rotate (1, round)
 *                 or .sel-corner[.is-picked] (Edit corners, round). body.is-handle-drag while a handle is dragged.
 *   50_plan.js    .is-edit-selected on every picked node (a .machine, a .loose-shape, or one shape inside a machine),
 *                 rect.sel-ring per picked item (30_plan.css draws it dashed), rect.marquee-box while a selection box
 *                 is dragged, svg.is-part-mode + .machine.is-part-open inside a machine, svg.is-dragging while the
 *                 picked items are being moved.
 * SIZES are the script's (12 px drawn; press target 44 px on touch, 12 px with a mouse) and are re-drawn per zoom.
 * This block only paints. Every line is non-scaling, so it is the same thickness at every zoom.
 * COLOUR: a handle is white with a solid blue edge in BOTH themes. One of the two always stands off what is under
 * it (white plan, dark plan, any machine colour). Frames and outlines use --brand, which follows the theme.
 * SHAPE carries the meaning, not colour alone: square = resize, solid round dot above the box = turn, round on a
 * corner = a corner you can drag (solid = the picked one). */

/* the box round the one picked item, its handles, and the unseen press targets */
#sel-handles .sel-frame { fill: none; stroke: var(--brand); stroke-width: 1.5px; vector-effect: non-scaling-stroke; pointer-events: none; }
#sel-handles .sel-handle { fill: #ffffff; stroke: var(--brand-solid, #2563eb); stroke-width: 1.5px; vector-effect: non-scaling-stroke; pointer-events: none; }
#sel-handles .sel-hit { fill: transparent; stroke: none; pointer-events: all; touch-action: none; }
/* the turn handle: a solid dot with a white rim (the rim is painted first, so the dot keeps its 12 px) */
#sel-handles .sel-handle.sel-rotate { fill: var(--brand-solid, #2563eb); stroke: #ffffff; stroke-width: 3px; paint-order: stroke; }
/* Edit corners: a round handle on each corner, the picked one solid. The box steps back to a faint dashed line. */
#sel-handles .sel-handle.sel-corner { stroke-width: 2px; }
#sel-handles .sel-handle.sel-corner.is-picked { fill: var(--brand-solid, #2563eb); stroke: #ffffff; stroke-width: 3px; paint-order: stroke; }
#sel-handles:has(> .sel-corner) > .sel-frame { stroke-width: 1px; stroke-dasharray: 3 3; opacity: .7; }
/* one picked item shows the frame and handles; the dashed ring from 30_plan.css stays for several picked items */
#layer-sel:has(~ #sel-handles > .sel-frame) .sel-ring { display: none; }

/* the pointer says what a handle does (a mouse only sees these) */
#sel-handles .sel-hit.sel-ns { cursor: ns-resize; }
#sel-handles .sel-hit.sel-ew { cursor: ew-resize; }
#sel-handles .sel-hit.sel-nwse { cursor: nwse-resize; }
#sel-handles .sel-hit.sel-nesw { cursor: nesw-resize; }
#sel-handles .sel-hit.sel-rotate { cursor: grab; }
#sel-handles .sel-hit.sel-corner { cursor: move; }
body.is-handle-drag #sel-handles .sel-hit.sel-rotate { cursor: grabbing; }

/* hover, PC only: the handle under the pointer tints (the drawn shape sits right before its press target) */
@media (hover: hover) and (pointer: fine) {
  #sel-handles .sel-handle:has(+ .sel-hit:hover) { fill: #bfdbfe; }
  #sel-handles .sel-handle.sel-rotate:has(+ .sel-hit:hover), #sel-handles .sel-handle.sel-corner.is-picked:has(+ .sel-hit:hover) { fill: var(--brand-solid-hover, #1d4ed8); }
}

/* the selection box dragged over empty plan */
#layer-sel .marquee-box { fill: var(--brand); fill-opacity: .1; stroke: var(--brand); stroke-width: 1.5px; stroke-dasharray: 4 3; vector-effect: non-scaling-stroke; pointer-events: none; }

/* a picked item: the same thicker blue edge a selected machine has in view mode. A band's width is its geometry,
 * so a band only changes colour. */
.plan-svg .is-edit-selected .shp, .plan-svg .shp.is-edit-selected, .plan-svg .loose-shape.is-edit-selected { stroke: var(--brand); stroke-width: 2.5px; vector-effect: non-scaling-stroke; }
.plan-svg .is-edit-selected .band-edge, .plan-svg .band-edge.is-edit-selected { stroke: var(--brand); }

/* inside a machine (part mode): the rest of the plan steps back, the open machine's shapes are outlined dashed and
 * see-through, the picked shape is solid again */
.plan-svg.is-part-mode .machine:not(.is-part-open), .plan-svg.is-part-mode .loose-shape, .plan-svg.is-part-mode #layer-unmatched { opacity: .35; }
.plan-svg.is-part-mode #layer-areas, .plan-svg.is-part-mode #layer-decor { opacity: .5; }
.plan-svg.is-part-mode .machine.is-part-open .shp { fill-opacity: .45; stroke: var(--brand); stroke-width: 1.5px; stroke-dasharray: 5 3; }
.plan-svg.is-part-mode .machine.is-part-open .band-edge { stroke: var(--brand); }
.plan-svg.is-part-mode .machine.is-part-open .shp.is-edit-selected, .plan-svg.is-part-mode .machine.is-part-open .is-edit-selected .shp { fill-opacity: 1; stroke-width: 2.5px; stroke-dasharray: none; }

/* lifted: while the picked items are being moved they go a little see-through with a heavier edge. No shadow on
 * purpose - a filter here is measured in plan metres and would be redrawn on every move. */
.plan-svg.is-dragging .is-edit-selected .shp, .plan-svg.is-dragging .shp.is-edit-selected, .plan-svg.is-dragging .loose-shape.is-edit-selected { fill-opacity: .8; stroke-width: 3.5px; }
/* while they are moved the frame and handles step out of the way: the script leaves them at the start place until
 * the drop, and a frame with handles round empty plan reads as a second item. Never during a handle drag - there
 * the frame IS what is being changed. */
body:not(.is-handle-drag) .plan-svg.is-dragging #sel-handles { visibility: hidden; }

@media (forced-colors: active) {
  #sel-handles .sel-frame, #layer-sel .marquee-box { stroke: Highlight; }
  #sel-handles .sel-handle { fill: Canvas; stroke: Highlight; }
  #sel-handles .sel-handle.sel-rotate, #sel-handles .sel-handle.sel-corner.is-picked { fill: Highlight; stroke: Canvas; }
}
@media print { #sel-handles, #layer-sel .marquee-box { display: none !important; } }

/* ==== H-A (Fable, 16/11/2026): the release panel on a phone (.sel-bar.is-ungroup, drawn by 66_select.js) ====
 * Until this block nothing laid the panel out, so it took the action bar's equal columns: the tick-list sat in one
 * 97 px column, each name wrapped to 3 to 7 lines, and a 22-shape machine made a panel 1994 px tall that ran off the
 * top of the screen and could not scroll.
 * Now, top to bottom: the count line; the list (one 48 px row per shape with a 20 px tick, no bullets, its own
 * scroll); the reason, full width; then Cancel | Release side by side, 48 px, always on screen.
 * HEIGHT: the panel still hangs from the edit bar, and it stops --ug-top below the top of the screen (116 px = the
 * house bar, one or two rows on a phone, plus the chip row), so it never covers the bar. The list takes what is left,
 * at most 60% of the screen. If not even two rows fit (a phone on its side), the whole panel scrolls instead.
 * Phone only: html[data-device="phone"], inside the breakpoint that docks the bar. PC and tablet do not move. */
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  html[data-device="phone"] .sel-bar.is-ungroup { --ug-top: 116px; --ug-vh: 100vh; --ug-room: calc(var(--ug-vh) - var(--dft-dock, var(--editbar-h, 124px)) - var(--dft-h, 0px) - var(--ug-top));
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: auto minmax(50px, 1fr) auto auto; gap: 6px 8px; padding: 8px; max-height: max(160px, var(--ug-room)); overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; }
  @supports (height: 100dvh) { html[data-device="phone"] .sel-bar.is-ungroup { --ug-vh: 100dvh; } }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-bar-count { grid-column: 1 / -1; grid-row: 1; align-self: auto; padding: 0 2px; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-list { grid-column: 1 / -1; grid-row: 2; box-sizing: border-box; min-height: 0; max-height: max(98px, min(calc(var(--ug-vh) * 0.6), calc(var(--ug-room) - 132px))); margin: 0; padding: 0; list-style: none; overflow-x: hidden; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--r-sm); background: var(--surface); }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-row { box-sizing: border-box; display: flex; align-items: center; gap: 12px; min-height: 48px; margin: 0; padding: 0 12px; border-top: 1px solid var(--line); list-style: none; }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-row:first-child { border-top: 0; }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-row > label { flex: 1 1 auto; align-self: stretch; display: flex; align-items: center; gap: 12px; min-width: 0; margin: 0 -12px; padding: 0 12px; cursor: pointer; }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-tick { flex: none; width: 20px; height: 20px; margin: 0; accent-color: var(--brand-solid, #2563eb); }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-tick:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
  html[data-device="phone"] .sel-bar.is-ungroup .sel-ug-name { flex: 1 1 auto; min-width: 0; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden; overflow-wrap: anywhere; color: var(--ink); font-size: 14px; line-height: 1.3; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-reason { grid-column: 1 / -1; grid-row: 3; padding: 0 2px; color: var(--ink-soft); font-size: 13px; line-height: 1.35; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-cancel { grid-column: 1; grid-row: 4; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-release { grid-column: 2; grid-row: 4; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-cancel, html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-release { min-height: 48px; padding: 4px 8px; border-radius: var(--r-sm); font-size: 15px; font-weight: 600; }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-release:not(.is-disabled):not([aria-disabled="true"]) { background: var(--navy); border-color: var(--navy); color: #ffffff; }
  html[data-device="phone"][data-theme="dark"] .sel-bar.is-ungroup > .sel-ug-release:not(.is-disabled):not([aria-disabled="true"]) { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
  html[data-device="phone"] .sel-bar.is-ungroup > .sel-ug-release:not(.is-disabled):not([aria-disabled="true"]):active { filter: brightness(.9); }
}
@media screen and (max-height: 500px) and (max-width: 960px) { html[data-device="phone"] .sel-bar.is-ungroup { --ug-top: 60px; } }
/* ==== end H-A ==== */
