/* Persistent preview shares the lab rig and framebuffer; it has no run state. */
:root { --lab-preview-inset: 0px; }
html { scroll-padding-bottom: calc(var(--lab-preview-inset) + 28px + env(safe-area-inset-bottom, 0px)); }
.shell { padding-bottom: calc(92px + var(--lab-preview-inset) + env(safe-area-inset-bottom, 0px)); }
.lab-workspace-main :is(input, select, textarea, button, a, summary, [tabindex]) {
  scroll-margin-bottom: calc(var(--lab-preview-inset) + 28px + env(safe-area-inset-bottom, 0px));
}

.lab-preview {
  position: relative;
  flex: 0 0 auto;
  min-width: 0;
  margin-top: 12px;
  padding: 8px;
  border: 1px solid #36565b;
  border-radius: 11px;
  background: #10212d;
  color: #e3edf5;
  direction: rtl;
}
.lab-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 27px;
  margin-bottom: 4px;
}
.lab-preview-header > strong { min-width: 0; font-size: 12px; line-height: 1.6; font-weight: 650; }
.lab-preview-tools { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.lab-preview-tools :is(a, button) {
  display: grid;
  place-items: center;
  width: 27px;
  height: 27px;
  padding: 0;
  border: 1px solid #3c5569;
  border-radius: 6px;
  background: #172c3b;
  color: #bdcfdf;
  font: 18px/1 var(--sans);
  text-decoration: none;
  cursor: pointer;
}
.lab-preview-tools :is(a, button):hover { color: #a3f1db; border-color: #5d9989; background: #1c3a3d; }
.lab-preview[data-collapsed="true"] .lab-preview-header { margin-bottom: 0; }
#labPreviewBody { min-width: 0; }
.lab-preview-scenes { position: relative; min-width: 0; }
.lab-preview-robot {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid #29414f;
  border-radius: 7px;
  background: #09131e;
}
#labPreview3D { display: block; width: 100%; height: 130px; object-fit: contain; touch-action: pan-y; }
#labPreviewStatus {
  position: absolute;
  top: 6px;
  right: 6px;
  left: 6px;
  max-height: 42px;
  overflow: auto;
  margin: 0;
  padding: 4px 6px;
  border-radius: 5px;
  color: #c0d5e4;
  background: #0c1a27eb;
  font-size: 9px;
  line-height: 1.6;
  text-align: center;
}
.lab-preview-lcd {
  position: absolute;
  left: 5px;
  bottom: 5px;
  width: 74px;
  padding: 3px 3px 1px;
  border: 1px solid #47635f;
  border-radius: 5px;
  background: #102127;
}
#labPreviewLCD { display: block; width: 100%; height: 49px; object-fit: contain; image-rendering: pixelated; background: #03070b; }
.lab-preview-lcd > span { display: block; color: #a4c5c1; font: 8px/1.6 var(--mono); text-align: center; direction: ltr; }
.lab-preview-readouts {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
  padding: 4px 1px 3px;
  color: #91abba;
  font: 9px/1.5 var(--mono);
  font-variant-numeric: tabular-nums;
}
.lab-preview-readouts > span { white-space: nowrap; }
.lab-preview-readouts output { color: #dcebf4; }
#labPreviewPan { color: #82e1c4; }
#labPreviewTilt { color: #e8c788; }
#labPreviewTime { white-space: nowrap; }
.lab-preview-mode {
  min-height: 15px;
  max-height: 32px;
  overflow: auto;
  margin: 0;
  color: #a4c5ce;
  font-size: 9px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}
.lab-preview[data-source="python-live"] .lab-preview-mode { color: #8ae6c9; }
.lab-preview[data-source="hardware"] .lab-preview-mode { color: #edca8c; }
.lab-preview[data-source="stopped"] .lab-preview-mode { color: #d8b1ba; }
.lab-preview-actions { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; margin-top: 4px; }
#labPreview .lab-preview-actions .btn { min-height: 31px; padding: 5px 7px; font-size: 10px; line-height: 1.65; white-space: normal; transform: none; }
#labPreview .lab-preview-actions .btn:disabled { cursor: not-allowed; }
#labPreview #labLiveStop { min-width: 40px; color: #efc0cb; border-color: #775062; background: #362735; }
#labLiveHint { max-height: 29px; overflow: auto; margin: 4px 0 0; color: #8fa7bb; font-size: 9px; line-height: 1.6; }
.lab-preview-update { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 7px; margin-top: 5px; }
#labLiveApply { padding: 5px 7px; min-height: 30px; font-size: 10px; color: #b6eee0; border-color: #456e67; }
#labLiveApply:disabled { opacity: .45; }
#labLiveDirty { font-size: 9px; line-height: 1.6; color: #96aebf; overflow-wrap: anywhere; }
#labLiveDirty[data-state="dirty"] { color: #edca8c; }
#labPreview :is(a, button):focus-visible { outline: 2px solid #8ae8d1; outline-offset: 2px; }

@media (min-width: 1101px) {
  /* Preserve a real rail footprint. Only navigation scrolls on short screens. */
  .lab-nav-shell { display: flex; flex-direction: column; padding: 12px 10px 10px; overflow: hidden; }
  .lab-nav-heading { flex: 0 0 auto; padding: 0 8px 9px; }
  .lab-nav-heading h2 { margin-top: 2px; font-size: 16px; }
  .lab-workspace .lab-nav-heading .section-label { font-size: 8px; }
  .lab-nav { flex: 1 1 auto; min-height: 0; gap: 3px; padding: 2px; overflow-y: auto; overscroll-behavior-y: contain; }
  .lab-tab { flex: 0 0 auto; min-height: 44px; padding: 7px 9px; gap: 9px; }
  .lab-tab-text strong { font-size: 12px; }
  .lab-tab-text small, .lab-tab-index { display: none; }
  .lab-tab-icon, .lab-tab-icon svg { width: 20px; height: 20px; }
  .lab-tab-icon { flex-basis: 20px; }
  .lab-nav-foot { flex: 0 0 auto; margin: 8px 8px 0; padding-top: 9px; }
  .lab-world-link { font-size: 11px; }
  .lab-nav-foot > a:not(.lab-world-link) { margin-top: 4px; font-size: 10px; }
  .lab-nav-foot > :is(small, p) { display: none; }
}

@media (min-width: 1101px) and (max-height: 620px) {
  #labPreview3D { height: 100px; }
  .lab-preview { margin-top: 8px; }
  .lab-nav-heading { padding-bottom: 5px; }
}

@media (max-width: 1100px) {
  .lab-preview {
    position: fixed;
    z-index: 30;
    right: 14px;
    left: 14px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    margin: 0;
    padding: 8px 12px;
    border-color: #496a70;
    border-radius: 12px;
    box-shadow: 0 -8px 28px #03091380;
  }
  .lab-preview-header { min-height: 28px; margin-bottom: 5px; }
  .lab-preview-header > strong { font-size: 12px; }
  .lab-preview-tools :is(a, button) { width: 29px; height: 29px; }
  #labPreviewBody {
    display: grid;
    grid-template-columns: minmax(240px, 1.25fr) minmax(70px, .4fr) minmax(200px, 1fr);
    grid-template-rows: minmax(24px, auto) auto auto minmax(20px, auto);
    column-gap: 18px;
    row-gap: 4px;
    align-items: center;
  }
  .lab-preview-scenes { grid-column: 1; grid-row: 1 / 5; display: grid; grid-template-columns: minmax(0, 1fr) 95px; align-items: center; gap: 10px; }
  .lab-preview-robot { border-radius: 7px; }
  #labPreview3D { height: 110px; }
  .lab-preview-lcd { position: static; width: 95px; padding: 3px; }
  #labPreviewLCD { height: 66px; }
  .lab-preview-lcd > span { font-size: 8px; line-height: 1.5; }
  .lab-preview-readouts { grid-column: 2; grid-row: 1 / 5; display: flex; flex-direction: column; align-items: flex-start; justify-content: center; gap: 10px; padding: 0; font-size: 11px; }
  .lab-preview-mode { grid-column: 3; grid-row: 1; font-size: 10px; max-height: 34px; }
  .lab-preview-actions { grid-column: 3; grid-row: 2; margin: 0; }
  #labPreview .lab-preview-actions .btn { min-height: 33px; font-size: 11px; }
  .lab-preview-update { grid-column: 3; grid-row: 3; margin: 0; }
  #labLiveHint { grid-column: 3; grid-row: 4; margin: 0; max-height: 32px; font-size: 10px; line-height: 1.6; }
  .voice-dock { bottom: calc(var(--lab-preview-inset) + 24px + env(safe-area-inset-bottom, 0px)); }
  body[data-preview-keyboard="true"] #labPreviewBody { display: none !important; }
  body[data-preview-keyboard="true"] .lab-preview-header { margin-bottom: 0; }
}

@media (max-width: 700px) {
  .lab-preview { padding: 7px 8px; }
  .lab-preview-header { min-height: 26px; margin-bottom: 4px; }
  .lab-preview-header > strong { font-size: 11px; }
  .lab-preview-tools :is(a, button) { width: 28px; height: 28px; }
  #labPreviewBody {
    grid-template-columns: minmax(0, 1fr) 73px;
    grid-template-rows: 100px auto auto auto;
    column-gap: 10px;
    row-gap: 3px;
    align-items: start;
  }
  .lab-preview-scenes { grid-column: 1; grid-row: 1; grid-template-columns: minmax(0, 1fr) minmax(0, .65fr); gap: 7px; }
  #labPreview3D { height: 98px; }
  .lab-preview-lcd { width: 100%; min-width: 0; padding: 2px; }
  #labPreviewLCD { height: 65px; }
  .lab-preview-lcd > span { font-size: 7px; }
  #labPreviewStatus { font-size: 8px; padding: 3px; top: 4px; right: 4px; left: 4px; }
  .lab-preview-readouts { grid-column: 2; grid-row: 1; align-self: start; gap: 6px; padding-top: 3px; font-size: 10px; }
  .lab-preview-mode { grid-column: 2; grid-row: 1; align-self: end; max-height: 30px; margin-bottom: 1px; font-size: 8px; line-height: 1.65; }
  .lab-preview-actions { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(0, 1fr) minmax(60px, .32fr); }
  #labPreview .lab-preview-actions .btn { min-height: 30px; padding: 4px 8px; font-size: 11px; }
  .lab-preview-update { grid-column: 1 / -1; grid-row: 3; }
  #labLiveHint { grid-column: 1 / -1; grid-row: 4; max-height: 26px; font-size: 8px; line-height: 1.6; }
}

@media (prefers-reduced-motion: reduce) {
  .lab-preview, .lab-preview *, .lab-nav-shell { transition: none; scroll-behavior: auto; }
}

.lab-animation-picker { min-width: 0; margin-top: 7px; border: 1px solid #3d5f61; border-radius: 7px; background: #122a32; }
.lab-animation-picker > summary { padding: 8px; color: #b6eee0; font-size: 10px; line-height: 1.7; cursor: pointer; }
.lab-picker-body { max-height: min(38vh, 270px); overflow-y: auto; padding: 2px 8px 8px; overscroll-behavior-y: contain; }
.lab-animation-picker .animation-picker-fields { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 7px; }
.lab-animation-picker label { min-width: 0; margin: 0; color: #b4cad3; font-size: 9px; line-height: 1.8; }
.lab-animation-picker .animation-picker-name { grid-column: 1 / -1; }
.lab-animation-picker :is(select, input[type="number"]) { display: block; min-width: 0; width: 100%; margin-top: 4px; padding: 7px 6px; border: 1px solid #466475; border-radius: 6px; background: #0c1d29; color: #e3edf5; font: 11px/1.5 var(--sans); }
.lab-animation-picker :is(select, input):disabled { opacity: .5; cursor: not-allowed; }
.lab-animation-picker .animation-picker-unlimited { grid-column: 1 / -1; display: flex; align-items: center; gap: 6px; }
.lab-animation-picker input[type="checkbox"] { width: auto; margin: 0; accent-color: #6ad9b9; }
#labPreview #labPickerApply { width: 100%; min-height: 31px; margin-top: 9px; padding: 6px; color: #b6eee0; border-color: #4b7e73; background: #1c3b39; font-size: 10px; transform: none; }
#labPreview #labPickerApply:disabled { opacity: .45; cursor: not-allowed; }
.lab-animation-picker .animation-picker-status { margin: 7px 0 0; color: #a6e2ce; font-size: 9px; line-height: 1.7; overflow-wrap: anywhere; }
.lab-animation-picker .animation-picker-help { margin: 6px 0 0; color: #93adbb; font-size: 8px; line-height: 1.7; }
#labPreview .lab-animation-picker :is(summary, select, input):focus-visible { outline: 2px solid #8ae8d1; outline-offset: 2px; }
@media (max-width: 1100px) { .lab-animation-picker { grid-column: 1 / -1; grid-row: 5; margin-top: 5px; } }
