.pdf-preview {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;

  &__body {
    display: flex;
    flex: 1;
    overflow: hidden;
    min-height: 0;
    position: relative;

    .react-pdf__Document,
    .react-pdf__message {
      // .react-pdf__message wraps the loading skeleton of <Document>
      // See: https://github.com/wojtekmaj/react-pdf/blob/ff7f698a383bcba3e1af4bd8d72944762bb5e5c0/packages/react-pdf/src/Document.tsx#L630-L634
      display: flex;
      flex: 1;
      min-height: 0;
    }
  }

  &__container {
    flex: 1;
    overflow: hidden;
    min-height: 400px;

    &-skeleton {
      display: flex;
      justify-content: center;
      flex: 1;
      // So the skeleton aspect ratio could be respected.
      align-items: flex-start;
      padding: 16px 16px 0 16px;
    }

    .react-pdf__Document {
      height: 100%;
    }
  }

  &__page-skeleton {
    border-radius: 4px;
    background: var(--c--contextuals--background--surface--primary);
    box-shadow: 0 3.649px 14.597px 0 rgba(0, 0, 0, 0.1);
    animation: pdf-skeleton-pulse 1.5s ease-in-out infinite;
    max-width: 800px;
    width: 100%;
    aspect-ratio: 1 / 1.414;
  }

  &__sidebar {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 5;
    width: 150px;
    overflow: hidden;

    padding: 12px 0;
    border-right: 1px solid var(--c--contextuals--border--surface--primary);
    background: var(--c--contextuals--background--surface--primary);
    transform: translateX(0);
    transition: transform 0.3s;

    .react-pdf__Document {
      height: 100%;
    }

    &--closed {
      transform: translateX(-100%);
    }

    [role="gridcell"] {
      display: flex;
      justify-content: center;
    }
  }

  &__thumbnail {
    cursor: pointer;
    border: none;
    background: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: border-color 0.15s ease;
    box-sizing: border-box;
    margin: 0 auto;

    .react-pdf__Thumbnail {
      box-shadow: 0 0.5px 5px 0 rgba(0, 0, 0, 0.1);
      border-radius: 4px;
      overflow: hidden;
      border: 2px solid transparent;
    }

    &--active {
      .react-pdf__Thumbnail {
        border: 2px solid
          var(--c--contextuals--border--semantic--brand--primary);
      }

      .pdf-preview__thumbnail-number {
        background-color: var(
          --c--contextuals--border--semantic--brand--primary
        );
        color: var(--c--contextuals--background--surface--primary);
      }
    }
  }

  &__sidebar-skeleton {
    display: flex;
    justify-content: center;
  }

  &__thumbnail-skeleton {
    width: 106px;
    height: 150px;
    border-radius: 4px;
    background: var(--c--contextuals--border--surface--primary);
    animation: pdf-skeleton-pulse 1.5s ease-in-out infinite;
  }

  &__thumbnail-number {
    margin-top: 4px;
    font-size: 12px;
    font-weight: 700;
    color: var(--c--contextuals--content--semantic--neutral--secondary);
    text-align: center;
    font-family: var(--c--globals--font--families--base);
    padding: 4px 6px;
    border-radius: 8px;
  }

  &__horizontal-scroll {
    overflow-x: auto;
    overflow-y: hidden;
  }

  &__page-wrapper {
    .react-pdf__Document {
      display: flex;
      flex-direction: column;
      align-items: center;
    }
  }

  &__container .react-pdf__Page,
  &__page-wrapper .react-pdf__Page {
    border-radius: 4px;
    overflow: hidden;
    box-shadow: 0 3.649px 14.597px 0 rgba(0, 0, 0, 0.1);
  }

  &__zoom-controls {
    display: flex;
    align-items: center;
    gap: 4px;
  }

  &__page-nav {
    display: flex;
    align-items: center;
    gap: var(--c--globals--spacings--3xs);
    padding: 0 4px;
  }

  &__page-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 14px;
    font-weight: 600;
    color: var(--c--contextuals--content--semantic--neutral--secondary);

    .c__field {
      width: auto;

      .c__input__wrapper {
        height: 26px;
        padding: 4px;

        input {
          font-weight: 600;
          text-align: center;
          padding: 0;
          color: var(--c--contextuals--content--semantic--neutral--tertiary);
        }
      }
    }
  }

  &__page-total {
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    color: var(--c--contextuals--content--semantic--neutral--secondary);
  }

  &__error {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--c--contextuals--content--semantic--danger--primary);
    font-size: 14px;
  }
}

@keyframes pdf-skeleton-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.4;
  }
}

@media (max-width: 768px) {
  .pdf-preview {
    &__controls {
      padding: 8px;
      gap: 8px;
    }

    &__page-input {
      font-size: 13px;
    }

    &__page-indicator {
      font-size: 13px;
    }
  }

  .zoom-control__value {
    min-width: 40px;
    font-size: 13px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .pdf-preview__page-skeleton {
    animation: none;
  }

  .pdf-preview__thumbnail-skeleton {
    animation: none;
  }

  .pdf-preview__sidebar {
    transition: none;
  }
}

.pdf-preview__external-link {
  word-break: break-all;
  display: block;
  padding: 8px;
  background-color: var(--background-alt-grey);
  border-radius: 4px;
  font-family: monospace;
  font-size: 14px;
  margin: 8px 0;
}
