/* 56_shelf.css - KP Equipment slice C2b-2a (Fable, 10/11/2026): the Redundant shelf at the edge of the 2D plan (56_shelf.js).
 * Tokens from 01_tokens.css; the amber --shelf-* colours are set on .plan-root in 30_plan.css (light and dark).
 * PC and tablet: a pill above the scale bar (bottom-left) opens a strip along the bottom edge of the plan.
 * Phone: the pill sits bottom-right and opens a bottom sheet in the record's style. C2b-2c: on phone too it is lifted
 * above the scale bar row, so the pill and the bar never meet at any zoom; a disabled Restore is styled in 30_plan.css.
 * The wrapper takes no taps itself, so the plan stays live beside the pill. Breakpoints are `screen` scoped. */

.shelf { --shelf-bad: #b91c1c; position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: flex-start; pointer-events: none; }
[data-theme="dark"] .shelf { --shelf-bad: #fca5a5; }
.shelf[hidden] { display: none; }
body.is-moving .shelf { display: none; }

/* ---- the pill ---- */
.shelf-tab { pointer-events: auto; position: relative; z-index: 5; display: inline-flex; align-items: center; gap: var(--sp-2); min-height: 44px; margin: 0 0 46px var(--sp-4); padding: 0 var(--sp-4) 0 var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-pill); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; box-shadow: var(--shadow); cursor: pointer; }
.shelf-tab:hover { background: var(--surface-alt); }
.shelf-tab:active { background: var(--brand-soft); }
.shelf-tab:focus-visible, .shelf-open:focus-visible, .shelf-close:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.shelf-ic { flex: 0 0 auto; width: 18px; height: 18px; fill: none; stroke: var(--shelf-ink); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stage:has(> .scale[hidden]) .shelf-tab { margin-bottom: var(--sp-3); }
.shelf.is-open .shelf-tab { display: none; }

/* ---- the strip ---- */
.shelf-panel { pointer-events: auto; position: relative; z-index: 5; align-self: stretch; max-height: min(340px, 56dvh); overflow-y: auto; padding: var(--sp-2) var(--sp-4) var(--sp-3); background: var(--surface); color: var(--ink); border-top: 1px solid var(--line); box-shadow: 0 -6px 20px rgba(15, 23, 42, .10); }
[data-theme="dark"] .shelf-panel { box-shadow: 0 -6px 20px rgba(0, 0, 0, .45); }
.shelf-panel[hidden] { display: none; }
.stage.has-shelf-open .scale, .stage.has-shelf-open .hint { display: none; }
.stage.has-shelf .listwrap { padding-bottom: 76px; }

.shelf-head { display: flex; align-items: center; gap: var(--sp-2) var(--sp-3); }
.shelf-title { flex: 0 0 auto; margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--ink-soft); white-space: nowrap; }
.shelf-sub { flex: 1 1 auto; min-width: 0; margin: 0; font-size: 13px; line-height: 1.35; color: var(--ink-muted); }
.shelf-close { flex: 0 0 auto; }

.shelf-list { display: flex; gap: var(--sp-3); margin: var(--sp-2) 0 0; padding: 2px 2px 6px; list-style: none; overflow-x: auto; overscroll-behavior-x: contain; scroll-snap-type: x proximity; }
.shelf-item { flex: 0 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 2px var(--sp-3); width: min(520px, 90%); padding: 6px 10px 6px 0; border: 1px solid var(--line); border-left: 4px solid var(--shelf-edge); border-radius: var(--r); background: var(--surface); scroll-snap-align: start; }
.shelf-open { display: flex; flex-direction: column; justify-content: center; gap: 1px; min-width: 0; min-height: 60px; padding: 4px var(--sp-2) 4px var(--sp-3); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink); font: inherit; text-align: left; cursor: pointer; }
.shelf-open:hover { background: var(--surface-alt); }
.shelf-open:active { background: var(--brand-soft); }
.shelf-open:focus-visible { outline-offset: -2px; }
.shelf-id { font-family: var(--mono); font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.shelf-name { font-size: 15px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.shelf-since { font-size: 13px; line-height: 1.35; color: var(--ink-muted); overflow-wrap: anywhere; } /* C2b-2c: wraps to a second line in a narrow strip, never cut */
.shelf-item .shelf-restore { font-weight: 600; white-space: nowrap; }
.shelf-why { grid-column: 1 / -1; margin: 0; padding: 0 2px 4px var(--sp-3); font-size: 13px; line-height: 1.35; color: var(--ink-soft); overflow-wrap: anywhere; }
.shelf-why[hidden] { display: none; }
.shelf-why.is-error { color: var(--shelf-bad); font-weight: 600; }

@media (prefers-reduced-motion: no-preference) {
  .shelf-tab.is-bump { animation: shelf-bump .45s var(--ease-out); }
  .shelf-panel { animation: shelf-rise var(--dur) var(--ease-out); }
}
@keyframes shelf-bump { 0% { transform: translateY(0); } 40% { transform: translateY(-5px); } 100% { transform: translateY(0); } }
@keyframes shelf-rise { from { transform: translateY(16px); } to { transform: none; } }

/* ---- phone: pill bottom-right, the shelf is a bottom sheet ---- */
@media screen and (max-width: 700px), screen and (max-height: 500px) and (max-width: 960px) {
  .shelf { align-items: flex-end; }
  .shelf-tab { margin: 0 var(--sp-3) 46px 0; } /* C2b-2c: above the scale bar row; the bar grows with the zoom */
  @media screen and (max-width: 340px) { .shelf-tab { margin-bottom: 64px; } } /* C2b-2c: at 320 px wide the scale bar wraps to two rows, so the pill sits higher still */
  .stage:has(> .scale[hidden]) .shelf-tab { margin-bottom: var(--sp-3); }
  .shelf-panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 32; max-height: 70dvh; padding: var(--sp-3) var(--sp-4) calc(var(--sp-4) + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--line); border-radius: var(--r) var(--r) 0 0; box-shadow: var(--shadow-lg); overscroll-behavior: contain; }
  .shelf-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "title close" "sub close"; align-items: center; gap: 2px var(--sp-3); }
  .shelf-title { grid-area: title; }
  .shelf-sub { grid-area: sub; }
  .shelf-close { grid-area: close; }
  .shelf-list { flex-direction: column; gap: var(--sp-2); margin-top: var(--sp-3); overflow-x: visible; }
  .shelf-item { width: auto; grid-template-columns: minmax(0, 1fr); gap: var(--sp-1); padding: 6px 10px 10px 0; }
  .shelf-name, .shelf-since { white-space: normal; overflow-wrap: anywhere; }
  .shelf-item .shelf-restore { min-height: 48px; margin-left: var(--sp-3); font-size: 16px; }
  .shelf-why { padding-top: var(--sp-1); }
}

@media print { .shelf { display: none; } }
