.text-product-media:not(:has(.texteditor-inline__preview[data-has-text="true"])) #custombee-configurator-template,
.text-product-media:has(.texteditor-inline__preview[data-has-text="true"]) .text-product-media__gallery {
  display: none;
}

.text-preview-placeholder__bar {
  display: block;
  height: 1em;
  border-radius: .25rem;
  background: color-mix(in srgb, var(--preview-ink) 10%, transparent);
}

/* Ignore server-rendered whitespace; hide skeletons only once actual content mounts. */
#custombee-configurator-container .text-editor-mount:not(:has(> *)),
#custombee-configurator-container .text-editor-mount:has(> *) + .text-controls-placeholder {
  display: none;
}

.text-controls-placeholder {
  --preview-ink: var(--theme-ink, var(--foreground, #212529));
  display: grid;
  gap: 0;
  align-content: start;
}

.text-controls-placeholder__label {
  width: 30%;
  max-width: 12rem;
  height: 24px;
  margin: 12px 0 6.4px;
}

.text-controls-placeholder__field {
  min-height: 38px;
  border: 1px solid var(--border-default-color, #dee2e6);
  border-radius: var(--theme-radius, var(--border-default-radius, .5rem));
  background: color-mix(in srgb, var(--preview-ink) 4%, transparent);
}

.text-controls-placeholder__textarea {
  min-height: 62px;
}

.text-controls-placeholder__columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}

/* Reserve the initial editor footprint through bundle and font loading. */
#custombee-configurator-container :is(.text-controls-placeholder, .texteditorform.texteditor-inline) {
  min-height: 101rem;
}

@media (min-width: 768px) {
  #custombee-configurator-container :is(.text-controls-placeholder, .texteditorform.texteditor-inline) {
    min-height: 93rem;
  }
}

.text-controls-placeholder__step { padding-bottom: 12px; }
.text-controls-placeholder__step + .text-controls-placeholder__step { margin-top: 12.8px; }
.text-controls-placeholder__step:first-child { padding-bottom: 28px; }
.text-controls-placeholder__step:nth-child(2) { min-height: 187.4px; }
.text-controls-placeholder__step:nth-child(3) { min-height: 92.4px; }
.text-controls-placeholder__step:nth-child(4) { min-height: 264.3px; }
.text-controls-placeholder__step:nth-child(5) { min-height: 117.4px; }
.text-controls-placeholder__step:nth-child(6) { min-height: 97.2px; }
.text-controls-placeholder__step:nth-child(7) { min-height: 411px; }
@media (max-width: 767px) {
  .text-controls-placeholder__step:nth-child(2) { min-height: 208.4px; }
  .text-controls-placeholder__step:nth-child(4) { min-height: 317.1px; }
  .text-controls-placeholder__step:nth-child(5) { min-height: 180.4px; }
}

/* Keep Spree's price visible until the embedded editor has calculated its price. */
#product-details-page:has(.texteditor-inline[data-price-ready="true"]) [data-text-price-placeholder] {
  display: none;
}

