/* ==========================================================================
   UA Living Spec Book — Studio admin (st-*, pe-*, se-*)
   Studio home, project editor, and section editor. The client book's calm
   editorial brand, tightened for work: base gap --ua-s4 (denser than the
   book), cards on --ua-bg-card with 1px --ua-line-soft, Bellefair panel
   titles, eyebrow labels. Consumes tokens from css/tokens.css only.
   Selectors are tolerant: BEM __ subclasses plus plain-element fallbacks,
   matching the conventions of components.css / sections.css.
   ========================================================================== */

/* ======================================================================
   Shared panel recipe (.st-panel / .pe-panel)
   ====================================================================== */
.st-panel,
.pe-panel {
  min-width: 0;
  padding: var(--ua-s5);
  background: var(--ua-bg-card);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius-lg);
  accent-color: var(--ua-ink);
}

/* Work rhythm: everything inside a panel breathes at the base gap. */
.st-panel > * + *,
.pe-panel > * + * {
  margin-top: var(--ua-s4);
}

/* Panel titles — Bellefair, never uppercase, quiet weight. */
.st-panel > h2,
.st-panel > h3,
.pe-panel > h2,
.pe-panel > h3,
.st-panel__title,
.pe-panel__title,
.st-toolbar h2,
.st-toolbar h3 {
  margin: 0;
  font-family: var(--ua-font-display);
  font-size: 1.45rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ua-text-strong);
}

/* Eyebrow group labels inside panels get a little air above. */
.st-panel .ua-eyebrow,
.pe-panel .ua-eyebrow {
  margin-bottom: var(--ua-s2);
}

/* Muted helper copy inside panels. */
.st-panel > p,
.pe-panel > p {
  max-width: 58ch;
  font-size: var(--ua-fs-small);
  font-weight: 200;
  color: var(--ua-text-muted);
  line-height: 1.6;
}

/* Tables inside panels: raised surface, denser cells than the book. */
.st-panel .ua-table-wrap,
.pe-panel .ua-table-wrap {
  background: var(--ua-bg-raised);
}

.st-panel .ua-table th,
.pe-panel .ua-table th {
  padding: 0.55rem 0.75rem;
}

.st-panel .ua-table td,
.pe-panel .ua-table td {
  padding: 0.6rem 0.75rem;
  vertical-align: middle;
}

.st-panel td .ua-progress,
.pe-panel td .ua-progress {
  width: 100%;
  min-width: 64px;
}

/* Forms inside panels stack calmly at the base gap. */
.st-panel form,
.pe-panel form {
  display: grid;
  gap: var(--ua-s4);
  justify-items: start;
}

.st-panel form .ua-field,
.st-panel form .ua-input,
.pe-panel form .ua-field,
.pe-panel form .ua-input {
  justify-self: stretch;
  width: 100%;
}

.pe-panel input[type='range'] {
  width: 100%;
  accent-color: var(--ua-ink);
  cursor: pointer;
}

/* Bounded thumbs for image pickers inside admin fields. */
.pe-panel .ua-field img,
.st-panel .ua-field img,
.se-field img {
  max-height: 140px;
  width: auto;
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius);
  background: var(--ua-bg-raised);
}

/* ======================================================================
   Studio home — two-column grid (projects | clients & access)
   ====================================================================== */
.st-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: var(--ua-s5);
  align-items: start;
  margin-block: var(--ua-s5) var(--ua-s8);
}

.st-grid > * {
  min-width: 0;
}

/* Panels stacked within a grid column. */
.st-grid > div > .st-panel + .st-panel {
  margin-top: var(--ua-s5);
}

/* ======================================================================
   Toolbar — panel header row: title left, actions right
   ====================================================================== */
.st-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--ua-s2) var(--ua-s3);
  min-width: 0;
}

.st-toolbar > div {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2);
  min-width: 0;
}

/* ======================================================================
   Switch — real checkbox drawn as a 40×22 pill track
   ====================================================================== */
