/* 82_part_pick.css - T63 (Fable): pick-a-part mode and the TEST maintenance request (82_part_pick.js).
 * One full-screen layer over the plan, the same house look as the parts editor (81_parts_editor.css).
 * Tokens from 01_tokens.css only. Phone first: the model on top (about two fifths of the screen), the numbered list
 * under it, the picked part and its one button in a bar at the foot.
 * T66a (design pass): the layout follows the SHAPE of the screen, not only its width.
 *  - upright (phone, tablet held upright): model on top, list under it; from 700 px the model takes more of the
 *    height and the list runs in two columns (three from 1000 px), read left to right.
 *  - on its side (from 560 px wide: phone on its side, tablet on its side, desktop): the model on the left, the list
 *    and the bar in a column on the right; on a short screen (520 px or less) the bars and rows tighten.
 * The DOM order is the order on screen at every size, so the focus order follows it. Every breakpoint is `screen`
 * scoped. Touch targets are at least 44 px. The number on the model and the number in the list share one colour, so
 * they read as one thing. No control sits on the model except its own numbers. */

.pp-root { position: fixed; inset: 0; z-index: 600; display: flex; flex-direction: column; background: var(--bg); color: var(--ink); font-family: var(--font); font-size: 16px; line-height: 1.4; }
.pp-root[hidden], .pp-root [hidden] { display: none !important; }
.pp-root *, .pp-root *::before, .pp-root *::after { box-sizing: border-box; }
.pp-root button { -webkit-tap-highlight-color: transparent; }
.pp-root :focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
/* a heading is focused after a change of step so a screen reader starts there; it is not a control */
.pp-root h1:focus, .pp-root h1:focus-visible, .pp-root h2:focus, .pp-root h2:focus-visible { outline: none !important; box-shadow: none !important; }
.pp-ic { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- head: the house bar ---- */
.pp-head { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-2) var(--sp-4); padding-top: max(var(--sp-2), env(safe-area-inset-top)); background: var(--kp-bar); color: var(--kp-bar-ink); box-shadow: var(--kp-bar-shadow); position: relative; z-index: 1; }
.pp-head :focus-visible { outline-color: var(--kp-bar-ring); }
.pp-title { flex: 1 1 0; min-width: 0; }
.pp-h1 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-sub { margin: 0; font-size: 13px; color: var(--kp-bar-ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-bar-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; min-height: 44px; min-width: 44px; padding: 0 var(--sp-4); border: 1px solid var(--kp-bar-line); border-radius: var(--r-pill); background: var(--kp-bar-tint); color: var(--kp-bar-ink); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; }
.pp-back { padding: 0; }
.pp-lbl-narrow { display: none; }
.pp-count { min-width: 22px; padding: 1px 6px; border-radius: var(--r-pill); background: var(--kp-bar-on); color: var(--navy); font-size: 13px; font-weight: 700; text-align: center; font-variant-numeric: tabular-nums; }
[data-theme="dark"] .pp-count { color: var(--on-brand); }

/* ---- the TEST strip: always in view, so nobody takes this for a real request ---- */
.pp-strip { display: flex; align-items: center; gap: var(--sp-2); margin: 0; padding: var(--sp-2) var(--sp-4); background: var(--warning-bg); color: var(--ink); border-bottom: 1px solid var(--warning); font-size: 14px; }
.pp-tag { display: inline-flex; align-items: center; flex: none; padding: 2px 10px; border: 1px solid transparent; border-radius: var(--r-pill); font-size: 13px; font-weight: 700; line-height: 1.4; white-space: nowrap; }
.pp-tag-test { background: var(--surface); border-color: var(--warning); color: var(--warning-fg); letter-spacing: .04em; }
.pp-tag-low { background: var(--surface-alt); border-color: var(--line); color: var(--ink-soft); }
.pp-tag-normal { background: var(--info-bg); border-color: var(--info); color: var(--info); }
.pp-tag-stop { background: var(--danger-bg); border-color: var(--danger); color: var(--danger-fg); }

/* ---- body ---- */
.pp-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
/* nothing on the model can be selected as text or called out by a long press: a gloved press is a press */
.pp-stage { position: relative; flex: none; height: 38vh; min-height: 220px; overflow: hidden; background: var(--surface-alt); border-bottom: 1px solid var(--line); touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.pp-canvas { display: block; width: 100%; height: 100%; touch-action: none; outline: none; }
.pp-stage-msg { position: absolute; inset: 0; display: grid; place-items: center; margin: 0; padding: var(--sp-4); color: var(--ink-soft); font-size: 15px; text-align: center; pointer-events: none; }
/* clip, not hidden: a focused number near the edge must never scroll the layer away from the model under it */
.pp-pins { position: absolute; inset: 0; overflow: hidden; overflow: clip; pointer-events: none; }
.pp-pin { position: absolute; left: 0; top: 0; display: grid; place-items: center; width: 44px; height: 44px; margin: -22px 0 0 -22px; padding: 0; border: 0; border-radius: 50%; background: none; font: inherit; cursor: pointer; pointer-events: auto; touch-action: manipulation; }
.pp-pin-dot { display: grid; place-items: center; width: 28px; height: 28px; border: 2px solid var(--paper); border-radius: 50%; background: var(--brand-solid); color: var(--paper); font-size: 14px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; box-shadow: var(--shadow); }
/* the other numbers go quiet (outline only) so the picked one stands out; still dark on light, light on dark */
.pp-pins.has-sel .pp-pin[aria-pressed="false"] .pp-pin-dot { border-color: var(--ink-muted); background: var(--surface); color: var(--ink); box-shadow: none; }
/* the picked number sits over its neighbours */
.pp-pin[aria-pressed="true"] { z-index: 1; }
.pp-pin[aria-pressed="true"] .pp-pin-dot { width: 36px; height: 36px; font-size: 16px; box-shadow: 0 0 0 3px var(--brand-solid), var(--shadow-lg); }
.pp-pin:focus-visible { outline-offset: -2px; }

.pp-side { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-4); }
.pp-h2 { margin: 0; font-size: 18px; font-weight: 600; line-height: 1.3; }
.pp-hint { margin: 0; color: var(--ink-soft); font-size: 15px; }
.pp-small { font-size: 13px; }
.pp-list { display: flex; flex-direction: column; gap: var(--sp-2); margin: 0; padding: 0; list-style: none; }
.pp-row { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 56px; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; box-shadow: var(--shadow-sm); touch-action: manipulation; }
.pp-row:active { border-color: var(--brand); }
.pp-row[aria-pressed="true"] { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.pp-num { display: grid; place-items: center; flex: none; width: 32px; height: 32px; border-radius: 50%; background: var(--brand-solid); color: var(--paper); font-size: 15px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.pp-row-text { display: flex; flex-direction: column; flex: 1 1 auto; min-width: 0; }
.pp-name { font-weight: 600; overflow-wrap: anywhere; }
.pp-code { color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; }
.pp-code.is-pending { font-style: italic; }

/* ---- the picked part and its one button: a bar of its own under the list, never over it ---- */
.pp-bar { flex: none; display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -2px 8px rgba(15,23,42,.06); }
.pp-bar-text { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-3); flex: 1 1 auto; min-width: 0; min-height: 44px; }
.pp-bar-text .pp-row-text { flex: 1 1 0; }
.pp-bar-none { margin: 0; color: var(--ink-soft); font-size: 15px; }
.pp-bar-miss { flex: 1 1 100%; margin: 0; color: var(--ink-soft); font-size: 13px; }
.pp-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; flex: none; min-height: 44px; padding: 0 var(--sp-4); border: 1px solid var(--ink-muted); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-weight: 600; white-space: nowrap; cursor: pointer; touch-action: manipulation; }
.pp-btn-primary { border-color: var(--brand-solid); background: var(--brand-solid); color: var(--paper); }
.pp-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---- what is wrong ---- */
.pp-form, .pp-done { display: flex; flex-direction: column; gap: var(--sp-4); }
.pp-picked { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3); border: 1px solid var(--brand); border-radius: var(--r); background: var(--brand-soft); }
.pp-field { display: flex; flex-direction: column; gap: 6px; }
.pp-label { padding: 0; font-size: 15px; font-weight: 600; }
.pp-textarea { display: block; width: 100%; min-height: 112px; padding: var(--sp-3); border: 1px solid var(--ink-muted); border-radius: var(--r); background: var(--surface); color: var(--ink); font: inherit; font-size: 16px; line-height: 1.4; resize: vertical; }
.pp-textarea[aria-invalid="true"] { border-color: var(--danger); box-shadow: inset 0 0 0 1px var(--danger); }
.pp-err { margin: 0; color: var(--danger-fg); font-size: 14px; font-weight: 600; }
.pp-urg { display: flex; flex-direction: column; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.pp-urg-opts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-2); }
.pp-opt { position: relative; display: flex; flex-direction: column; justify-content: center; min-height: 64px; padding: var(--sp-2) var(--sp-3); border: 1px solid var(--ink-muted); border-radius: var(--r); background: var(--surface); cursor: pointer; }
.pp-opt input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
.pp-opt:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); box-shadow: inset 0 0 0 1px var(--brand); }
.pp-opt.is-stop:has(input:checked) { border-color: var(--danger); background: var(--danger-bg); box-shadow: inset 0 0 0 1px var(--danger); }
.pp-opt:has(input:focus-visible) { outline: 2px solid var(--brand); outline-offset: 2px; }
.pp-opt-name { font-weight: 600; }
.pp-opt-sub { color: var(--ink-soft); font-size: 13px; line-height: 1.3; }
.pp-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--sp-2); }
.pp-actions-start { justify-content: flex-start; }
.pp-tick { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 50%; background: var(--success-bg); color: var(--success-fg); }

