/* Two-sided menu preview (adapted from business-card-builder flip) */
.kmb-design-form-wrapper--split {
  overflow: visible;
}

.kmb-design-form-wrapper--split .kmb-design-form-layout {
  overflow: visible;
}

.kmb-design-form-preview {
  min-width: 0;
  box-sizing: border-box;
}

.kmb-preview-mobile-toggle {
  display: none;
}

.kmb-preview-panel-inner {
  display: block;
}

.kmb-menu-flip-stage {
  position: relative;
}

.kmb-menu-flip-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.kmb-menu-flip-tool {
  appearance: none;
  border: 2px solid #c6007e;
  background: #fff;
  color: #c6007e;
  min-height: 40px;
  padding: 0 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.kmb-menu-flip-tool.is-active {
  background: #c6007e;
  border-color: #c6007e;
  color: #fff;
}

.kmb-menu-flip-tool:disabled {
  opacity: 0.4;
  cursor: default;
}

.kmb-menu-flip-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 24px;
  font-size: 13px;
  color: #64748b;
  margin-bottom: 8px;
}

.kmb-menu-flip-status-text {
  line-height: 1.4;
}

.kmb-menu-flip-spinner {
  display: none;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(198, 0, 126, 0.2);
  border-top-color: #c6007e;
  border-radius: 50%;
  animation: kmb-preview-spin 0.7s linear infinite;
}

.kmb-menu-flip-spinner--large {
  width: 36px;
  height: 36px;
  border-width: 3px;
}

.kmb-menu-flip-status.is-busy .kmb-menu-flip-spinner,
.kmb-menu-flip-card.is-loading .kmb-menu-flip-loading .kmb-menu-flip-spinner {
  display: inline-block;
}

.kmb-menu-flip-status.is-busy {
  color: #475569;
}

@keyframes kmb-preview-spin {
  to {
    transform: rotate(360deg);
  }
}

.kmb-menu-flip-wrap {
  width: 100%;
  max-width: 100%;
  display: flex;
  justify-content: center;
  /* Own compositor layer — avoids sticky + nested perspective scroll glitches */
  transform: translate3d(0, 0, 0);
  isolation: isolate;
}

/* Menu PDF page ratio (604×850). Size from column width, not vh (vh shifts with scroll/sticky). */
.kmb-menu-flip-card {
  position: relative;
  width: 100%;
  max-width: min(100%, 420px);
  aspect-ratio: 604 / 850;
  height: auto;
  margin: 0 auto;
  transform-style: preserve-3d;
  transform: perspective(1400px) rotateY(0deg);
  transform-origin: center center;
  transition: transform 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
  will-change: transform;
}

.kmb-menu-flip-card[data-preview-side="back"] {
  transform: perspective(1400px) rotateY(180deg);
}

.kmb-menu-flip-face {
  position: absolute;
  inset: 0;
  overflow: hidden;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  box-shadow: 0 16px 40px rgba(15, 23, 42, 0.14);
  backface-visibility: hidden;
  background: #f8fafc;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kmb-menu-flip-front {
  transform: rotateY(0deg) translateZ(1px);
}

.kmb-menu-flip-back {
  transform: rotateY(180deg) translateZ(1px);
}

/* Do not stretch canvas — keep PDF.js pixel aspect (distortion was width/height 100%) */
.kmb-menu-flip-face canvas {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin: 0 auto;
}

.kmb-menu-flip-loading {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: rgba(255, 255, 255, 0.88);
  font-size: 14px;
  font-weight: 600;
  color: #475569;
  border-radius: 8px;
  backface-visibility: hidden;
  /* Above flip faces (translateZ(1px)) inside preserve-3d card */
  transform: translateZ(12px);
  pointer-events: none;
}

.kmb-menu-flip-loading .kmb-menu-flip-spinner {
  display: inline-block;
}

.kmb-menu-flip-card.is-loading .kmb-menu-flip-loading {
  display: flex;
  pointer-events: auto;
}

/* Counter-rotate when viewing back so text reads normally */
.kmb-menu-flip-card[data-preview-side="back"] .kmb-menu-flip-loading {
  transform: rotateY(180deg) translateZ(12px);
}

.kmb-menu-flip-placeholder {
  padding: 1.5rem;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: #c6007e;
  line-height: 1.5;
}

/* Design switcher (products in menu design category) */
.kmb-design-switcher {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid #e8e8e8;
}

.kmb-design-switcher-label {
  margin: 0 0 10px;
  font-size: 13px;
  font-weight: 700;
  color: #334155;
  letter-spacing: 0.02em;
}

.kmb-design-switcher-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.kmb-design-switcher-thumb {
  appearance: none;
  flex: 0 0 auto;
  width: 64px;
  height: 64px;
  padding: 3px;
  margin: 0;
  border: 2px solid #e2e8f0;
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  overflow: hidden;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.kmb-design-switcher-thumb:hover {
  border-color: #c6007e;
}

.kmb-design-switcher-thumb.is-active {
  border-color: #c6007e;
  box-shadow: 0 0 0 2px rgba(198, 0, 126, 0.25);
}

.kmb-design-switcher-thumb:focus-visible {
  outline: 2px solid #c6007e;
  outline-offset: 2px;
}

.kmb-design-switcher-thumb img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 4px;
}

.kmb-design-switcher-thumb-fallback {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #f1f5f9 0%, #e2e8f0 100%);
  border-radius: 4px;
}

/* Desktop: sticky preview column — scale card down on short viewports so the footer is not clipped */
@media (min-width: 961px) {
  .kmb-design-form-preview {
    position: sticky;
    top: 1.25rem;
    --kmb-preview-sticky-top: 1.25rem;
    /* Toolbar, status line, design switcher, and padding below the card */
    --kmb-preview-chrome-below: 11.5rem;
    align-self: start;
    z-index: 20;
    overflow: visible;
    padding-bottom: 0.5rem;
    box-sizing: border-box;
    /* Do not transform the sticky box itself — 3D lives inside .kmb-menu-flip-wrap */
  }

  .kmb-menu-flip-stage {
    transform: translate3d(0, 0, 0);
  }

  .kmb-menu-flip-card {
    width: min(
      100%,
      420px,
      calc(
        (100vh - var(--kmb-preview-sticky-top) - var(--kmb-preview-chrome-below)) * 604 / 850
      )
    );
  }

  @supports (height: 100dvh) {
    .kmb-menu-flip-card {
      width: min(
        100%,
        420px,
        calc(
          (100dvh - var(--kmb-preview-sticky-top) - var(--kmb-preview-chrome-below)) * 604 / 850
        )
      );
    }
  }

  body.admin-bar .kmb-design-form-preview {
    top: calc(32px + 1.25rem);
    --kmb-preview-sticky-top: calc(32px + 1.25rem);
  }

  @media screen and (min-width: 783px) {
    body.admin-bar .kmb-design-form-preview {
      top: calc(46px + 1.25rem);
      --kmb-preview-sticky-top: calc(46px + 1.25rem);
    }
  }
}

@media (prefers-reduced-motion: reduce) {
  .kmb-menu-flip-card {
    transition: none;
    will-change: auto;
  }
}