.st-switch {
  display: inline-flex;
  align-items: center;
  gap: var(--ua-s2);
  font-size: var(--ua-fs-small);
  font-weight: 200;
  color: var(--ua-text-muted);
  cursor: pointer;
  user-select: none;
}

.st-switch input[type='checkbox'],
input.st-switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 40px;
  height: 22px;
  margin: 0;
  border: 1px solid var(--ua-line-strong);
  border-radius: var(--ua-radius-pill);
  background: var(--ua-line-soft);
  cursor: pointer;
  transition:
    background-color var(--ua-fast) var(--ua-ease),
    border-color var(--ua-fast) var(--ua-ease);
}

.st-switch input[type='checkbox']::before,
input.st-switch::before {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--ua-bg-raised);
  box-shadow: 0 1px 2px color-mix(in srgb, var(--ua-ink) 22%, transparent);
  transition:
    transform var(--ua-fast) var(--ua-ease),
    background-color var(--ua-fast) var(--ua-ease);
}

.st-switch input[type='checkbox']:checked,
input.st-switch:checked {
  background: var(--ua-ink);
  border-color: var(--ua-ink);
}

.st-switch input[type='checkbox']:checked::before,
input.st-switch:checked::before {
  transform: translateX(18px);
  background: var(--ua-bg);
}

.st-switch input[type='checkbox']:focus-visible,
input.st-switch:focus-visible {
  outline: 2px solid var(--ua-ink);
  outline-offset: 2px;
}

.st-switch input[type='checkbox']:disabled,
input.st-switch:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.st-switch input:checked ~ span {
  color: var(--ua-text);
}

/* ======================================================================
   User lines — clients & access panel rows
   ====================================================================== */
.st-userline {
  display: flex;
  align-items: center;
  gap: var(--ua-s3);
  padding-block: var(--ua-s3);
  font-size: var(--ua-fs-small);
  font-weight: 200;
}

.st-userline + .st-userline {
  border-top: 1px solid var(--ua-line-soft);
  margin-top: 0;
}

.st-userline > :first-child {
  flex: 1 1 auto;
  min-width: 0;
}

.st-userline strong {
  display: block;
  font-weight: 400;
  color: var(--ua-text-strong);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.st-userline .u-muted,
.st-userline__email,
.st-userline small {
  display: block;
  font-size: var(--ua-fs-tiny);
  color: var(--ua-text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.st-userline .ua-badge {
  flex: none;
  margin-left: auto;
}

.st-userline .ua-badge ~ * {
  margin-left: 0;
}

/* ======================================================================
   Invite form + returned action link
   ====================================================================== */
.st-invite {
  display: grid;
  gap: var(--ua-s4);
  justify-items: start;
}

/* Divider hairline only when the form follows other panel content. */
* + .st-invite {
  padding-top: var(--ua-s4);
  border-top: 1px solid var(--ua-line-soft);
}

.st-invite .ua-field,
.st-invite .ua-input {
  justify-self: stretch;
  width: 100%;
}

/* Copy-to-clipboard row: readonly link + copy button. */
.st-invite__result,
.st-invite__link,
.st-invite output {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2);
  justify-self: stretch;
  min-width: 0;
}

.st-invite__result .ua-input,
.st-invite__link .ua-input,
.st-invite output .ua-input,
.st-invite input[readonly] {
  flex: 1 1 12rem;
  min-width: 0;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: var(--ua-fs-tiny);
  color: var(--ua-text-muted);
}

.st-invite__status,
.st-invite small,
.st-invite > p {
  margin: 0;
  font-size: var(--ua-fs-tiny);
  font-weight: 200;
  color: var(--ua-text-muted);
  line-height: 1.6;
}

/* ======================================================================
   Empty state — first-run onboarding card
   ====================================================================== */
.st-empty {
  display: grid;
  justify-items: center;
  gap: var(--ua-s3);
  max-width: 34rem;
  margin: clamp(var(--ua-s7), 12vh, var(--ua-s9)) auto var(--ua-s8);
  padding: clamp(var(--ua-s6), 6vw, var(--ua-s8)) var(--ua-s6);
  background: var(--ua-bg-card);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius-lg);
  box-shadow: var(--ua-shadow-soft);
  text-align: center;
}

.st-empty h2,
.st-empty h3 {
  margin: 0;
  font-family: var(--ua-font-display);
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ua-text-strong);
}