/* ---- one column: the saved test requests, and the "nothing here yet" states ---- */
.pp-single { display: block; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: var(--sp-4); padding-bottom: max(var(--sp-4), env(safe-area-inset-bottom)); }
.pp-wrap { display: flex; flex-direction: column; gap: var(--sp-3); max-width: 720px; margin: 0 auto; }
.pp-empty { display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); max-width: 480px; margin: var(--sp-6) auto 0; padding: var(--sp-5); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); text-align: center; }
.pp-empty .pp-ic { width: 32px; height: 32px; color: var(--ink-muted); }
.pp-reqs { display: grid; gap: var(--sp-3); margin: 0; padding: 0; list-style: none; }
.pp-req { display: flex; flex-direction: column; gap: var(--sp-2); padding: var(--sp-3) var(--sp-4); border: 1px solid var(--line); border-radius: var(--r); background: var(--surface); box-shadow: var(--shadow-sm); }
.pp-req-top { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2); }
.pp-req-date { margin-left: auto; color: var(--ink-soft); font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pp-req-part { display: flex; align-items: center; gap: var(--sp-3); }
.pp-req-note { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.pp-req-via { margin: 0; color: var(--ink-soft); font-size: 13px; }

/* ---- the way in, under the machine record ---- */
.pp-entry { display: flex; flex-direction: column; align-items: flex-start; gap: var(--sp-2); margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px solid var(--line); }
.pp-entry[hidden] { display: none; }
.pp-entry-btn { display: inline-flex; align-items: center; gap: 6px; min-height: 44px; }
.pp-entry-note { margin: 0; color: var(--ink-soft); font-size: 13px; }

/* ---- a mouse over a control (never on touch, where a hover would stick) ---- */
@media screen and (hover: hover) {
  .pp-row:hover { border-color: var(--ink-muted); }
  .pp-row[aria-pressed="true"]:hover { border-color: var(--brand); }
  .pp-btn:not(:disabled):hover { border-color: var(--ink); }
  .pp-btn-primary:not(:disabled):hover { border-color: var(--brand-solid-hover, var(--brand-solid)); background: var(--brand-solid-hover, var(--brand-solid)); }
  .pp-pin[aria-pressed="false"]:hover .pp-pin-dot { box-shadow: 0 0 0 3px var(--brand-soft), var(--shadow); }
}

/* ---- phone ---- */
@media screen and (max-width: 700px) {
  .pp-head { gap: var(--sp-2); padding-left: var(--sp-3); padding-right: var(--sp-3); }
  .pp-reqbtn { padding: 0 var(--sp-3); }
  .pp-lbl-wide { display: none; }
  .pp-lbl-narrow { display: inline; }
  .pp-strip { padding-left: var(--sp-3); padding-right: var(--sp-3); font-size: 13px; }
  /* while typing, the whole screen is the form: the picked part stays named in its card */
  .pp-root[data-step="form"] .pp-stage, .pp-root[data-step="saved"] .pp-stage { display: none; }
  .pp-actions .pp-btn { flex: 1 1 auto; }
}

/* ---- upright and wide (a tablet held upright): more of the height for the model, the list in columns ---- */
@media screen and (orientation: portrait) and (min-width: 700px) {
  /* only while picking: the form under it keeps the room it had */
  .pp-root[data-step="pick"] .pp-stage { height: 46vh; }
  .pp-side { padding: var(--sp-4) var(--sp-5); }
  .pp-bar { padding-left: var(--sp-5); padding-right: var(--sp-5); }
  .pp-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-2) var(--sp-3); }
}
@media screen and (orientation: portrait) and (min-width: 1000px) {
  .pp-list { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

/* ---- on its side (phone, tablet, desktop): the model beside the list ---- */
@media screen and (orientation: landscape) and (min-width: 560px) {
  .pp-body:not(.pp-single) { display: grid; grid-template-columns: minmax(0, 1fr) clamp(300px, 36%, 440px); grid-template-rows: minmax(0, 1fr) auto; }
  .pp-stage { grid-column: 1; grid-row: 1 / span 2; height: auto; min-height: 0; border-bottom: 0; border-right: 1px solid var(--line); }
  .pp-side { grid-column: 2; grid-row: 1; }
  .pp-bar { grid-column: 2; grid-row: 2; }
  .pp-root[data-model="none"] .pp-body:not(.pp-single) { grid-template-columns: minmax(0, 720px); justify-content: center; }
  .pp-root[data-model="none"] .pp-side, .pp-root[data-model="none"] .pp-bar { grid-column: 1; }
}
@media screen and (orientation: landscape) and (min-width: 900px) {
  .pp-side { padding: var(--sp-5) var(--sp-4); }
}
@media screen and (min-width: 900px) {
  .pp-single { padding: var(--sp-5); }
}

/* ---- on its side and short (a phone on its side): tighter bars and rows, so the model and the list both have room ---- */
@media screen and (orientation: landscape) and (min-width: 560px) and (max-height: 520px) {
  .pp-head { padding-top: max(2px, env(safe-area-inset-top)); padding-bottom: 2px; padding-left: max(var(--sp-3), env(safe-area-inset-left)); padding-right: max(var(--sp-3), env(safe-area-inset-right)); }
  .pp-h1 { font-size: 16px; }
  .pp-strip { padding-top: 3px; padding-bottom: 3px; padding-left: max(var(--sp-3), env(safe-area-inset-left)); padding-right: max(var(--sp-3), env(safe-area-inset-right)); font-size: 13px; }
  .pp-body:not(.pp-single) { grid-template-columns: minmax(0, 1fr) clamp(300px, 42%, 400px); }
  .pp-side { gap: var(--sp-2); padding: var(--sp-3); padding-right: max(var(--sp-3), env(safe-area-inset-right)); }
  .pp-h2 { font-size: 16px; }
  .pp-hint { font-size: 14px; }
  .pp-row { min-height: 48px; padding-top: var(--sp-1); padding-bottom: var(--sp-1); }
  .pp-bar { padding: var(--sp-2) var(--sp-3); padding-right: max(var(--sp-3), env(safe-area-inset-right)); padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom)); }
}
/* wherever the model is put away for the form (a narrow or a short screen on its side), the form takes one centred column */
@media screen and (orientation: landscape) and (min-width: 560px) and (max-width: 700px), screen and (orientation: landscape) and (min-width: 560px) and (max-height: 520px) {
  .pp-root[data-step="form"] .pp-stage, .pp-root[data-step="saved"] .pp-stage { display: none; }
  .pp-root[data-step="form"] .pp-body:not(.pp-single), .pp-root[data-step="saved"] .pp-body:not(.pp-single) { grid-template-columns: minmax(0, 720px); justify-content: center; }
  .pp-root[data-step="form"] .pp-side, .pp-root[data-step="saved"] .pp-side { grid-column: 1; }
}
