body.has-preview-modal {
  position: fixed;
  inset: 0;
  width: 100%;
  overflow: hidden;
}

body.has-preview-modal .detail-dock {
  opacity: 0;
  pointer-events: none;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding:
    calc(var(--safe-top) + 0.75rem)
    calc(var(--safe-right) + 0.75rem)
    calc(var(--safe-bottom) + 0.75rem)
    calc(var(--safe-left) + 0.75rem);
}

.preview-modal[hidden] {
  display: none;
}

.preview-modal__backdrop {
  position: absolute;
  inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(8px);
}

.preview-modal__dialog {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: min(1120px, 100%);
  max-width: calc(100vw - var(--safe-left) - var(--safe-right) - 1.5rem);
  height: min(88dvh, 860px);
  max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 1.5rem);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-lg);
  background: var(--panel-strong);
  box-shadow: 0 24px 80px rgba(39, 49, 68, 0.2);
  overflow: hidden;
}

.preview-modal__dialog:fullscreen {
  width: 100vw;
  height: 100dvh;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 0;
}

.preview-modal__dialog:fullscreen::backdrop {
  background: var(--overlay);
  backdrop-filter: blur(8px);
}

.preview-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.15rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.preview-modal__eyebrow {
  display: block;
  margin-bottom: 0.15rem;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.preview-modal__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  justify-content: flex-end;
  align-items: center;
}

.preview-modal__frame {
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: var(--preview-frame-bg);
}

.preview-modal__viewport {
  position: relative;
  min-height: 0;
}

.preview-modal__frame.is-loading {
  opacity: 0;
}

.preview-modal__loading {
  position: absolute;
  inset: 0;
  z-index: 1;
  display: grid;
  place-items: center;
  padding: clamp(1rem, 2vw, 1.4rem);
  background:
    linear-gradient(180deg, color-mix(in srgb, var(--preview-frame-bg) 92%, transparent), color-mix(in srgb, var(--panel) 88%, transparent));
  transition: opacity 160ms ease;
}

.preview-modal__loading[hidden] {
  display: none;
}

.preview-modal__loading-card {
  width: min(30rem, 100%);
  display: grid;
  justify-items: center;
  gap: 0.65rem;
  padding: 1.2rem 1.25rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(39, 49, 68, 0.14);
  text-align: center;
}

.preview-modal__loading-card strong {
  font-size: 1.02rem;
}

.preview-modal__loading-card p {
  margin: 0;
  color: var(--muted);
}

.preview-modal__loading-note {
  font-size: 0.94rem;
}

.preview-modal__spinner {
  width: 2.8rem;
  height: 2.8rem;
  border: 3px solid color-mix(in srgb, var(--line) 90%, transparent);
  border-top-color: var(--primary);
  border-radius: 999px;
  animation: preview-spin 0.9s linear infinite;
}

.json-block {
  margin: 0;
  padding: 1rem;
  overflow-x: auto;
  border-radius: var(--radius-md);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  word-break: break-word;
}

.break-word {
  word-break: break-word;
}

.empty-state {
  text-align: center;
}

@keyframes rise-fade {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@media (max-width: 980px) {
  .preview-modal {
    padding:
      calc(var(--safe-top) + 0.5rem)
      calc(var(--safe-right) + 0.5rem)
      calc(var(--safe-bottom) + 0.5rem)
      calc(var(--safe-left) + 0.5rem);
  }

  .preview-modal__dialog {
    width: 100%;
    max-width: calc(100vw - var(--safe-left) - var(--safe-right) - 1rem);
    height: min(92dvh, 860px);
    max-height: calc(100dvh - var(--safe-top) - var(--safe-bottom) - 1rem);
  }

  .preview-modal__header {
    align-items: start;
    flex-direction: column;
  }

  .preview-modal__actions {
    width: 100%;
    justify-content: flex-start;
  }

  .preview-modal__loading-card {
    width: min(34rem, 100%);
  }
}

@media (max-width: 720px) {
  .preview-modal {
    place-items: stretch;
    padding: 0;
  }

  .preview-modal__dialog {
    width: 100%;
    max-width: none;
    height: 100dvh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .preview-modal__header {
    padding:
      calc(var(--safe-top) + 0.8rem)
      calc(var(--safe-right) + 0.9rem)
      0.85rem
      calc(var(--safe-left) + 0.9rem);
  }

  .preview-modal__actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  .preview-modal__actions > :last-child {
    grid-column: 1 / -1;
  }

  .preview-modal__actions .button {
    width: 100%;
    justify-content: center;
  }

  .preview-modal__loading {
    padding:
      calc(var(--safe-top) + 1rem)
      calc(var(--safe-right) + 1rem)
      calc(var(--safe-bottom) + 1rem)
      calc(var(--safe-left) + 1rem);
  }

  .preview-modal__loading-card {
    padding: 1rem 1rem 1.05rem;
    border-radius: var(--radius-md);
  }
}
