.preview {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
  background: var(--bg);
}

.header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  /* Fit control hugs the left, settings gear trails right (mirrors the editor
     toolbar). It used to be flex-end, which made any overflow trim the *left*
     item — clipping "Original". Left-aligned, the gear is the trimmable end, and
     the preview's min-width is sized so it never actually overflows. */
  justify-content: flex-start;
  gap: var(--space-3);
  height: 40px;
  padding: 0 var(--space-4);
  border-bottom: var(--border-width) solid var(--border);
}

/* Push the right cluster (export + settings gear) to the far right; Fit hugs
   the left. The cluster itself is the last child, so any header overflow trims
   from its right edge, never clipping "Original" on the left. */
.headerEnd {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.body {
  position: relative; /* establishes stacking context for the busy overlay */
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: var(--space-5);
  box-sizing: border-box;
}

/* Fit-mode segmented control (spec §04) styling now lives in
   SegmentedControl.module.css; the per-mode sizing classes below stay here. */

/*
 * Chart sizing. The host (passed to vega-embed) is branded `.vega-embed`
 * (display:inline-block) at runtime; that shrink-wraps it, which is why
 * width:"container" collapsed before. The frame carries the fit class and the
 * two-class selectors below out-specify `.vega-embed` to give the host a
 * definite box for the responsive modes. `box-sizing:border-box` keeps the
 * chart inside the body padding rather than overflowing it.
 */
.frame {
  box-sizing: border-box;
}

.host {
  box-sizing: border-box;
}

/* Original — natural size; the body scrolls if the chart is larger than the pane. */
.fitOriginal {
  display: inline-block;
}

/* Width — host spans the pane width; height stays natural. */
.fitWidth {
  display: block;
  width: 100%;
}
.fitWidth .host {
  width: 100%;
}

/* Height — host spans the pane height; width stays natural. */
.fitHeight {
  display: block;
  height: 100%;
}
.fitHeight .host {
  height: 100%;
}

/* Full — host fills the pane in both dimensions. */
.fitFull {
  display: block;
  width: 100%;
  height: 100%;
}
.fitFull .host {
  width: 100%;
  height: 100%;
}

.error {
  margin: 0;
  padding: var(--space-5);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.6;
  color: var(--support-error);
  white-space: pre-wrap;
  word-break: break-word;
}

/*
 * Busy overlay — non-blocking; floats over the chart body only (arch §10.2;
 * spec §04/§10). position:absolute relative to .body's position:relative.
 * pointer-events:none ensures the editor and other controls stay fully
 * interactive while the overlay is visible.
 *
 * The spinner animation is a pure CSS transform-based rotation so it respects
 * the global prefers-reduced-motion rule in base.css (animation-duration → 0.01ms).
 */
.busyOverlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  pointer-events: none;
}

.busySpinner {
  display: block;
  width: var(--icon-lg);
  height: var(--icon-lg);
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: busySpin 600ms linear infinite;
}

.busyLabel {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

@keyframes busySpin {
  to {
    transform: rotate(360deg);
  }
}
