/*
 * Bestles Interne Website – iPhone-Vorschau-Rahmen (Cards-Modul, Spalte 3)
 */

.iphone-preview-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 24px 16px;
  flex-shrink: 0;
}

.iphone-frame {
  --iphone-bezel: 12px;
  --iphone-radius: 48px;
  --iphone-max-width: 256px;
  --iphone-preview-font-root: 19;
  /* iPhone 17 — 402 × 874 pt (6,3") */
  --iphone-screen-w: 402;
  --iphone-screen-h: 874;
  position: relative;
  width: min(100%, var(--iphone-max-width));
  aspect-ratio: var(--iphone-screen-w) / var(--iphone-screen-h);
  min-height: calc(min(100%, var(--iphone-max-width)) * var(--iphone-screen-h) / var(--iphone-screen-w));
  flex-shrink: 0;
  box-sizing: border-box;
  background: #000;
  border: var(--iphone-bezel) solid #000;
  border-radius: var(--iphone-radius);
  box-shadow:
    0 0 0 1px rgba(255, 255, 255, 0.06),
    0 16px 48px var(--shadow);
  overflow: hidden;
}

.iphone-frame__notch {
  position: absolute;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 38%;
  height: 28px;
  background: #000;
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 14px;
  z-index: 2;
}

.iphone-frame__screen {
  container-type: inline-size;
  position: absolute;
  inset: 0;
  background: var(--color-bg);
  border-radius: calc(var(--iphone-radius) - var(--iphone-bezel));
  overflow: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.iphone-frame__screen::-webkit-scrollbar {
  display: none;
}

.iphone-frame__screen iframe,
.iphone-frame__screen .iphone-preview-content {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

.iphone-frame__screen .iphone-preview-content {
  /* 402pt-Device: skaliert auf sichtbare Screen-Breite (--iphone-preview-font-root ≈ pt-Root) */
  font-size: calc(100cqw * var(--iphone-preview-font-root) / var(--iphone-screen-w));
}

.iphone-frame--zoomable {
  cursor: zoom-in;
}

.iphone-frame--zoomable:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 4px;
}

/* Text- & Bildmodus Desktop: iPhone volle Spaltenhöhe */
@media (min-width: 881px) {
  .pb-main--view-text .iphone-preview-wrap,
  .pb-main--view-bild .iphone-preview-wrap {
    width: 100%;
    height: 100%;
    flex: 1 1 auto;
    min-height: 0;
    padding: 12px;
    justify-content: center;
    box-sizing: border-box;
  }

  .pb-main--view-text .iphone-frame,
  .pb-main--view-bild .iphone-frame {
    height: 100%;
    width: auto;
    min-height: 0;
    max-height: 100%;
    flex-shrink: 0;
  }
}

@media (max-width: 880px) {
  .pb-main--view-text .iphone-preview-wrap,
  .pb-main--view-bild .iphone-preview-wrap {
    height: auto;
    padding: 24px 16px;
  }

  .pb-main--view-text .iphone-frame,
  .pb-main--view-bild .iphone-frame {
    height: auto;
    width: min(100%, var(--iphone-max-width));
    min-height: calc(min(100%, var(--iphone-max-width)) * var(--iphone-screen-h) / var(--iphone-screen-w));
    max-width: none;
  }
}

/* —— Vollbild-Overlay —— */

.iphone-preview-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--overlay);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-sizing: border-box;
}

@supports (color: color-mix(in srgb, red, blue)) {
  .iphone-preview-overlay {
    background: color-mix(in srgb, var(--bg) 88%, transparent);
  }
}

.iphone-preview-overlay[hidden] {
  display: none !important;
}