.st-empty p {
  margin: 0;
  max-width: 44ch;
  font-size: var(--ua-fs-small);
  font-weight: 200;
  color: var(--ua-text-muted);
  line-height: 1.65;
}

.st-empty .ua-btn {
  margin-top: var(--ua-s2);
}

/* ======================================================================
   Project editor — layout
   ====================================================================== */
.pe-layout {
  display: grid;
  gap: var(--ua-s5);
  max-width: 64rem;
  margin-inline: auto;
  padding-block: var(--ua-s5) var(--ua-s8);
}

.pe-layout > * {
  min-width: 0;
}

/* ======================================================================
   Project editor — chapters manager
   ====================================================================== */
.pe-chapters {
  display: grid;
  gap: var(--ua-s3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pe-chapter,
.pe-chapters > li,
.pe-chapters > div {
  display: grid;
  gap: var(--ua-s3);
  min-width: 0;
  padding: var(--ua-s4);
  background: var(--ua-bg-raised);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius);
  list-style: none;
}

.pe-chapter > *,
.pe-chapters > li > *,
.pe-chapters > div > * {
  min-width: 0;
}

.pe-chapter > header,
.pe-chapter__head,
.pe-chapters header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2);
}

.pe-chapter header .ua-input,
.pe-chapter__head .ua-input {
  flex: 1 1 10rem;
  min-width: 0;
}

/* Chip rows inside a chapter. */
.pe-chapters ul,
.pe-chapter ul,
.pe-chapter__chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--ua-s2);
  margin: 0;
  padding: 0;
  list-style: none;
}

/* ======================================================================
   Project editor — section chips (moved with the ↑↓ buttons inside)
   ====================================================================== */
.pe-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--ua-s1);
  padding: 0.2rem 0.3rem 0.2rem 0.8rem;
  border: 1px solid var(--ua-line);
  border-radius: var(--ua-radius-pill);
  background: var(--ua-bg-card);
  color: var(--ua-text);
  font-size: var(--ua-fs-tiny);
  font-weight: 300;
  letter-spacing: 0.03em;
  line-height: 1.3;
  transition:
    border-color var(--ua-fast) var(--ua-ease),
    box-shadow var(--ua-fast) var(--ua-ease);
}

.pe-chip:hover,
.pe-chip:focus-within {
  border-color: var(--ua-line-strong);
  box-shadow: var(--ua-shadow-soft);
}

.pe-chip > span {
  max-width: 22ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pe-chip button,
.pe-chip .ua-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.6rem;
  height: 1.6rem;
  min-width: 1.6rem;
  min-height: 1.6rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--ua-text-muted);
  cursor: pointer;
  transition:
    background-color var(--ua-fast) var(--ua-ease),
    color var(--ua-fast) var(--ua-ease);
}

.pe-chip button:hover,
.pe-chip .ua-btn:hover {
  background: var(--ua-ink);
  color: var(--ua-text-on-ink);
}

.pe-chip button:disabled,
.pe-chip .ua-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pe-chip button:disabled:hover,
.pe-chip .ua-btn:disabled:hover {
  background: transparent;
  color: var(--ua-text-muted);
}

.pe-chip .ua-icon {
  width: 0.95em;
  height: 0.95em;
}

/* ======================================================================
   Project editor — sections list (position-ordered rows)
   ====================================================================== */
.pe-sections {
  display: grid;
  gap: var(--ua-s2);
  margin: 0;
  padding: 0;
  list-style: none;
}

.pe-sections > li,
.pe-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2) var(--ua-s3);
  padding: var(--ua-s3) var(--ua-s4);
  background: var(--ua-bg-raised);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius);
  list-style: none;
  font-size: var(--ua-fs-small);
  font-weight: 200;
}

