/* Light-reflex workspace (js/pupil-reflex/ui/rapd-workspace.js).
   Same reading order as the Krimsky and H-Test workspaces:
   toolbar → exams → steps → [eyes · coach | controls] → reference.
   Reading order changes, anatomy does not. */
#rapd-lab { padding:10px 12px; gap:10px; overflow-wrap:anywhere; min-width:0; border-radius:16px; scroll-margin-top:calc(var(--shell-header-h,110px) + 16px); }
#tabContentExam[data-exam="rapd-lab"] .exam-card { isolation:isolate; }
#rapd-lab [hidden] { display:none !important; }

/* ── Exams: four always-visible choices ─────────────────────────────── */
#rapd-lab .rpl-exams { display:grid; grid-template-columns:repeat(4,minmax(0,1fr)); gap:6px; }
#rapd-lab .rpl-exam { position:relative; display:flex; align-items:flex-start; gap:10px; min-width:0; min-height:58px; padding:10px 12px; border:1px solid var(--border-soft); border-radius:12px; background:var(--surface); color:var(--text); font:inherit; text-align:start; cursor:pointer; transition:border-color 140ms ease, background 140ms ease, box-shadow 140ms ease; }
#rapd-lab .rpl-exam:hover { border-color:var(--accent); }
#rapd-lab .rpl-exam[aria-checked="true"] { border-color:var(--accent); background:var(--accent-tint); box-shadow:inset 0 0 0 1px var(--accent); }
#rapd-lab .rpl-exam-num { display:grid; place-items:center; flex:0 0 24px; height:24px; border:1.5px solid var(--border); border-radius:50%; background:var(--surface); font:600 12px/1 var(--ct-mono, ui-monospace, monospace); color:var(--text-soft); }
#rapd-lab .rpl-exam[aria-checked="true"] .rpl-exam-num { border-color:var(--accent); background:var(--accent); color:#fff; }
#rapd-lab .rpl-exam-text { display:flex; flex-direction:column; gap:2px; min-width:0; }
#rapd-lab .rpl-exam-text strong { font-size:13px; font-weight:650; line-height:1.3; }
#rapd-lab .rpl-exam-text > span { font-size:11.5px; line-height:1.4; color:var(--text-soft); display:-webkit-box; -webkit-line-clamp:2; -webkit-box-orient:vertical; overflow:hidden; }
#rapd-lab .rpl-exam[aria-checked="true"] .rpl-exam-text strong { color:var(--accent-strong); }
#rapd-lab .rpl-exam-badge { position:absolute; top:-8px; inset-inline-end:10px; padding:1px 8px; border:1px solid var(--accent); border-radius:999px; background:var(--surface); color:var(--accent-strong); font-size:10.5px; font-weight:700; line-height:1.5; white-space:nowrap; }

/* ── Steps: one row, like the other labs ────────────────────────────── */
#rapd-lab .rpl-steprow { display:flex; align-items:center; gap:8px; padding-bottom:8px; border-bottom:1px solid var(--border-soft); }
#rapd-lab .rpl-workflow-steps { flex:1; display:grid; grid-auto-flow:column; grid-auto-columns:minmax(0,1fr); gap:4px; min-width:0; }
#rapd-lab .rpl-workflow-steps li { min-width:0; }
#rapd-lab .rpl-workflow-steps .ctc-step { min-width:0; min-height:38px; padding:5px 8px; gap:8px; border-color:var(--border-soft); border-radius:8px; text-align:start; box-sizing:border-box; }
#rapd-lab .rpl-workflow-steps .ctc-step[aria-current="step"] { border-color:var(--accent); }
#rapd-lab .rpl-workflow-steps .ctc-step:disabled { opacity:.5; cursor:default; }
#rapd-lab .rpl-workflow-steps .ctc-step-num { width:22px; height:22px; flex:0 0 22px; font-size:11px; }
#rapd-lab .rpl-workflow-steps .ctc-step-title { font-size:12px; line-height:1.3; }
#rapd-lab .rpl-restart { flex:none; display:inline-flex; align-items:center; gap:4px; min-height:36px; padding:4px 10px; border:1px solid var(--border-soft); border-radius:8px; background:var(--surface); color:var(--accent-strong); font:inherit; font-size:12px; font-weight:600; cursor:pointer; }
#rapd-lab .rpl-restart:hover { border-color:var(--accent); background:var(--accent-tint); }
#rapd-lab[data-interaction="automatic"] .rpl-restart { display:none; }

