.ndv-hidden {
  display: none !important;
}

.ndv-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
  background: rgba(9, 13, 22, 0.58);
  backdrop-filter: blur(2px);
}

.ndv-overlay.ndv-hidden {
  display: none;
}

.ndv-dialog {
  width: min(96vw, 1680px);
  height: 94vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  overflow: hidden;
  color: var(--text, var(--wf-text, #111827));
  background: var(--surface, var(--wf-surface, #f8f9fb));
  border: 1px solid var(--stroke, var(--wf-border, #d1d5db));
  border-radius: 16px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  font-family: "Space Grotesk", "Inter", system-ui, sans-serif;
}

.ndv-header {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--stroke, var(--wf-border, #d1d5db));
}

.ndv-heading {
  min-width: 0;
}

.ndv-title {
  margin: 0;
  overflow: hidden;
  color: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ndv-subtitle {
  margin: 3px 0 0;
  overflow: hidden;
  color: var(--muted, var(--wf-text-muted, #6b7280));
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ndv-button,
.ndv-original {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 7px 11px;
  color: inherit;
  background: var(--surface-muted, var(--wf-surface-soft, #f3f4f6));
  border: 1px solid var(--stroke, var(--wf-border, #d1d5db));
  border-radius: 9px;
  cursor: pointer;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}

.ndv-button:hover,
.ndv-original:hover {
  border-color: var(--muted, #9ca3af);
}

.ndv-button:disabled {
  cursor: default;
  opacity: 0.38;
}

.ndv-close {
  flex: 0 0 auto;
  min-width: 84px;
}

.ndv-toolbar {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 7px;
  padding: 8px 14px;
  background: var(--surface-muted, var(--wf-surface-soft, #f3f4f6));
  border-bottom: 1px solid var(--stroke, var(--wf-border, #d1d5db));
}

.ndv-page-label {
  min-width: 96px;
  color: var(--muted, var(--wf-text-muted, #6b7280));
  font-size: 0.78rem;
  text-align: center;
}

.ndv-viewport {
  position: relative;
  min-height: 0;
  overflow: auto;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  background:
    linear-gradient(45deg, rgba(127, 127, 127, 0.045) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(127, 127, 127, 0.045) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(127, 127, 127, 0.045) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(127, 127, 127, 0.045) 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
}

.ndv-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  background: #fff;
  box-shadow: 0 3px 16px rgba(0, 0, 0, 0.14);
}

.ndv-loader {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}

.ndv-loader::before {
  width: 30px;
  height: 30px;
  content: "";
  border: 3px solid rgba(107, 114, 128, 0.28);
  border-top-color: var(--text, var(--wf-text, #111827));
  border-radius: 50%;
  animation: ndv-spin 0.75s linear infinite;
}

.ndv-loader.ndv-hidden,
.ndv-error.ndv-hidden {
  display: none;
}

.ndv-error {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  color: #c62828;
  background: var(--surface, var(--wf-surface, #f8f9fb));
  font-size: 0.88rem;
  text-align: center;
}

body[data-theme="dark"] .ndv-dialog {
  color: var(--text, #e5e7eb);
  background: var(--surface, #191b20);
}

body[data-theme="dark"] .ndv-toolbar,
body[data-theme="dark"] .ndv-button,
body[data-theme="dark"] .ndv-original {
  background: var(--surface-muted, #22252b);
}

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

@media (max-width: 720px) {
  .ndv-overlay {
    padding: 0;
  }

  .ndv-dialog {
    width: 100vw;
    height: 100dvh;
    border-radius: 0;
  }

  .ndv-header {
    padding: 11px 12px;
  }

  .ndv-title {
    font-size: 0.92rem;
  }

  .ndv-subtitle,
  .ndv-original {
    display: none;
  }

  .ndv-toolbar {
    min-height: 46px;
    padding: 6px 8px;
  }

  .ndv-button {
    min-height: 32px;
    padding: 6px 9px;
  }

  .ndv-close {
    min-width: auto;
  }

  .ndv-viewport {
    padding: 8px;
  }
}