.pe-sections strong,
.pe-section strong {
  font-weight: 400;
  color: var(--ua-text-strong);
}

.pe-sections .u-muted,
.pe-sections small,
.pe-section small {
  font-size: var(--ua-fs-tiny);
  color: var(--ua-text-muted);
}

/* Position number — tabular, faint. */
.pe-sections__num,
.pe-section__num {
  min-width: 2ch;
  font-family: 'Lato', 'Helvetica Neue', Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  font-size: var(--ua-fs-tiny);
  color: var(--ua-text-faint);
}

/* Action cluster hugs the right edge. */
.pe-sections__actions,
.pe-section__actions,
.pe-sections li > menu {
  display: flex;
  align-items: center;
  gap: var(--ua-s1);
  margin: 0 0 0 auto;
  padding: 0;
  list-style: none;
}

/* ======================================================================
   Project editor — danger zone (hairline accents, never lurid)
   ====================================================================== */
.pe-danger {
  min-width: 0;
  padding: var(--ua-s5);
  background: var(--ua-bg-card);
  border: 1px solid color-mix(in srgb, var(--ua-status-danger) 38%, var(--ua-line-soft));
  border-radius: var(--ua-radius-lg);
}

.pe-danger > * + * {
  margin-top: var(--ua-s4);
}

.pe-danger > h2,
.pe-danger > h3,
.pe-danger__title {
  margin: 0;
  font-family: var(--ua-font-display);
  font-size: 1.45rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ua-status-danger);
}

.pe-danger > p {
  max-width: 58ch;
  font-size: var(--ua-fs-small);
  font-weight: 200;
  color: var(--ua-text-muted);
  line-height: 1.6;
}

.pe-danger .ua-btn {
  border-color: color-mix(in srgb, var(--ua-status-danger) 45%, transparent);
  color: var(--ua-status-danger);
}

.pe-danger .ua-btn:hover {
  background: var(--ua-status-danger);
  border-color: var(--ua-status-danger);
  color: var(--ua-text-on-ink);
}

.pe-danger .ua-btn:disabled,
.pe-danger .ua-btn:disabled:hover {
  background: transparent;
  border-color: color-mix(in srgb, var(--ua-status-danger) 45%, transparent);
  color: var(--ua-status-danger);
  opacity: 0.45;
}

/* ======================================================================
   Inline confirm bars — calm alternative to window.confirm
   ====================================================================== */
.st-confirm,
.pe-confirm,
.se-confirm {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2) var(--ua-s3);
  padding: var(--ua-s3) var(--ua-s4);
  background: color-mix(in srgb, var(--ua-status-changes) 7%, transparent);
  border-left: 2px solid var(--ua-status-changes);
  border-radius: 0 var(--ua-radius) var(--ua-radius) 0;
  font-size: var(--ua-fs-small);
  font-weight: 200;
  color: var(--ua-text);
}

.st-confirm p,
.pe-confirm p,
.se-confirm p {
  flex: 1 1 14rem;
  min-width: 0;
  margin: 0;
  line-height: 1.5;
}

.st-confirm .ua-input,
.pe-confirm .ua-input,
.se-confirm .ua-input {
  flex: 1 1 12rem;
  min-width: 0;
}

/* Quiet text cancel — mirrors the book's "Change decision" affordance. */
.st-confirm button:not(.ua-btn),
.pe-confirm button:not(.ua-btn),
.se-confirm button:not(.ua-btn) {
  flex: none;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ua-text-muted);
  font: inherit;
  font-size: var(--ua-fs-small);
  font-weight: 200;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.st-confirm button:not(.ua-btn):hover,
.pe-confirm button:not(.ua-btn):hover,
.se-confirm button:not(.ua-btn):hover {
  color: var(--ua-text-strong);
}

/* Destructive confirms inside the danger zone pick up the danger hairline. */
.pe-danger .pe-confirm,
.pe-danger .se-confirm {
  background: color-mix(in srgb, var(--ua-status-danger) 6%, transparent);
  border-left-color: var(--ua-status-danger);
}