/* ── Controls column ────────────────────────────────────────────────── */
#rapd-lab .rpl-work-row { display:flex; flex-direction:column; gap:8px; min-width:0; }
#rapd-lab .rpl-side { display:flex; flex-direction:column; gap:8px; min-width:0; }
#rapd-lab .rpl-box { display:flex; flex-direction:column; gap:8px; min-width:0; margin:0; padding:10px; border:1px solid var(--border-soft); border-radius:12px; background:var(--surface); }
#rapd-lab .rpl-box-title, #rapd-lab .rpl-filter-body .rpl-card-head h4 { margin:0; font-size:10.5px; font-weight:700; letter-spacing:.08em; text-transform:uppercase; color:var(--text-soft); }
#rapd-lab .rpl-note { font-size:12px; line-height:1.55; }

#rapd-lab .rpl-setup { gap:6px; }
#rapd-lab .rpl-setup-row { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:6px 10px; }
#rapd-lab .rpl-setup-label { font-size:12px; font-weight:600; color:var(--text-soft); }
#rapd-lab .rpl-setup .ct-seg-btn { min-height:32px; padding:4px 10px; font-size:12px; }

#rapd-lab .rpl-case-prompt { background:var(--accent-tint); border-color:var(--accent); }
#rapd-lab .rpl-case-prompt p { margin:0; font-size:12.5px; line-height:1.55; }
#rapd-lab .rpl-case-buttons { display:grid; grid-template-columns:1fr 1fr; gap:6px; }

/* The penlight: the exam's primary control, large targets. */
#rapd-lab .rpl-light-buttons { display:grid; grid-template-columns:minmax(0,1fr) minmax(64px,auto) minmax(0,1fr); gap:6px; direction:ltr; }
#rapd-lab .rpl-light-btn { display:flex; flex-direction:column; align-items:center; justify-content:center; gap:2px; min-width:0; min-height:64px; padding:8px 6px; border:1px solid var(--border); border-radius:12px; background:var(--surface-sunken); color:var(--text); font:inherit; cursor:pointer; transition:background 140ms ease, border-color 140ms ease, box-shadow 140ms ease; }
#rapd-lab .rpl-light-btn:hover { border-color:var(--accent); }
#rapd-lab .rpl-light-btn bdi { font:700 17px/1.1 var(--ct-mono, ui-monospace, monospace); }
#rapd-lab .rpl-light-btn span { font-size:11px; color:var(--text-soft); }
#rapd-lab .rpl-light-btn .rpl-light-off { font-size:12px; font-weight:600; color:var(--text); }
#rapd-lab .rpl-light-btn[data-rpl-light="OD"][aria-pressed="true"],
#rapd-lab .rpl-light-btn[data-rpl-light="OS"][aria-pressed="true"] { border-color:var(--warn-strong); background:var(--warn-tint); color:var(--warn-strong); box-shadow:0 0 0 3px color-mix(in srgb, var(--warn-strong) 18%, transparent); }
#rapd-lab .rpl-light-btn[data-rpl-light="OD"][aria-pressed="true"] span,
#rapd-lab .rpl-light-btn[data-rpl-light="OS"][aria-pressed="true"] span { color:inherit; }
#rapd-lab .rpl-light-btn[data-rpl-light=""][aria-pressed="true"] { border-color:var(--accent); background:var(--accent-tint); }
#rapd-lab .rpl-near-btn { display:flex; align-items:center; justify-content:center; gap:8px; min-height:52px; padding:8px 12px; border:1px solid var(--border); border-radius:12px; background:var(--surface-sunken); color:var(--text); font:inherit; font-size:13px; font-weight:650; cursor:pointer; }
#rapd-lab .rpl-near-btn:hover { border-color:var(--accent); }
#rapd-lab .rpl-near-btn[aria-pressed="true"] { border-color:var(--accent); background:var(--accent-tint); color:var(--accent-strong); box-shadow:0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
#rapd-lab .rpl-near-icon { width:14px; height:14px; border:2px solid currentColor; border-radius:50%; box-shadow:inset 0 0 0 3px var(--surface-sunken), inset 0 0 0 7px currentColor; }
#rapd-lab .rpl-tool-hint { margin:0; font-size:12px; line-height:1.5; color:var(--text-soft); }
#rapd-lab[data-path="near"] .rpl-light-buttons,
#rapd-lab:not([data-path="near"]) #rplNear,
#rapd-lab[data-practice-step="filter"] .rpl-manual-tools,
#rapd-lab[data-practice-step="record"] .rpl-manual-tools,
#rapd-lab[data-interaction="automatic"] .rpl-manual-tools { display:none; }

