/*
 * Lab chrome — loaded ONLY by lab.html (own <link>, after app.css so its
 * rules win ties). The sheet/drawer is a frosted panel floating over the
 * live scene; all geometry hangs off [data-state]; the ghost fade lets the
 * scene show through while a slider is held.
 */

[data-testid="lab-sheet"] {
  position: fixed;
  z-index: 5;
  display: flex;
  flex-direction: column;
  background: var(--card-bg);
  backdrop-filter: blur(14px) saturate(1.1);
  -webkit-backdrop-filter: blur(14px) saturate(1.1);
  border: 1px solid var(--card-border-c);
  color: var(--ink);
  transition: height 0.25s cubic-bezier(0.2, 0.7, 0.2, 1), width 0.25s cubic-bezier(0.2, 0.7, 0.2, 1), opacity 0.2s ease;
}
@media (prefers-reduced-motion: reduce) {
  [data-testid="lab-sheet"] { transition: none; }
}

/* ---- mobile: bottom sheet ------------------------------------------------ */
@media (max-width: 899.98px) {
  [data-testid="lab-sheet"] {
    left: 0; right: 0; bottom: 0;
    border-radius: 1.1rem 1.1rem 0 0;
    border-bottom: none;
  }
  [data-testid="lab-sheet"][data-state="peek"] { height: 7rem; }
  [data-testid="lab-sheet"][data-state="half"] { height: 46vh; }
  [data-testid="lab-sheet"][data-state="full"] { height: 88vh; }
  [data-testid="lab-sheet"][data-state="peek"] .lab-panels,
  [data-testid="lab-sheet"][data-state="peek"] .lab-footer { display: none; }
}

/* ---- desktop: right drawer ----------------------------------------------- */
@media (min-width: 900px) {
  [data-testid="lab-sheet"] {
    /* The masthead (header[role="banner"]) is static, in-flow chrome that sits
       above the drawer's own stacking region -- NOT full-width-fixed -- so it
       measures a fixed offsetHeight regardless of drawer viewport width
       (measured 66px across 900-1920px, one nav line). top:0 here used to let
       the drawer's frosted top region cover the masthead's nav links + theme
       picker: visible through the frost but unclickable (the drawer's
       z-index: 5 wins over the header's z-index: 2). Starting the drawer
       below the masthead's bottom edge means the two never occupy the same
       viewport row, so no z-index tie-break is needed at all. */
    top: 4.5rem; right: 0; bottom: 0;
    width: 340px;
    border-radius: 1.1rem 0 0 1.1rem;
    border-right: none;
  }
  [data-testid="lab-sheet"][data-state="collapsed"] { width: 3rem; }
  [data-testid="lab-sheet"][data-state="collapsed"] .lab-chips,
  [data-testid="lab-sheet"][data-state="collapsed"] .lab-tabs,
  [data-testid="lab-sheet"][data-state="collapsed"] .lab-panels,
  [data-testid="lab-sheet"][data-state="collapsed"] .lab-footer { display: none; }
}

/* ---- handle --------------------------------------------------------------- */
.lab-handle {
  flex: 0 0 auto;
  min-height: 44px;
  margin: 0; border: none; cursor: grab;
  background: transparent;
  touch-action: none; /* the drag owns vertical gestures */
  position: relative;
}
.lab-handle::after {
  content: ""; position: absolute; left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 3rem; height: 4px; border-radius: 2px;
  background: var(--mist); opacity: 0.7;
}
@media (min-width: 900px) {
  .lab-handle { cursor: pointer; }
  .lab-handle::after { width: 4px; height: 3rem; }
}

/* ---- tabs ------------------------------------------------------------------ */
.lab-tabs { flex: 0 0 auto; display: flex; gap: 0.4rem; padding: 0 0.9rem 0.6rem; }
.lab-tab {
  flex: 1; min-height: 44px;
  background: transparent; color: var(--mist);
  border: 1px solid var(--line); border-radius: 0.55rem;
  font: 500 0.72rem/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  cursor: pointer;
}
.lab-tab:hover { color: var(--ink); }
.lab-tab[aria-selected="true"] { color: var(--ink); border-color: var(--ai); box-shadow: var(--glow-ai); }

/* ---- panels + rows --------------------------------------------------------- */
.lab-panels { flex: 1 1 auto; overflow-y: auto; padding: 0.4rem 0.9rem; overscroll-behavior: contain; }
/* Tasks 3-5 fill each panel with rows; until then (and briefly between a tab
   switch and its section populating) an empty panel has no content, so a
   block <div> collapses to 0 height -- which reads as "not visible" to both
   users and Playwright's actionability checks. A small min-height keeps the
   active panel a real, visible box regardless of content. */