/* ======================================================================
   Section editor — layout: form | live preview
   ====================================================================== */
.se-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: var(--ua-s5);
  align-items: start;
  margin-top: var(--ua-s5);
}

.se-layout > * {
  min-width: 0;
}

.se-layout > .se-bar {
  grid-column: 1 / -1;
}

/* ======================================================================
   Section editor — form column
   ====================================================================== */
.se-form {
  min-width: 0;
  padding: var(--ua-s5);
  background: var(--ua-bg-card);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius-lg);
  accent-color: var(--ua-ink);
}

.se-form > * + * {
  margin-top: var(--ua-s4);
}

.se-form > h2,
.se-form > h3,
.se-form__title {
  margin: 0;
  font-family: var(--ua-font-display);
  font-size: 1.45rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  line-height: 1.15;
  color: var(--ua-text-strong);
}

.se-form .ua-eyebrow {
  margin-bottom: var(--ua-s2);
}

/* Group divider between schema field clusters. */
.se-form hr,
.se-form .ua-divider {
  margin: var(--ua-s5) 0 var(--ua-s4);
}

/* ======================================================================
   Section editor — fields (label + control + help)
   ====================================================================== */
.se-field {
  display: block;
  min-width: 0;
}

.se-field > label,
.se-field__label {
  display: block;
  color: var(--ua-text-muted);
  font-size: var(--ua-fs-tiny);
  font-weight: 400;
  letter-spacing: var(--ua-tracking-caps);
  text-transform: uppercase;
}

.se-field > label + * {
  margin-top: 0.4rem;
}

.se-field .ua-input {
  width: 100%;
}

.se-field textarea.ua-input {
  min-height: 4.5rem;
}

/* Help copy for non-technical staff — quiet, under the control. */
.se-field__help,
.se-field small,
.se-field > p {
  display: block;
  margin: 0.35rem 0 0;
  font-size: var(--ua-fs-tiny);
  font-weight: 200;
  color: var(--ua-text-muted);
  line-height: 1.5;
}

/* Inline control rows: color swatch + hex, upload + url, etc. */
.se-field__row,
.se-field .u-flex {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--ua-s2);
}

.se-field__row .ua-input {
  flex: 1 1 8rem;
  min-width: 0;
  width: auto;
}

.se-field input[type='color'] {
  flex: none;
  width: 2.6rem;
  height: 2.45rem;
  padding: 3px;
  border: 1px solid var(--ua-line);
  border-radius: var(--ua-radius);
  background: var(--ua-bg-raised);
  cursor: pointer;
}

.se-field input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

.se-field input[type='color']::-webkit-color-swatch {
  border: 1px solid var(--ua-line-soft);
  border-radius: 2px;
}

select.ua-input {
  cursor: pointer;
}

/* ======================================================================
   Section editor — list-of-objects editor (item cards)
   ====================================================================== */
.se-list {
  display: grid;
  gap: var(--ua-s3);
  margin: 0;
  padding: 0;
  list-style: none;
}

.se-listitem {
  display: grid;
  gap: var(--ua-s3);
  min-width: 0;
  padding: var(--ua-s3) var(--ua-s4) var(--ua-s4);
  background: var(--ua-bg-raised);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius);
  list-style: none;
}

/* Grid/flex minimum-size traps: cards and their header rows must be able
   to shrink below their content so long labels ellipsize instead of
   pushing the card past its column. */
.se-listitem > header,
.se-listitem__head,
.se-listitem > * {
  min-width: 0;
}

/* Quiet header row: item label left, reorder/remove icon buttons right.
   Pulls itself flush to the card edges when present. */
.se-listitem > header,
.se-listitem__head {
  display: flex;
  align-items: center;
  gap: var(--ua-s1);
  margin: calc(-1 * var(--ua-s3)) calc(-1 * var(--ua-s4)) 0;
  padding: var(--ua-s2) var(--ua-s2) var(--ua-s2) var(--ua-s4);
  border-bottom: 1px solid var(--ua-line-soft);
}