#rapd-lab .rpl-filter-body { display:flex; flex-direction:column; gap:8px; }
#rapd-lab .rpl-filter-body .rpl-card-head { display:flex; justify-content:space-between; align-items:baseline; gap:8px; flex-wrap:wrap; }
#rapd-lab .rpl-filter-body .ct-seg-btn { min-height:34px; }
#rapd-lab .rpl-filter-body .rpl-step { min-height:34px; min-width:44px; }

#rapd-lab .rpl-automatic .ctc-auto { display:flex; flex-wrap:wrap; gap:6px; }
#rapd-lab .rpl-automatic .ctc-auto-btn { flex:1 1 160px; min-height:40px; }
#rapd-lab .rpl-auto-status { margin:0; font-size:12px; color:var(--accent-strong); }
#rapd-lab .rpl-auto-status:empty { display:none; }
#rapd-lab[data-interaction="manual"] .rpl-automatic,
#rapd-lab:not([data-path="swing"]):not([data-path="nd"]) .rpl-automatic { display:none; }

#rapd-lab .rpl-next:not([hidden]) { position:sticky; bottom:12px; z-index:5; align-self:stretch; justify-content:center; min-height:46px; font-size:14px; box-shadow:0 6px 18px hsl(var(--shadow-color)/.18); }

/* Live record: every step listed from the start, ticked as it is seen. */
#rapd-lab .rpl-record-list { margin:0; padding:0; list-style:none; display:flex; flex-direction:column; }
#rapd-lab .rpl-record-list li { display:flex; justify-content:space-between; align-items:center; gap:8px; padding:7px 0; font-size:12.5px; border-bottom:1px solid var(--border-soft); }
#rapd-lab .rpl-record-list li:last-child { border-bottom:0; }
#rapd-lab .rpl-record-list li strong { display:flex; align-items:center; gap:6px; font-weight:600; }
#rapd-lab .rpl-record-list li strong::before { content:""; flex:none; width:8px; height:8px; border-radius:50%; border:1.5px solid var(--border); }
#rapd-lab .rpl-record-list li[data-done="true"] strong::before { border-color:var(--accent); background:var(--accent); }
#rapd-lab .rpl-record-list li > span { font-family:var(--ct-mono, ui-monospace, monospace); font-size:12px; }
#rapd-lab .rpl-record-list li > .rpl-muted { font-family:inherit; color:var(--text-faint); }
#rapd-lab .rpl-result-actions { display:flex; flex-wrap:wrap; gap:8px; }
#rapd-lab .rpl-result-actions:not(:has(> :not([hidden]))) { display:none; }
#rapd-lab .rpl-result-actions .ct-btn { flex:1 1 auto; justify-content:center; min-height:40px; }
#rapd-lab[data-practice-step="record"] .rpl-record { border-color:var(--accent); box-shadow:inset 0 0 0 1px var(--accent); }
#rapd-lab #rplChart { direction:ltr; height:130px; }

/* Coach (shared .ctc-coach look; tone set by the workspace) */
#rapd-lab .rpl-coach { display:flex; flex-wrap:wrap; align-items:flex-start; gap:6px 8px; margin:0; padding:9px 12px; border-radius:10px; border-inline-start:3px solid currentColor; }
#rapd-lab .rpl-coach .ctc-coach-dot { display:none; }
#rapd-lab .rpl-coach .ctc-coach-body { flex:1 1 220px; min-width:0; gap:3px; }
#rapd-lab .rpl-coach .ctc-coach-body strong { font-size:15px; line-height:1.3; }
#rapd-lab .rpl-coach .ctc-coach-body > span { font-size:13px; line-height:1.5; opacity:1; }
#rapd-lab .rpl-coach .rpl-coach-status { font-size:12px !important; font-weight:600; }
#rapd-lab .rpl-coach .rpl-coach-status:empty { display:none; }
#rapd-lab #rplDwell { display:flex; align-items:center; gap:10px; font-size:11px; margin-top:4px; }
#rapd-lab #rplDwell[hidden] { display:none !important; }
#rapd-lab #rplDwellProgress { flex:1; height:6px; accent-color:currentColor; }
#rapd-lab #rplDwellLabel { white-space:nowrap; font-family:var(--ct-mono, ui-monospace, monospace); }
#rapd-lab .rpl-coach > .pin-eyes-btn { width:auto; min-height:32px; padding:4px 7px; font-size:11px; }
#rapd-lab .rpl-coach > .pin-eyes-btn .exam-toolbar__label { position:static; width:auto; height:auto; clip:auto; overflow:visible; }