.lab-panel { min-height: 2rem; }
.lab-row {
  display: grid; grid-template-columns: minmax(0, 7.5rem) 1fr auto auto;
  align-items: center; gap: 0.55rem; min-height: 44px;
}
.lab-row label { font: 500 0.66rem/1.2 var(--mono); color: var(--mist); overflow-wrap: anywhere; }
.lab-row input[type="range"] { width: 100%; min-width: 0; accent-color: var(--ai); }
.lab-row input[type="text"], .lab-row input[type="color"] {
  min-width: 0; width: 100%; min-height: 32px;
  background: var(--void-2); color: var(--ink);
  border: 1px solid var(--line); border-radius: 0.4rem;
  font: 400 0.7rem/1.2 var(--mono); padding: 0.25rem 0.4rem;
}
.lab-row input[type="color"] { width: 44px; padding: 0.1rem; }
.lab-value { font: 500 0.7rem/1 var(--mono); color: var(--ink); min-width: 3.2rem; text-align: right; }
.lab-reset-dot {
  width: 20px; height: 20px; padding: 0; border-radius: 50%;
  border: 1px solid var(--line); background: var(--cut); opacity: 0.85;
  cursor: pointer; visibility: hidden;
}
.lab-reset-dot[data-dirty] { visibility: visible; }
.lab-group-heading { font: 700 0.72rem/1.2 var(--mono); color: var(--ai); letter-spacing: 0.1em; text-transform: uppercase; margin: 1rem 0 0.4rem; }
.lab-chips { display: flex; flex-wrap: wrap; gap: 0.4rem; padding-bottom: 0.6rem; }
.lab-chip {
  min-height: 44px; padding: 0 0.9rem;
  background: transparent; color: var(--mist);
  border: 1px solid var(--line); border-radius: 2rem;
  font: 500 0.72rem/1 var(--mono); cursor: pointer;
}
.lab-chip[aria-pressed="true"] { color: var(--ink); border-color: var(--ai); box-shadow: var(--glow-ai); }

/* ---- footer ----------------------------------------------------------------- */
.lab-footer { flex: 0 0 auto; display: flex; gap: 0.5rem; padding: 0.6rem 0.9rem; border-top: 1px solid var(--line); }
.lab-footer button, .lab-section-actions button {
  min-height: 44px; padding: 0 0.9rem;
  background: transparent; color: var(--ai);
  border: 1px solid var(--line); border-radius: 0.55rem;
  font: 500 0.72rem/1 var(--mono); cursor: pointer;
}
.lab-footer button:hover, .lab-section-actions button:hover { color: var(--ink); border-color: var(--ai); }
.lab-section-actions { display: flex; gap: 0.5rem; margin: 0.8rem 0 0.4rem; }
.lab-json {
  font: 400 0.62rem/1.5 var(--mono); color: var(--mist);
  background: var(--void-2); border: 1px solid var(--line); border-radius: 0.55rem;
  padding: 0.5rem; overflow-x: auto; white-space: pre;
}

/* ---- ghost-while-dragging ----------------------------------------------------
   Everything in the sheet fades except the active row, so the live scene
   behind shows the change in real time under the finger. */
[data-testid="lab-sheet"][data-ghost] { background: transparent; border-color: transparent; backdrop-filter: none; -webkit-backdrop-filter: none; }
[data-testid="lab-sheet"][data-ghost] .lab-handle,
[data-testid="lab-sheet"][data-ghost] .lab-tabs,
[data-testid="lab-sheet"][data-ghost] .lab-footer,
[data-testid="lab-sheet"][data-ghost] .lab-chips,
[data-testid="lab-sheet"][data-ghost] .lab-group-heading,
[data-testid="lab-sheet"][data-ghost] .lab-section-actions,
[data-testid="lab-sheet"][data-ghost] .lab-json,
[data-testid="lab-sheet"][data-ghost] .lab-panels > *:not([data-active-row]) .lab-row:not([data-active-row]) {
  opacity: 0.08;
  transition: opacity 0.15s ease;
}
[data-testid="lab-sheet"][data-ghost] .lab-row[data-active-row] { opacity: 1; }
[data-testid="lab-sheet"][data-ghost] .lab-row[data-active-row] .lab-value { font-size: 1.1rem; color: var(--ai); }
@media (prefers-reduced-motion: reduce) {
  [data-testid="lab-sheet"][data-ghost] * { transition: none; }
}
