.c__modal__backdrop:has(.file-preview__container) {
  background: var(--c--contextuals--background--semantic--contextual--primary);
  backdrop-filter: blur(8px);
  .c__modal {
    background: none;
  }

  .c__modal__scroller {
    padding: 0;
  }
}

/**
 * When the file preview is opened from the explorer search modal, we want to
 * have a more opaque backdrop color.
 */
.ReactModalPortal:has(.explorer__search__modal)
  ~ .ReactModalPortal:has(.file-preview__container)
  .c__modal__backdrop {
  background-color: var(--c--contextuals--background--surface--secondary);
}

.file-preview__container {
  width: 100%;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

.file-preview__header {
  height: 52px;
  border-bottom: 1px solid var(--c--contextuals--border--surface--primary);
  flex-shrink: 0;
  z-index: 10000;
  position: relative;
  background-color: var(--c--contextuals--background--surface--secondary);

  &__content {
    height: 100%;
    display: flex;
    align-items: center;
    padding: 0 var(--c--globals--spacings--xs);
    max-width: 100%;
    position: relative;

    &__left {
      display: flex;
      align-items: center;
      gap: var(--c--globals--spacings--3xs);
      flex: 1;
      min-width: 0; // Allow shrinking
    }

    &__right {
      display: flex;
      align-items: center;
      gap: var(--c--globals--spacings--3xs);
      flex: 1;
      justify-content: flex-end;
      min-width: 0; // Allow shrinking
    }
  }
}

.file-preview__title-wrapper {
  display: flex;
  align-items: center;
  gap: var(--c--globals--spacings--3xs);
  overflow: hidden;
}

.file-preview__title {
  font-size: 18px;
  font-weight: 600;
  color: var(--c--contextuals--content--semantic--neutral--primary);
  margin: 0;

  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-preview__content {
  flex: 1;
  overflow: hidden;
  max-width: 100dvw;
  position: relative;

  display: flex;

  // Blur effect on content
  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: inherit;
    z-index: -1;
  }
}

.file-preview__main {
  flex: 1;
  min-width: 0;
  transition: all 0.3s ease-in-out;
  width: 100%;
}

.file-preview-sidebar {
  position: fixed;
  right: -300px; // Start off-screen
  width: 300px;
  max-width: 300px;
  height: calc(100vh - 52px);

  border-left: 1px solid var(--c--contextuals--border--surface--primary);
  transition: transform 0.3s;
  z-index: 9998;
  overflow-y: auto;
  overflow-x: hidden;
  background-color: var(--c--contextuals--background--surface--secondary);
  backdrop-filter: blur(14px);

  &.open {
    transform: translateX(-300px);
  }
}

.file-preview__container--sidebar-open {
  .file-preview__main {
    width: calc(100% - 300px);
    margin-right: 300px;
  }
}

// Entry animation
.file-preview-overlay {
  animation: fadeIn 0.1s ease-out;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.file-preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--c--globals--spacings--3xs, 4px);
  color: var(--c--contextuals--content--semantic--brand--tertiary);
  font-size: 14px;
  font-style: normal;
  font-weight: 500;
  border-radius: var(--c--globals--spacings--3xs, 4px);
  border: 1px solid var(--c--contextuals--border--surface--primary);
  background-color: var(--c--contextuals--background--surface--secondary);
  box-shadow: 0px 2px 8px 0px rgba(0, 0, 0, 0.08);
}

// Styles for different viewer types
.file-preview__viewer {
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.file-preview-pdf-container {
  width: 100%;
  height: 100%;
  overflow: auto;

  .pdf-preview-container {
    height: 100%;
    display: flex;
    flex-direction: column;
  }
}

.file-preview-unsupported {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 2rem;
  text-align: center;
  color: var(--c--contextuals--content--semantic--neutral--secondary);
  gap: var(--c--globals--spacings--xs);

  &__title {
    color: var(--c--contextuals--content--semantic--neutral--primary);
    text-align: center;
    font-size: 16px;
    font-weight: 700;
    line-height: 22px;
  }

  &__description {
    color: var(--c--contextuals--content--semantic--neutral--secondary);
    text-align: center;
    font-size: 12px;
    font-weight: 400;
    line-height: 16px;
  }

  p {
    margin: 0.5rem 0;
    font-size: 16px;

    &:first-child {
      font-size: 18px;
      font-weight: 600;
      color: var(--c--contextuals--content--semantic--neutral--primary);
    }
  }

  a {
    margin-top: 1rem;
    padding: 0.75rem 1.5rem;
    background-color: var(
      --c--contextuals--content--semantic--brand--secondary
    );
    color: white;
    text-decoration: none;
    border-radius: 6px;
    font-weight: 500;
    transition: background-color 0.2s ease;

    &:hover {
      background-color: var(
        --c--contextuals--content--semantic--brand--tertiary
      );
    }
  }
}

.video-preview-viewer-container {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;

  .video-preview-viewer {
    width: 100%;
    max-width: 1000px;
  }
}

//
// -- Navigation buttons --
//

.file-preview__next-button,
.file-preview__previous-button {
  position: absolute;
  top: calc(50% - 20px);
  background-color: white;
  transition: transform 0.3s;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--xs, 8px);
  border: 1px solid var(--c--contextuals--border--surface--primary);
  background: var(--c--contextuals--background--surface--primary);
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.05);
}

.file-preview__next-button {
  right: 16px;
}

.file-preview__previous-button {
  left: 16px;
}

.file-preview__container--pdf-sidebar-open {
  .file-preview__previous-button {
    transform: translateX(150px);
  }
}

.file-preview__container--sidebar-open {
  .file-preview__next-button {
    transform: translateX(-300px);
  }
}

// Responsive design
@media (max-width: 768px) {
  .file-preview__header__content {
    padding: 0 16px;
  }

  .file-preview__title {
    font-size: 16px;
  }

  .file-preview__content > * {
    min-height: calc(100dvh - 84px);
  }

  .file-preview-nav {
    display: none;
  }

  // Sidebar overlay behavior on mobile
  .file-preview-sidebar {
    z-index: 10001; // Higher than header
    width: 100vw;
    max-width: 100vw;
    right: -100vw;
    background-color: var(--c--contextuals--background--surface--secondary);
    border-left: none;

    &.open {
      transform: translateX(-100vw);
    }
  }

  .file-preview__container--sidebar-open {
    .file-preview__main {
      width: 100%;
      margin-right: 0;
    }
  }

  .file-preview__next-button,
  .file-preview__previous-button {
    display: none;
  }
}

.file-preview__controls {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--c--globals--spacings--3xs);
  padding: var(--c--globals--spacings--3xs);
  border-radius: var(--xs, 8px);
  border: 1px solid var(--c--contextuals--border--surface--primary);
  background: var(--c--contextuals--background--surface--primary);
  box-shadow: 0 2px 4px 0 rgba(0, 0, 0, 0.05);

  &__separator {
    width: 1px;
    height: 24px;
    border-radius: 1px;
    overflow: hidden;
    background: var(--c--contextuals--border--surface--primary);
  }

  &__zoom {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--c--globals--spacings--3xs);

    &__value {
      text-align: center;
      min-width: 35px;
      font-size: 14px;
      font-weight: 600;
      color: var(--c--contextuals--content--semantic--neutral--secondary);
      cursor: pointer;
      padding: 4px 0;
    }
  }
}