@media (max-width: 1023px) {
  /* A block layout lets the preview stick throughout the product details. */
  #product-details-page:has(.text-product-media) {
    display: block;
    padding-bottom: calc(8.5rem + env(safe-area-inset-bottom, 0px));
  }

  #product-details-page > :has(.text-product-media [data-has-text="true"]) {
    position: sticky;
    top: var(--text-editor-sticky-top, 0px);
    z-index: 30;
  }

  .text-product-media:has([data-has-text="true"]) {
    background: var(--theme-surface, var(--background, #fff));
    box-shadow: 0 4px 12px rgb(0 0 0 / 8%);
  }

  #custombee-configurator-template .texteditor-inline__preview {
    display: flex;
    flex-direction: column;
    position: relative;
    height: auto;
    max-height: none;
    overflow: visible;
    padding: .5rem .75rem;
  }

  #custombee-configurator-template .texteditor-inline__preview-content,
  #custombee-configurator-template .texteditor-inline__preview-content > div {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
  }

  #custombee-configurator-template .texteditor-inline__preview-content {
    position: absolute;
    top: 100%;
    left: -1px;
    right: -1px;
    height: min(24dvh, 8rem);
    padding: .5rem .75rem .75rem;
    background: var(--theme-surface, var(--background, #fff));
    border: 1px solid var(--border-default-color, #dee2e6);
    border-top: 0;
    border-radius: 0 0 var(--theme-radius, .5rem) var(--theme-radius, .5rem);
    box-shadow: 0 6px 12px rgb(0 0 0 / 8%);
    clip-path: inset(0 -1rem -1rem -1rem);
    opacity: 1;
    transform: translateY(0);
    visibility: visible;
    transition:
      clip-path 260ms cubic-bezier(.22, 1, .36, 1),
      opacity 180ms ease,
      transform 260ms cubic-bezier(.22, 1, .36, 1),
      visibility 0s linear;
  }

  #custombee-configurator-template .texteditor-inline__preview .svg-preview {
    flex: 1;
    min-width: 0;
    min-height: 0;
    height: auto !important;
    aspect-ratio: auto !important;
    padding: .5rem;
  }

  #custombee-configurator-template .texteditor-inline__preview .svg-preview svg {
    /* The SVG viewBox contains the full lettering; fit it to both bounds. */
    width: 100%;
    height: 100% !important;
    min-height: 0;
  }

  #custombee-configurator-template .texteditor-inline__preview-content > h3,
  #custombee-configurator-template .texteditor-inline__preview-content > p {
    display: none !important;
  }

  #custombee-configurator-template .texteditor-inline__preview-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    width: 100%;
    min-height: 36px;
    padding: 0;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
  }

  #custombee-configurator-template .texteditor-inline__preview-toggle:focus-visible {
    outline: 2px solid var(--theme-action, var(--primary, #0d6efd));
    outline-offset: 2px;
  }

  #custombee-configurator-template .texteditor-inline__preview-toggle svg {
    transition: transform 260ms cubic-bezier(.22, 1, .36, 1);
  }

  #custombee-configurator-template [data-preview-expanded="true"] .texteditor-inline__preview-toggle svg {
    transform: rotate(180deg);
  }

  #custombee-configurator-template [data-preview-expanded="false"] {
    height: auto;
  }

  #custombee-configurator-template [data-preview-expanded="false"] .texteditor-inline__preview-content {
    /* Keep SVG measurements available while the panel is collapsed. */
    clip-path: inset(0 -1rem 100% -1rem);
    opacity: 0;
    transform: translateY(-.375rem);
    visibility: hidden;
    pointer-events: none;
    transition-duration: 160ms, 120ms, 160ms, 0s;
    transition-delay: 0s, 0s, 0s, 160ms;
  }

  #custombee-configurator-container .texteditor-inline__actions {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 40;
    padding: .75rem 1rem calc(.75rem + env(safe-area-inset-bottom, 0px));
    background: var(--theme-surface, var(--background, #fff));
    border-top: 1px solid var(--border-default-color, #dee2e6);
    box-shadow: 0 -4px 12px rgb(0 0 0 / 8%);
  }

  #custombee-configurator-container .texteditor-inline__actions .texteditor-inline__submit {
    margin: 0;
  }

  #custombee-configurator-container :is(input, textarea, select, [role="combobox"]) {
    scroll-margin-top: calc(var(--text-editor-sticky-top, 0px) + 30dvh + 1rem);
    scroll-margin-bottom: calc(8.5rem + env(safe-area-inset-bottom, 0px));
  }
}

/* The existing quantity selector stays in the form on desktop. */
#custombee-configurator-container .texteditor-inline__sticky-order {
  display: none;
}

@media (max-width: 1023px) {
  #custombee-configurator-container .texteditor-inline__quantity {
    display: none;
  }

  #custombee-configurator-container .texteditor-inline__sticky-order {
    display: block;
    margin-bottom: .5rem;
  }

  #custombee-configurator-container .texteditor-inline__sticky-order .order-variant-picker__per-piece {
    display: block;
    color: var(--theme-ink, var(--foreground, #212529));
    font-size: 1rem;
    font-weight: 700;
  }

  #custombee-configurator-container .texteditor-inline__sticky-order .order-variant-picker__meta > .order-variant-picker__badge {
    display: none;
  }

  #custombee-configurator-container .texteditor-inline__sticky-order .order-variant-picker__menu {
    max-height: min(50dvh, 20rem);
    overflow-y: auto;
    width: 100%;
    min-width: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  #custombee-configurator-template .texteditor-inline__preview-content,
  #custombee-configurator-template .texteditor-inline__preview-toggle svg {
    transition: none;
  }
}