/* ── Reference: optional reading, collapsed, full width ─────────────── */
#rapd-lab .rpl-workspace-details { display:grid; gap:8px; min-width:0; }
#rapd-lab .rpl-workspace-details:not(:has(> :not([hidden]))) { display:none; }
#rapd-lab .rpl-ref { margin:0; min-width:0; border:1px solid var(--border-soft); border-radius:10px; background:var(--surface); }
#rapd-lab .rpl-ref > summary { padding:11px 14px; font-size:12.5px; font-weight:600; color:var(--accent-strong); cursor:pointer; }
#rapd-lab .rpl-ref > :not(summary) { margin:0 14px 14px; }
#rapd-lab .rpl-ref .rpl-card { padding:0; border:0; background:none; display:flex; flex-direction:column; gap:8px; }
#rapd-lab .rpl-ref .rpl-card-head { display:flex; justify-content:space-between; align-items:center; gap:8px; flex-wrap:wrap; }
#rapd-lab .rpl-ref .rpl-card-head:empty { display:none; }
#rapd-lab .rpl-workspace-details > :is(.clinical-panel,.exam-secondary,#xcStrip) { margin:0; min-width:0; }
#rapd-lab .rpl-sources { padding-inline-start:18px; font-size:12px; line-height:1.7; }
#rapd-lab .rpl-table :is(th,td) { text-align:start; }
#rapd-lab :is(.rpl-confounds ul,.rpl-selfcheck-list) { padding-left:0; padding-inline-start:18px; }
#rapd-lab .rpl-steps, #rapd-lab .rpl-slider-row { direction:ltr; }

/* ── Composed workspace (rapd-workspace-layout.js) ──────────────────── */
html:not([data-sx-exam="on"]) #tabContentExam.rpl-workspace-active { max-width:1600px; padding:6px clamp(10px,2vw,28px) 32px; }
#tabContentExam.rpl-workspace-active .stage { display:flex; flex-direction:column; align-items:stretch; gap:8px; }
#rapd-lab.rpl-workspace > .exam-toolbar { margin:0; padding-bottom:6px; border-bottom:1px solid var(--border-soft); gap:6px; }
#rapd-lab.rpl-workspace .exam-toolbar__actions { gap:6px; }
#rapd-lab.rpl-workspace .track-toggle-btn { height:34px; padding:4px 8px; }
#rapd-lab.rpl-workspace .rpl-work-row { display:grid; grid-template-columns:minmax(0,1fr) minmax(330px,380px); gap:8px 16px; align-items:start; }
#rapd-lab.rpl-workspace .rpl-work-row > #examPatientWorkspace { grid-column:1; grid-row:1; display:grid; gap:8px; padding:0; margin:0; min-width:0; border:0; border-radius:10px; box-shadow:none; }
#rapd-lab.rpl-workspace .rpl-work-row > .rpl-side { grid-column:2; grid-row:1; }
#rapd-lab.rpl-workspace > .rpl-workspace-details { padding-top:8px; border-top:1px solid var(--border-soft); }
#tabContentExam.rpl-workspace-active .exam-field { max-width:clamp(400px,calc((100dvh - 440px) * 2.2),820px); width:100%; margin-inline:auto; }
#tabContentExam.rpl-workspace-active .eye-svg-wrap { max-width:300px; }