.iphone-preview-overlay__close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  z-index: 2;
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.iphone-preview-overlay__close:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.iphone-preview-overlay__frame {
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
  max-height: calc(var(--ui-viewport-h) - 4rem);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.iphone-preview-overlay__frame .iphone-frame {
  --iphone-max-width: min(
    calc((var(--ui-viewport-h) - 5rem) * var(--iphone-screen-w) / var(--iphone-screen-h)),
    calc(100vw - 3rem)
  );
  --iphone-bezel: 14px;
  --iphone-radius: 52px;
  width: min(100%, var(--iphone-max-width));
  min-height: calc(min(100%, var(--iphone-max-width)) * var(--iphone-screen-h) / var(--iphone-screen-w));
  max-height: calc(var(--ui-viewport-h) - 5rem);
  pointer-events: auto;
  cursor: default;
}

.iphone-preview-overlay__frame .iphone-frame__notch {
  height: 32px;
}

/* —— Mobile Overlay: nativer Vollbildmodus ohne Device-Rahmen (≤880px) —— */

@media (max-width: 880px) {
  .iphone-preview-overlay:not([hidden]) {
    padding: 0;
    align-items: stretch;
    justify-content: stretch;
    background: var(--bg);
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
  }

  @supports (color: color-mix(in srgb, red, blue)) {
    .iphone-preview-overlay:not([hidden]) {
      background: var(--bg);
    }
  }

  .iphone-preview-overlay:not([hidden]) .iphone-preview-overlay__close {
    top: max(0.35rem, env(safe-area-inset-top, 0px));
    right: max(0.35rem, env(safe-area-inset-right, 0px));
    z-index: 10;
    width: 1.5rem;
    height: 1.5rem;
    padding: 0;
    font-size: 1rem;
    line-height: 1;
    border: none;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-muted);
    opacity: 0.5;
    box-shadow: none;
  }

  .iphone-preview-overlay:not([hidden]) .iphone-preview-overlay__close:hover,
  .iphone-preview-overlay:not([hidden]) .iphone-preview-overlay__close:focus-visible {
    opacity: 0.85;
    color: var(--text);
    border: none;
  }

  .iphone-preview-overlay:not([hidden]) .iphone-preview-overlay__frame {
    flex: 1 1 auto;
    width: 100%;
    height: 100%;
    max-height: none;
    align-items: stretch;
    justify-content: stretch;
    pointer-events: auto;
  }

  .iphone-preview-overlay:not([hidden]) .iphone-preview-overlay__frame .iphone-frame {
    --iphone-bezel: 0px;
    --iphone-radius: 0px;
    --iphone-max-width: 100%;
    width: 100%;
    height: 100%;
    min-height: 100dvh;
    max-width: none;
    max-height: none;
    aspect-ratio: unset;
    border: none;
    border-radius: 0;
    background: var(--bg);
    box-shadow: none;
    pointer-events: auto;
  }

  .iphone-preview-overlay:not([hidden]) .iphone-frame__notch {
    display: none;
  }

  .iphone-preview-overlay:not([hidden]) .iphone-frame__screen {
    position: absolute;
    inset: 0;
    border-radius: 0;
    background: var(--bg);
  }

  .iphone-preview-overlay:not([hidden]) .iphone-frame__screen .iphone-preview-content {
    min-height: 100%;
  }

  .iphone-preview-overlay:not([hidden]),
  .iphone-preview-overlay.is-native {
    touch-action: pan-y;
  }
}

/* Legacy-Klasse (JS) — identisch zu Media Query oben */
.iphone-preview-overlay.is-native {
  padding: 0;
  background: var(--bg);
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

.iphone-preview-overlay.is-native .iphone-preview-overlay__close {
  top: max(0.35rem, env(safe-area-inset-top, 0px));
  right: max(0.35rem, env(safe-area-inset-right, 0px));
  z-index: 10;
  width: 1.5rem;
  height: 1.5rem;
  font-size: 1rem;
  border: none;
  background: transparent;
  color: var(--text-muted);
  opacity: 0.5;
}

.iphone-preview-overlay.is-native .iphone-preview-overlay__frame {
  width: 100%;
  height: 100%;
  max-height: none;
  align-items: stretch;
  justify-content: stretch;
}

.iphone-preview-overlay.is-native .iphone-preview-overlay__frame .iphone-frame {
  --iphone-bezel: 0px;
  --iphone-radius: 0px;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  max-width: none;
  max-height: none;
  aspect-ratio: unset;
  border: none;
  border-radius: 0;
  background: var(--bg);
  box-shadow: none;
}

.iphone-preview-overlay.is-native .iphone-frame__notch {
  display: none;
}

.iphone-preview-overlay.is-native .iphone-frame__screen {
  border-radius: 0;
  background: var(--bg);
}

.pb-mobile .iphone-preview-wrap {
  padding: 12px;
  justify-content: center;
}

.pb-mobile .iphone-preview-wrap .iphone-frame {
  --iphone-max-width: min(100%, 220px);
}