.se-listitem > header > :first-child,
.se-listitem__head > :first-child {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: var(--ua-fs-tiny);
  font-weight: 400;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ua-text-muted);
}

.se-listitem > header button,
.se-listitem__head button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 1.75rem;
  height: 1.75rem;
  min-width: 1.75rem;
  min-height: 1.75rem;
  padding: 0;
  border: 0;
  border-radius: var(--ua-radius);
  background: transparent;
  color: var(--ua-text-muted);
  cursor: pointer;
  transition:
    background-color var(--ua-fast) var(--ua-ease),
    color var(--ua-fast) var(--ua-ease);
}

.se-listitem > header button:hover,
.se-listitem__head button:hover {
  background: color-mix(in srgb, var(--ua-ink) 6%, transparent);
  color: var(--ua-text-strong);
}

.se-listitem > header button:disabled,
.se-listitem__head button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.se-listitem > header button:disabled:hover,
.se-listitem__head button:disabled:hover {
  background: transparent;
  color: var(--ua-text-muted);
}

/* Two-up field pairs inside an item card when the engine groups them. */
.se-listitem__body,
.se-listitem > fieldset {
  display: grid;
  gap: var(--ua-s3);
}

/* Add-item affordance under a list. */
.se-list + .ua-btn {
  margin-top: var(--ua-s2);
  justify-self: start;
}

/* ======================================================================
   Section editor — live preview (paper page)
   ====================================================================== */
.se-preview {
  position: sticky;
  top: calc(var(--ua-header-h) + var(--ua-s4));
  max-height: calc(100vh - var(--ua-header-h) - 7rem);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-width: 0;
  padding: clamp(var(--ua-s4), 3vw, var(--ua-s6));
  background: var(--ua-bg);
  border: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius-lg);
  box-shadow: var(--ua-shadow-soft);
}

.se-preview > * + * {
  margin-top: var(--ua-s4);
}

/* Pane label — works as a static eyebrow or as a <details> summary. */
.se-preview > .ua-eyebrow,
.se-preview > summary {
  display: flex;
  align-items: center;
  gap: var(--ua-s2);
  margin: 0;
  font-family: var(--ua-font-body);
  font-size: var(--ua-fs-tiny);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--ua-tracking-caps);
  color: var(--ua-text-muted);
}

.se-preview > summary {
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.se-preview > summary::-webkit-details-marker {
  display: none;
}

.se-preview > summary .ua-icon {
  margin-left: auto;
  transition: transform var(--ua-fast) var(--ua-ease);
}

details.se-preview[open] > summary .ua-icon {
  transform: rotate(180deg);
}

/* The rendered section sits flush — book styles apply inside untouched. */
.se-preview .sb-section {
  margin-top: 0;
  padding-top: 0;
  border-top: 0;
}

.se-preview .sb-section__body {
  margin-top: 0;
}

/* ======================================================================
   Section editor — sticky bottom action bar
   ====================================================================== */
.se-bar {
  position: sticky;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: var(--ua-s2) var(--ua-s3);
  margin-top: var(--ua-s5);
  padding: var(--ua-s3) clamp(var(--ua-s4), 3vw, var(--ua-s5));
  background: var(--ua-bg-raised);
  border-top: 1px solid var(--ua-line-soft);
  border-radius: var(--ua-radius-lg) var(--ua-radius-lg) 0 0;
}

/* Dirty state — quiet dot + label, left of the actions. */
.se-bar__dirty,
.se-bar .is-dirty {
  display: inline-flex;
  align-items: center;
  gap: var(--ua-s2);
  margin-right: auto;
  font-size: var(--ua-fs-tiny);
  font-weight: 200;
  letter-spacing: 0.04em;
  color: var(--ua-text-muted);
}

.se-bar__dirty::before,
.se-bar .is-dirty::before {
  content: '';
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ua-status-changes);
}