/* ── Field: pupil readings under each eye, tray centred below ───────── */
#tabContentExam[data-exam="rapd-lab"] .exam-field { padding-bottom:150px; }
#tabContentExam[data-exam="rapd-lab"] .tool-dock-container { position:absolute; bottom:40px; left:50%; transform:translateX(-50%); margin:0; }
#tabContentExam[data-exam="rapd-lab"] .eye-tag { position:absolute; top:calc(100% + 6px); left:50%; transform:translateX(-50%); width:max-content; max-width:100%; box-sizing:border-box; }
#tabContentExam[data-exam="rapd-lab"] .eye-tag .full { position:absolute; width:1px; height:1px; clip-path:inset(50%); overflow:hidden; white-space:nowrap; }
#tabContentExam[data-exam="rapd-lab"] .shine-btn { display:none; }
#tabContentExam[data-exam="rapd-lab"] .rpl-nd-overlay { z-index:100; }
.rpl-light-mark { position:absolute; transform:translate(-50%,-50%); z-index:101; border:2px solid var(--accent-strong); border-radius:50%; box-shadow:0 0 0 2px var(--surface); pointer-events:none; }
.rpl-light-mark[hidden] { display:none; }
.rpl-light-mark span { position:absolute; top:-22px; left:50%; transform:translateX(-50%); color:var(--surface); background:var(--accent-strong); border-radius:12px; padding:3px 8px; font-size:10px; font-weight:600; white-space:nowrap; }
html[data-sx-exam="on"] #rapd-lab .ct-learn, body.expert-mode #rapd-lab .ct-learn { display:none !important; }
/* Penlight vs near target: only the stimulus this exam uses is on the tray. */
html:not([data-sx-exam="on"]) body:not(.expert-mode) #tabContentExam[data-exam="rapd-lab"][data-pupil-path="near"] :is(.tool-slot[data-tool="penlight"],#penlight),
html:not([data-sx-exam="on"]) body:not(.expert-mode) #tabContentExam[data-exam="rapd-lab"]:not([data-pupil-path="near"]) #nearBtn { display:none; }

/* Not composed (embedded quiz stage): lab beside the card on wide screens. */
@media (min-width:1100px) {
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) .stage { display:grid; grid-template-columns:380px minmax(0,1fr); align-items:start; }
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) .lab-nav { grid-column:1/-1; }
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) .exam-card { grid-column:2; grid-row:2/5; padding:14px; }
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) #rapd-lab { grid-column:1; grid-row:2; }
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) :is(.clinical-panel,.exam-secondary) { grid-column:1; min-width:0; }
  #tabContentExam[data-exam="rapd-lab"]:not(.rpl-workspace-active) #rapd-lab .rpl-exams { grid-template-columns:1fr 1fr; }
}

/* ── Tablet / phone ─────────────────────────────────────────────────── */
@media (max-width:1099px) {
  #rapd-lab .rpl-exams { grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:999px) {
  #rapd-lab.rpl-workspace .rpl-work-row { display:flex; flex-direction:column; }
  #rapd-lab.rpl-workspace .rpl-work-row > :is(#examPatientWorkspace,.rpl-side) { width:100%; box-sizing:border-box; }
}
@media (max-width:700px) {
  #rapd-lab { padding:8px; }
  #rapd-lab button { min-height:44px; }
  #rapd-lab .rpl-exam { padding:8px 10px; min-height:52px; gap:8px; }
  #rapd-lab .rpl-exam-text > span { display:none; }
  #rapd-lab .rpl-exam-text strong { font-size:12.5px; }
  #rapd-lab .rpl-steprow { flex-wrap:wrap; }
  #rapd-lab .rpl-workflow-steps { flex:1 1 100%; }
  #rapd-lab .rpl-workflow-steps .ctc-step { flex-direction:column; justify-content:center; gap:3px; padding:4px 2px; text-align:center; min-height:52px; }
  #rapd-lab .rpl-workflow-steps .ctc-step-title { font-size:10.5px; }
  #rapd-lab .rpl-restart { margin-inline-start:auto; }
  #rapd-lab.rpl-workspace > .exam-toolbar { flex-wrap:wrap; }
  #rapd-lab.rpl-workspace .exam-toolbar__actions { width:100%; justify-content:flex-start; gap:5px; }
  #rapd-lab.rpl-workspace .track-toggle-btn { width:44px; height:44px; min-height:44px; padding:6px; }
  #rapd-lab.rpl-workspace .track-toggle-btn .tracking-text { display:none; }
  #tabContentExam[data-exam="rapd-lab"] .exam-field { padding-bottom:170px; }
  #tabContentExam[data-exam="rapd-lab"] .tool-dock-container { bottom:56px; }
  #rapd-lab .rpl-coach > .pin-eyes-btn { min-height:44px; }
  /* The stimulus controls come straight after the eyes; setup follows them. */
  #rapd-lab .rpl-side > .rpl-setup { order:6; }
  #rapd-lab .rpl-side > :is(.rpl-record,.rpl-trace) { order:7; }
}