/* Saved / status line without the dot. */
.se-bar__status,
.se-bar > p {
  margin: 0 auto 0 0;
  font-size: var(--ua-fs-tiny);
  font-weight: 200;
  letter-spacing: 0.04em;
  color: var(--ua-text-muted);
}

/* ======================================================================
   Section editor — "Advanced: edit as JSON" escape hatch
   ====================================================================== */
.se-json {
  padding-top: var(--ua-s4);
  border-top: 1px solid var(--ua-line-soft);
}

.se-json > summary {
  display: flex;
  align-items: center;
  gap: var(--ua-s2);
  font-size: var(--ua-fs-tiny);
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: var(--ua-tracking-caps);
  color: var(--ua-text-muted);
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.se-json > summary::-webkit-details-marker {
  display: none;
}

.se-json > summary:hover {
  color: var(--ua-text-strong);
}

.se-json > summary .ua-icon {
  transition: transform var(--ua-fast) var(--ua-ease);
}

.se-json[open] > summary .ua-icon {
  transform: rotate(180deg);
}

.se-json > summary + * {
  margin-top: var(--ua-s3);
}

.se-json textarea,
.se-json textarea.ua-input {
  width: 100%;
  min-height: 12rem;
  font-family: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.55;
  white-space: pre;
  overflow-x: auto;
  tab-size: 2;
  resize: vertical;
}

.se-json .ua-btn {
  margin-top: var(--ua-s3);
}

.se-json__error,
.se-json [role='alert'] {
  margin: var(--ua-s2) 0 0;
  font-size: var(--ua-fs-tiny);
  font-weight: 400;
  color: var(--ua-status-danger);
}

/* ======================================================================
   Responsive
   ====================================================================== */
@media (max-width: 1100px) {
  .se-layout {
    grid-template-columns: minmax(0, 1fr);
  }

  .se-preview {
    position: static;
    max-height: none;
    overflow: visible;
  }
}

@media (max-width: 1000px) {
  .st-grid {
    grid-template-columns: minmax(0, 1fr);
  }
}

@media (max-width: 768px) {
  .st-grid {
    margin-block: var(--ua-s4) var(--ua-s7);
  }

  .pe-layout {
    padding-block: var(--ua-s4) var(--ua-s7);
    gap: var(--ua-s4);
  }

  .se-layout {
    margin-top: var(--ua-s4);
    gap: var(--ua-s4);
  }

  .pe-sections > li,
  .pe-section {
    padding: var(--ua-s3);
  }
}

@media (max-width: 480px) {
  .st-panel,
  .pe-panel,
  .pe-danger,
  .se-form {
    padding: var(--ua-s4);
  }

  .st-empty {
    padding: var(--ua-s6) var(--ua-s4);
  }

  .se-listitem {
    padding: var(--ua-s3) var(--ua-s3) var(--ua-s4);
  }

  .se-listitem > header,
  .se-listitem__head {
    margin: calc(-1 * var(--ua-s3)) calc(-1 * var(--ua-s3)) 0;
    padding-left: var(--ua-s3);
  }

  .pe-chip > span {
    max-width: 14ch;
  }

  .se-bar {
    padding-inline: var(--ua-s3);
  }

  .se-bar .ua-btn {
    flex: 1 1 auto;
  }

  .se-bar__dirty,
  .se-bar .is-dirty,
  .se-bar__status,
  .se-bar > p {
    flex: 1 1 100%;
    margin-right: 0;
  }
}

/* ======================================================================
   Reduced motion
   ====================================================================== */
@media (prefers-reduced-motion: reduce) {
  .st-switch input[type='checkbox'],
  .st-switch input[type='checkbox']::before,
  input.st-switch,
  input.st-switch::before,
  .pe-chip,
  .pe-chip button,
  .pe-chip .ua-btn,
  .se-listitem > header button,
  .se-listitem__head button,
  .se-preview > summary .ua-icon,
  .se-json > summary .ua-icon {
    transition: none !important;
    animation: none !important;
  }
}
